[KongchangAI]
· 3 min read· 1,541 words

How to Streamline CLAUDE.md: Cut 322 Lines to 24 and Drastically Reduce Costs

How to Streamline CLAUDE.md: Cut 322 Lines to 24 and Drastically Reduce Costs

CLAUDE.md should be streamlined into checkable rules, with processes loaded on demand and model routing handled by subagents

The article points out that CLAUDE.md is loaded every session; verbose content not only consumes tokens but also dilutes instruction compliance, and contradictory rules cause the model to choose arbitrarily. The author suggests first understanding the file load scope and using `/context` to confirm which files are actually loaded; in terms of content, keep only real, runnable commands and checkable conventions that differ from default behavior, cut information the model can infer itself such as directories, dependencies, and architecture, and keep it under 200 lines. Useful processes that were removed should be moved into rules, skills, and CLAUDE.local.md for on-demand loading; splitting with @import does not save tokens. Model routing should rely on the subagent's model field rather than textual wishes. Finally, use a short CLAUDE.md to import AGENTS.md, letting three tools share one instruction file while avoiding the symlink issue on Windows.

Why Your CLAUDE.md Might Be Slowing Down Your AI Coding

Many people, when writing a CLAUDE.md, habitually cram everything in: project overview, directory tree, dependency versions, and long architecture essays. The result is a bloated file of over three hundred lines and more than three thousand tokens. This file is loaded every session, so even when you're just tweaking an unrelated small feature, those tokens are still consumed. Anthropic's official documentation explicitly states that longer files eat into context and reduce instruction compliance rates.

Even more insidious is self-contradiction: in the same file, line 219 says use two-space indentation, while line 230 says four-space indentation. The official docs note that when two instructions conflict, the model may arbitrarily pick one to follow.

And it's not a one-time charge.

First, Understand Which Files Are Actually Loaded

When Claude Code starts, it only reads CLAUDE.md and CLAUDE.local.md in your startup directory and all parent directories. Files in subfolders are not loaded at startup; they are loaded on demand only when you read or edit files within that folder.

There are four layers of scope: enterprise managed policy, personal files in the user's home directory, project files committed to the team, and CLAUDE.local.md which is not committed to git. These are not override relationships; they are concatenated from broadest to most specific.

Two commands worth remembering: /init generates a starting file from the codebase, and if a file already exists, it suggests improvements rather than overwriting; /context (or /memory) shows which files are actually loaded. Before blaming the model, check this first.

Context window is the total token limit the model can "see" in a single session. System prompts, tool definitions, conversation history, and loaded instruction files all have to squeeze into this one budget. Files like CLAUDE.md fall under "fixed overhead": they are re-sent with every request, and even if their content is irrelevant to the current task, they occupy the window and increase inference costs. Once the window fills up, earlier content may be truncated or compressed, and the model's attention to instructions gets diluted. This is the technical reason why the official docs emphasize that "longer files eat into context and reduce instruction compliance rates"—it's not that the model can't understand, but that the relative weight of valid signals in the noise decreases.

What to Write and What to Cut in a Streamlined Version

The top priority is commands. The original video's author wrote a small script to run each command under the commands heading in CLAUDE.md one by one, and found that test and lint passed, but type check failed—the project didn't have a type check script at all. Every session round, the model was being told to run a command that doesn't exist. Wrong commands are worse than no commands.

Test pass.

Next, only write conventions that differ from default behavior, such as using integer cents for monetary amounts, or only using ES modules. Write checkable rules: use "two-space indentation" rather than "format code correctly", use "run npm test before committing" rather than "test your changes". When the model makes the same mistake a second time, that's the signal to add a line.

Block-level HTML comments are stripped before the model sees them, so notes left for human maintainers don't cost tokens.

What to cut: directory structure, dependency lists, architecture overviews—the model can figure these out from the code itself. Vague instructions like "write clean code" and "follow best practices" should also be deleted; they only consume tokens without saying anything specific. Anthropic recommends keeping each file under 200 lines. The original video's comparison was 18 lines in, 316 lines out.

One trap: splitting into multiple files with @import doesn't save tokens. Imported files are loaded along with the importer, with the same cost.

Block-level HTML comments being stripped refers to comment blocks that start with <!-- and occupy an entire line. Claude Code removes such content before feeding instruction files to the model, so it's safe to write "notes for human maintainers" without incurring token costs. However, inline comments (on the same line as body text) and regular Markdown comments may not enjoy the same treatment. When relying on this mechanism, it's best to confirm with /context or actual testing. Leveraging this, you can leave change reasons, maintenance reminders, and to-dos in the file without worrying about them crowding the model's budget.

