Complete Claude Code Tutorial
Claude Code is an agentic coding tool developed by Anthropic. It runs in the terminal or integrates with IDEs that support terminal functionality, leveraging Claude’s language model capabilities to assist with coding, refactoring, debugging, maintenance, and codebase understanding.1. Claude Code Introduction and How It Works
Before diving into CLAUDE.md, let’s quickly understand what Claude Code is and how it interacts with your project.What is Claude Code?
- Claude Code is a command-line (CLI) tool / agentic coding tool provided by Anthropic that allows you to interact directly with your codebase using natural language: letting Claude understand your project structure, generate/modify code, execute shell commands, submit Git changes, and more.
- It’s not just a simple code completion or chatbot, but an intelligent agent that can proactively take actions (editing files, running commands, Git operations, etc.).
- Claude Code attempts to incorporate project context (file contents, history, prompts) into consideration to make informed decisions.
How Claude Acquires Context / Memory
- On startup, Claude Code recursively searches upward from the current directory for CLAUDE.md or CLAUDE.local.md files (CLAUDE.md is currently mainstream), and reads these contents as “memory” or “context”.
- If certain subdirectories (subtrees) also have CLAUDE.md, when entering these subdirectories and reading these subtrees, the CLAUDE.md files in these subtrees will also be included in the context. They are not preloaded at startup.
- The contents of CLAUDE.md become part of Claude’s default “system prompt / background”, meaning Claude will reference the instructions within it when thinking/making decisions.
- During conversations, you can use shortcuts (such as lines starting with #) to write content into CLAUDE.md. For example:
- Claude will prompt you to place this line into a specific memory file (i.e., which CLAUDE.md).
- In conversations, you can also use the
/memorycommand to directly edit memory files (i.e., open CLAUDE.md or other memory files for modification). - CLAUDE.md supports importing other files (using
@path/to/file.mdsyntax), allowing you to split instructions or configurations into multiple files. - To avoid conflicts or security issues, the import syntax is not interpreted as an import within Markdown code blocks or backticks (``` or `).
Claude Code Installation and Configuration
Mac & Linux Configuration Ensure your system has Node.js version 18+ installed 1. Install Homebrew (Recommended for Mac) If Homebrew is not yet installed:GPTProto Relay API - Claude Code Proxy API - Affordable and Stable Claude API Proxy ServiceReplace
sk-xxx with your token from the API key page- Select your preferred theme (press Enter)
- Confirm security notice (press Enter)
- Use default Terminal configuration (press Enter)
- Trust working directory (press Enter)
- Start coding! 🚀
2. Why Write CLAUDE.md - Its Purpose
CLAUDE.md is a background documentation file that Claude reads on startup and incorporates into its thinking. Its purposes include:- Setting “Behavioral Guidelines” for the Project/Team For example: variable naming rules, code style, important module descriptions, tool script usage, developer conventions, etc. This helps Claude make decisions or modify code in accordance with team standards.
- Reducing Repetitive Background in Each Prompt Since it’s loaded at startup, your subsequent natural language prompts to Claude can omit re-explaining these conventions or rules.
- Guiding Claude’s Behavior / Restricting Permissions / Specifying Tools You can specify in CLAUDE.md which tools are safe to use, which require caution, or tell Claude “use this script/command in this situation”.
- Project Structure Description / Key Modules and Conventions In multi-person collaboration or large projects, CLAUDE.md helps Claude quickly understand module responsibilities, entry files, dependencies, etc., leading to more reasonable suggestions.
- Hierarchical Memory / Subdirectory Customization Different submodules or subdirectories in a project can have their own CLAUDE.md to customize local behavior. This way, even when calling Claude in a submodule, it can reference the submodule’s specific rules.
-
Import / Combine Multiple Instructions
Using
@syntax, you can split descriptions of different functional modules into multiple .md files, then import them in the main CLAUDE.md. This makes the structure clearer and easier to maintain. - Improve Claude’s Decision Quality / Reduce Guessing Many users report: the more standardized and explicit the CLAUDE.md, the more stable and expected Claude’s output becomes.
3. How to Create and Configure CLAUDE.md
Below is a systematic approach (starting from scratch):1. Initialize CLAUDE.md
- In your project root directory, run:
- Claude Code will attempt to read the project structure, key files, dependencies, etc., then automatically generate a preliminary CLAUDE.md.
- After generation, it’s recommended to manually review and modify it.
2. Placement Location and Hierarchy
- Usually placed in the project root directory:
./CLAUDE.md. - For monorepos or multi-module projects, you can also place additional CLAUDE.md files in parent or subdirectories. When Claude works in a subdirectory, it will prioritize loading the subdirectory’s CLAUDE.md.
- You can also place personal preferences / cross-project instructions in your user directory (such as
~/.claude/CLAUDE.md). - Currently CLAUDE.local.md (old name) is gradually being deprecated, with the import mechanism recommended as a replacement.
3. CLAUDE.md Content Structure and Recommended Format
Below is a recommended content structure and writing standard, which can be adjusted based on team/project needs:- Keep it concise and clear, avoid cramming too many details. Overly long backgrounds might make it harder for Claude to grasp the key points.
- Write rules in natural language rather than just code snippets. Claude can understand such instructions.
- Moderately provide examples/templates in rules to help Claude understand the meaning.
- When the project evolves or standards change, update CLAUDE.md promptly.
- For team projects, you can commit the main CLAUDE.md to version control so team members can share it.
4. Importing Other Files (@syntax)
As mentioned earlier, to avoid making CLAUDE.md bloated, you can write rules for different modules or subsystems into separate .md files, then reference them in the main file using import syntax. For example:Import syntax is not effective within code blocks / backticks.
4. Claude Code Basic Usage Flow / Common Commands
After having CLAUDE.md, let’s discuss some basic usage and interaction flows of Claude Code.Installation and Configuration
- Install globally using npm (prerequisite is Node.js installed):
- First startup will go through a configuration process, including OAuth, API key, permission authorization, etc.
- After installation, you can run
claude doctorto check environment and version status. - On Windows, you may need to run it in WSL or Git Bash environment.
Common Interactions / Commands
Below are commonly used Claude Code interaction commands and tips:| Command / Method | Function / Description |
|---|---|
claude | Start interactive session |
claude -p "..." | Send prompt directly in non-interactive mode (similar to “prompt” mode) |
claude -c | Continue previous session (maintain context) |
/help | Display help documentation |
/clear | Clear current conversation history |
/config | View / modify configuration |
/cost | View current session or cumulative token usage / cost |
/model | Switch Claude model being used (e.g., Sonnet / Opus, etc.) |
/memory | Open memory editor in conversation (edit CLAUDE.md and other memory files) |
/review | Request review / suggestions for current code changes |
/vim | Enter vim mode for editing (if supported) |
- Use
-pprompt +--output-format stream-jsonto get JSON output - Headless mode doesn’t preserve conversation context (each is an independent request)
Example Flow: A Typical Task
From a natural language requirement to code changes, the general flow might look like:- Start Claude:
claude - Present requirement:
> Add user login and registration functionality to this project - Claude will scan CLAUDE.md, project files, list a plan (subtask checklist), may ask you to confirm the plan first
- After you confirm the plan, Claude will make changes to files sequentially (generate, modify, delete, etc.), asking if you accept each modification before proceeding
- Finally, Claude will generate commits, PRs, commit messages, etc.
- You can then have Claude review changes, write documentation, refactor, fix bugs, etc.
5. Practical Examples (Including CLAUDE.md + Input/Output)
Below are several complete examples demonstrating CLAUDE.md + prompts + Claude’s output/actions.Example 1: Small Node.js Project
Project Structure:- Claude reads CLAUDE.md, understands project background and conventions
- Scans project file structure, finds src/user.js and tests/user.test.js
- Returns a plan, for example:
- After you confirm, Claude generates code changes step by step, asking if you accept each step
- Finally generates a commit (e.g., “user: add register & login with tests”)
Example 2: Using Imports for Multiple Documentation Files
Suppose the project is quite large, with frontend and backend modules, each with different rules. You can write the main CLAUDE.md like this:frontend/CLAUDE.md:
backend/CLAUDE.md:
backend/ directory, Claude will read backend/CLAUDE.md and combine it with the main CLAUDE.md’s general rules to understand your instructions.
Then you can tell Claude in the backend directory:
backend/CLAUDE.md.
Example 3: Debug Logs + Pipe Input
Suppose you have a log fileerror.log containing stack trace / exception information. You want Claude to help analyze the error.
Command line:
/prompt mode)
Claude will receive the log content as input, with CLAUDE.md project background in context, thus giving you error analysis suggestions more relevant to the project.
6. Advanced Tips and Best Practices Summary
Below are some community / official recommended tips to help you write good CLAUDE.md and improve Claude Code’s efficiency and stability.| Tip / Recommendation | Explanation / Rationale |
|---|---|
| Prioritize Refinement | Don’t cram too much redundant content into CLAUDE.md. Keep rules clear, concise, focused on the most critical decision points. |
| Use # to Quickly Write to Memory | During conversations, write a rule starting with #, Claude will prompt you to add it to which CLAUDE.md. |
| Dynamic / Temporary Memory | For one-off adjustments, short-term rules, you can also write them in the conversation, not necessarily entirely in CLAUDE.md. |
| Regular Maintenance / Cleanup | As the project evolves, CLAUDE.md may become outdated or messy. Recommend periodic review, adjusting structure and rules. |
| Be Cautious with Tool Authorization | Claude by default requests authorization before modifying files / Git operations. You can adjust which tools are allowed or not in conversation / configuration. |
| Have Claude Generate Plan / TODO Checklist First | Before executing code modifications, have it list a plan first, you can confirm if it’s reasonable to avoid deviating from expectations. |
| Provide Sufficient Background / Constraints in Prompts | Even with CLAUDE.md, in complex tasks you can still distill key constraints in prompts to prevent Claude from deviating. |
| Utilize Subdirectory CLAUDE.md for Refinement | Write local CLAUDE.md in submodules to bring rules closer to business logic. |
| Enable / Disable Auto-update | If you want to control version stability, you can disable Claude Code’s auto-update behavior. |
Summary
Claude Code is a powerful AI programming assistant, and CLAUDE.md is the key to making it better understand your project and team standards. Through proper CLAUDE.md configuration, you can:- Have Claude follow project coding standards and best practices
- Reduce repetitive work of explaining project background
- Improve quality of code generation and modification
- Better control Claude’s behavior and permissions

