How Claude Code Instructions Work
When you start a Claude Code session, Claude receives a system prompt that tells it how to behave. This prompt combines two layers:
- Built-in instructions from Anthropic — defines core capabilities like file editing, code search, terminal commands, git operations, and safety guidelines
- Your custom instructions from CLAUDE.md — defines your project conventions, rules, commands, and preferences
You can't modify the built-in system prompt directly, but your CLAUDE.md instructions are appended to it and can override default behaviors. This means you have full control over how Claude interacts with your codebase.
Claude Code's built-in prompt says: "CLAUDE.md instructions OVERRIDE any default behavior and you MUST follow them exactly as written." This gives your custom rules top priority.
The Instruction Hierarchy
Claude Code loads instructions from multiple sources. They are merged in this order (highest priority first):
| File | Scope | Commit to Git? | Use For |
|---|---|---|---|
./CLAUDE.md |
Project | Yes (shared) | Team conventions, build commands, architecture |
./src/CLAUDE.md |
Directory | Yes | Module-specific patterns, API conventions |
~/.claude/CLAUDE.md |
Global | No (personal) | Editor prefs, personal coding style, aliases |
.claude/settings.json |
Project | Yes | Permissions, allowed/denied tools |
.claude/settings.local.json |
Personal | No | Personal overrides, local tool permissions |
Writing CLAUDE.md (Your Custom Instructions)
CLAUDE.md is a plain Markdown file. Every line you write costs context tokens, so keep it concise. Focus on information Claude can't infer from your code.
Essential Sections
What to Include
- Build/test commands — Claude needs to know how to run your project
- Naming conventions — file names, variable names, CSS class names
- Architecture overview — directory structure and what goes where
- Hard rules — things Claude must ALWAYS or NEVER do
- Tech stack — framework versions, key libraries, ORMs
What to Leave Out
- General coding advice Claude already knows
- Language syntax or framework docs
- Lengthy explanations (every token counts)
- Temporary notes or TODOs
Long CLAUDE.md files waste context tokens on every interaction. Be ruthless about what you include. If Claude can figure it out from the code, don't put it in CLAUDE.md.
CLAUDE.md Examples by Project Type
Python / FastAPI
React Native / Expo
Rust / CLI Tool
Global Settings & Rules
Your global CLAUDE.md at ~/.claude/CLAUDE.md applies to every project. Use it for personal preferences:
Project CLAUDE.md overrides global CLAUDE.md when they conflict. Use global for personal style preferences and project for team conventions.
settings.json (Permissions & Controls)
The .claude/settings.json file controls which tools Claude Code can use without asking permission:
| Permission | Description |
|---|---|
allow |
Tools that run without asking. Use glob patterns: Bash(npm run *) |
deny |
Tools that are always blocked, even if Claude thinks they're needed |
For personal overrides that shouldn't be committed to the repo, use .claude/settings.local.json with the same format.
Skills as Specialized System Prompts
Claude Code skills are essentially reusable system prompt fragments. Each skill has a SKILL.md file that works like a focused CLAUDE.md for a specific task:
Skills are activated when relevant to the conversation. Browse the Skills Directory to find pre-built skills, or create your own.
Advanced Instruction Techniques
Conditional Rules
Use directory-specific CLAUDE.md files to apply different rules to different parts of your codebase:
Override Default Behaviors
Claude Code has built-in behaviors you can override with explicit instructions:
Template Variables
Reference dynamic values in your instructions that Claude can resolve from context:
Embedding External References
Keep CLAUDE.md lean by pointing to external docs:
Troubleshooting
Claude isn't following my instructions
- Check that CLAUDE.md is in the right location (project root for project rules)
- Use strong language: "NEVER" and "ALWAYS" and "MUST" get higher compliance
- Keep instructions short and specific — vague instructions get vague compliance
- Put critical rules at the top of the file
Context is too large
- Trim CLAUDE.md to under 200 lines
- Move detailed documentation to separate files and reference them
- Use
/compactto free up context window space - See the Memory Guide for context management strategies
Instructions conflict between files
When project CLAUDE.md says one thing and global CLAUDE.md says another, the project file wins. For directory CLAUDE.md files, the most specific (deepest) directory wins.
Frequently Asked Questions
Can I see the full system prompt Claude Code uses?
The built-in system prompt is visible in the Claude Code open-source repository on GitHub. Your CLAUDE.md is appended to it. Use /doctor inside Claude Code to see what configuration files are being loaded.
How often is CLAUDE.md reloaded?
CLAUDE.md is loaded at the start of each session. If you edit it during a session, start a new session for changes to take effect. The file is not hot-reloaded within an active session.
Can I use CLAUDE.md to restrict what Claude can do?
CLAUDE.md can set behavioral rules (like "never use any type"), but for hard permission controls, use .claude/settings.json. The deny list in settings.json provides enforcement that can't be overridden by conversation.
What's the difference between CLAUDE.md and a skill?
CLAUDE.md provides always-on instructions for your project. Skills are activatable instructions for specific tasks. Think of CLAUDE.md as your project's constitution and skills as specialized experts you call in when needed. See Skills vs MCP for a deeper comparison.
Should CLAUDE.md be committed to git?
Yes, commit ./CLAUDE.md and .claude/settings.json so the whole team benefits. Personal preferences go in ~/.claude/CLAUDE.md (global, not committed) and .claude/settings.local.json (personal, gitignored).