Anthropic officially provides seven ways to customize Claude Code's behavior (CLAUDE.md, Rules, Skills, Subagents, Hooks, Output Styles, and System Prompt Appending). Each differs in loading timing, compaction behavior, and context cost, so the appropriate method should be selected based on the specific need.
Suitable tasks: Situations that require a systematic understanding of Claude Code's customization mechanisms, or a decision about where to place project standards, team conventions, automated workflows, and so on
Unsuitable tasks: Situations that require deep technical implementation details (this article focuses more on a decision framework)
Applicable model version: Claude Opus 4.7 (through Claude Code)
Applicable client, Agent, or API: Claude Code CLI
Recommended reasoning levels and parameters: N/A (this article discusses customization mechanisms rather than specific tasks)
| Method | When it's loaded | Compaction behavior | Context cost | When to use |
|---|---|---|---|---|
| CLAUDE.md (root) | Session start; stays in context for the entire session | Memoized. Read once and cached for the session; cache cleared and re-read after compaction | High. Every line costs tokens whether relevant or not | Build commands, directory layout, monorepo structure, coding conventions, team norms |
| CLAUDE.md (subdirectory) | On-demand, when Claude reads a file under that subdirectory | Lost until that subdirectory is touched again | Low. Only consumes context when the relevant subdirectory is being worked on | Conventions specific to a subdirectory |
| Rules | Session start (user-level rules) or only when matching files are touched (path-scoped) | Re-injected on compaction | Medium. Always-on unless path-scoped | Specific constraints or conventions (e.g., all API handlers must validate input with Zod) |
| Skills | Name and description at session start; full body loads when the skill is invoked | Invoked skills re-injected up to a shared budget; oldest dropped first | Low. Full body loads only when invoked; subject to a shared token budget across invoked skills | Procedural workflows (deploy or release checklists) |
| Subagents | Name, description, and tool list at session start; body loads only when called via the Agent tool | Only the final message (summary plus metadata) returns to the main session | Low. Zero cost in main context until called; runs in its own isolated context window | Running work in parallel or side tasks that should run in isolation and return only a summary (deep search, log analysis, dependency audit) |
| Hooks | Fire on lifecycle events | Bypass compaction entirely | Low. Configuration lives outside main context; some output may return (e.g., blocking errors) | Deterministic automation: run linters, post to Slack on completion, block commands, back up chat history on PreCompact |
| Output styles | Session start; injected into the system prompt | Never compacted | High. Occupies context window, but overwrites default system prompt | Significant role changes (code assistant to general assistant) |
| Appending the system prompt | Session start; passed as a CLI flag | Never compacted; applies only to that invocation | Moderate. Cached after first request in a session | Tone, response length, formatting preferences |
Two types:
Always loaded: The root CLAUDE.md, loaded at the start of a session and retained without loss or degradation throughout a long session
On-demand: A subdirectory CLAUDE.md, loaded only when Claude reads a file under that subdirectory
Key recommendations:
Keep CLAUDE.md under 200 lines
Assign an owner and review changes like code
Move team-specific conventions into path-scoped rules
Move workflows into skills
In monorepos, give each team's directory its own subdirectory CLAUDE.md
Monorepo configuration:
{
"claudeMdExcludes": ["teams/other-team/**"]
}---
paths:
- "src/api/**"
- "**/*.handler.ts"
---
All API handlers must validate input with Zod before processing.Choose CLAUDE.md (root) when:
You need build commands, directory layout, or monorepo structure
You need coding conventions or team norms
The information must remain available throughout the entire session
Choose CLAUDE.md (subdirectory) when:
The conventions apply only to a specific subdirectory
You want to reduce context cost
Choose Rules when:
You need hard constraints (such as "all API handlers must validate input with Zod")
You need path-scoped constraints
Choose Skills when:
You need reusable workflows (deployment checklists or release checks)
You want on-demand loading to save context
Choose Subagents when:
You need to run work in parallel
You need tasks to run in an isolated context and return only a summary (deep search, log analysis, dependency audits)
Choose Hooks when:
You need deterministic automation (running linters, blocking commands, or backing up chat history)
You need to trigger actions on lifecycle events
Choose Output styles when:
You need a significant role change (from code assistant to general assistant)
Choose Appending the system prompt when:
You need to set tone, response length, or formatting preferences
Assess the current project: Identify which conventions need to be always available (put them in the root CLAUDE.md) and which are needed only in specific situations (put them in a subdirectory or rules)
Review the existing CLAUDE.md: If it exceeds 200 lines, consider moving team conventions into rules and workflows into skills
Configure the monorepo: Create a subdirectory CLAUDE.md for each team, and use claudeMdExcludes to exclude unrelated team files
Create Rules: Create path-scoped rules for hard constraints
Create Skills: Create skills for reusable workflows
Configure Hooks: Configure hooks for automated tasks (such as running linters or blocking dangerous commands)
Test compaction behavior: Test the compaction behavior of each method in a long session to ensure that critical conventions are not lost
The article explicitly lists seven methods and their loading timing, compaction behavior, context cost, and usage timing
It emphasizes keeping CLAUDE.md under 200 lines and assigning an owner
It provides an example of the YAML frontmatter format for Rules
It explains the advantages, disadvantages, and applicable scenarios for each method in detail
It emphasizes that Skills use a shared token budget, with the oldest dropped first
It explains that Subagents have zero cost in the main context and load only when called
This article provides a decision framework rather than specific implementation details
The seven methods can be used together; trade-offs should be evaluated based on the needs of the specific project
The always-loaded type of CLAUDE.md consumes tokens in every session, even when irrelevant
The shared token budget for Skills may cause the oldest skills to be dropped
Hooks bypass compaction, but their configuration lives outside the main context
Official article: "Think of this file as giving Claude an overview of your codebase, or as an index pointing to other files where Claude can find more information as needed."
"Keep CLAUDE.md under 200 lines, give it an owner, and review changes to it like code."
"Each method trades context cost against authority."
Claude Opus 4.7