Let the Right Content Appear Only When Needed

Among the cut content, some parts are genuinely useful, such as a thirty-step review process and testing conventions. They shouldn't be deleted, but loaded on demand. Three destinations: rules under CLAUDE/rules, skills under CLAUDE/skills, and personal notes in CLAUDE.local.md.

Rules with a paths field are loaded only when the model reads or writes matching files. When working on source code, rules related to test files are completely absent from context. paths is also the only front matter field that Claude Code reads in rules.

Process-oriented content becomes skills: review checklists move into a skill's md file, loaded when invoked or when the model judges it relevant. Setting disable-model-invocation to true means only you can trigger it with a slash command. Personal configurations like sandbox URLs go into CLAUDE.local.md, and you can use git ls-files to confirm it has never been committed.

Front matter is a YAML metadata block wrapped between two --- lines at the beginning of a Markdown file, commonly used to declare structured fields like title, tags, and paths. Claude Code only recognizes the paths field in rule files, using it to determine when the rule takes effect: when the file path the model reads or edits matches a pattern in paths, the rule is injected into context. Other front matter fields are ignored, and writing them triggers no additional behavior. Understanding this can prevent you from mistakenly writing routing logic as regular body text, causing rules to always load or never load.

Model Routing Relies on Subagents, Not Wishes

A common suggestion is "write in CLAUDE.md that small tasks should use haiku". But CLAUDE.md is just guiding text; it cannot change which model actually runs. The real switch is in subagent files: under .CLAUDE/agents, define name, description (explaining when to use it), a tool list, and model: haiku. If you don't specify model, it uses the same model as the main conversation.

Next problem, usage.

So that sentence in CLAUDE.md becomes a routing hint pointing to subagents: search, rename, single-file edits go to the fast helper; multi-file bugs stay with the main model to plan first. Switch the main session with /model or the model field in settings; in Opus plan mode, use Opus to plan, then switch back to Sonnet to write code. Anthropic's cost guide puts it plainly: Sonnet can handle most coding tasks, and Opus is reserved for hard reasoning.

Subagent is a lightweight execution unit invoked by the main conversation, with its own context and toolset. It is defined as a Markdown file under .CLAUDE/agents, with name, description, available tools, and a model field declared in front matter. The main model decides when to delegate tasks based on the description, and after the subagent completes, it returns only a summary of results to the main conversation; the intermediate process does not occupy the main context. Fields like model: haiku are where the running model actually changes, while text suggestions in CLAUDE.md are just hints that the model can ignore. Delegating narrow tasks like search and rename to cheap subagents is the main means of controlling costs and context bloat.

One File for Three Tools to Share

When using Claude Code, Cursor, and Codex simultaneously, three instruction files will slowly drift apart. The solution is to place an AGENTS.md in the repository root. This is an open format, now hosted by the Agentic AI Foundation under the Linux Foundation. Codex reads it from the repository root to the current folder before starting work, with a default budget of 32 KB; Cursor reads it in the root and subdirectories; Claude Code has supported it since version 2.1.277.

slash Clawed.md, and no Clawed.local.md in your folder or above it.

But there's a default behavior trap: Claude Code only reads AGENTS.md directly when your folder and all its parent directories have no CLAUDE.md, .CLAUDE/CLAUDE.md, or CLAUDE.local.md. Add a personal notes file to an AGENTS.md project, and Claude Code will read only the notes and skip AGENTS.md.

The safe approach is to import with a short CLAUDE.md: write @AGENTS.md on the first line. Claude reads the shared file first, then the lines below that belong only to Claude, and the file won't be loaded twice. You can also set project instructions to read both in /config.

Don't use symbolic links. On Windows (unless symlinks are enabled), after cloning with core.symlinks=false, CLAUDE.md is reduced to a nine-byte string AGENTS.md. Anthropic's documentation specifically warns about this. If you have Windows colleagues, use imports.

Final Checklist

Use /context to confirm which files are loaded; list real commands and verify each one; cut content the model can infer from code, keeping it under 200 lines; move processes into skills and file-specific rules into rules; use subagents for model routing; finally, use a short CLAUDE.md to import AGENTS.md, achieving shared use across three tools.

#CLAUDE.md#AGENTS.md#Claude Code#subagents#model routing#token cost optimization
Share:

Related articles