/t · guide · budget

A multi-file CLAUDE.md token budget is about where each rule lives, not how much each file weighs.

M
Matthew Diakonov
8 min read

Every other guide on this topic answers the wrong question. They tell you how to add up your layered cost. That is arithmetic. The harder question, the one that actually changes your bill, is where each rule should live given that Claude Code loads from five different kinds of files with five different load frequencies. A rule pays tokens on every turn it sits in context, whether or not the turn needed it. The cheapest spend in a multi-file system is not deleting rules. It is moving them to a file that loads when they fire, and stays out of context the rest of the time.

1. The assumption baked into every analyzer

Open src/lib/analyzer.ts and look at line 264. The ccmd analyzer, the one behind the textarea on ccmd.dev, makes one assumption to turn token count into a cost:

analyzer.ts

One line: estimatedTokensFireEveryTurn = totalTokens. Every token in the file you pasted, multiplied by every turn that file is in context. That is true for the file you pasted, by definition. It is not true for every file Claude Code loads. Half of the files in a real Claude Code setup fire less than every turn. The analyzer can only score the file in its textarea. The allocation has to happen in your head, and the framework is the rest of this page.

2. Each file has a fire rate. Match it to the rule's scope.

Nine places a CLAUDE.md-shaped rule can live, with the fire rate of each and the kind of rule that should sit there. Read left to right. A mismatch between the right column and the left is your token leak.

FeatureWhat rule belongs hereWhen this file is in context
~/.claude/CLAUDE.md (user)every turn, every repomachine-wide rules only
./CLAUDE.md (project root)every turn in this reporules every session touches
@import targetevery turn, expanded inlinesame as wherever the import lives, no discount
./CLAUDE.local.mdevery turn, your machine onlypersonal overrides not shared with the repo
.claude/rules/*.md without paths:every turnsame scope as the project root, no benefit
Managed policy CLAUDE.mdevery turn, cannot be excludedspend you do not control; budget around it
./subdir/CLAUDE.md (nested)0 until Claude reads in subdir/, then every turn until /compactsubtree-scoped rules
.claude/rules/*.md with paths:only when a matching file is readfile-pattern rules (migrations, generated code, vendored)
.claude/skills/<name>/SKILL.mdonly when the skill is invokedone-shot workflows (release, ship, set up)

Two practical reads from this table. First, the top six rows all have the same fire rate: every turn. Moving a rule from one of those rows to another row above the line does not save you a single token. The decision is binary: above the line is "every turn," below the line is "conditional." Second, the bottom three rows are the only allocation moves that actually shrink your per-turn floor. A rule that only matters when you are working in api/ belongs in api/CLAUDE.md, not in ./CLAUDE.md.

3. A worked example: 4,900 tokens per turn, no rules deleted

A realistic ./CLAUDE.md in a small monorepo, 6,200 tokens, six sections. The audit asks the same question for each section: what is the smallest scope that needs this rule? Move it to the file whose fire rate matches that scope.

ccmd · rehome by scope
Net result, one number
0tokens per turn off the floor, zero rules deleted

On a 30-turn session at Opus 4.7 input rate $15/M, that is roughly $2.20 saved per session, before prompt cache effects. Every one of those tokens stayed in your config; it just stopped riding turns that did not need it.

The interesting part of the example is what did not change. The user file still loads in every repo on the machine. The 1,300 tokens of house-style rules in ./CLAUDE.md still fire on every turn. The audit moved rules whose scope was narrower than the file they lived in. That is the only allocation move that creates savings; everything else is rearranging the same spend.

4. Three traps that look like budget moves but are not

Trap one: splitting into @import files. Anthropic's memory docs are explicit: imports expand inline at launch, "does not reduce context." A three-line root file that pulls in three 2,000-token files costs 6,000 tokens a turn. The import line is for organization. It is not a budget tool.

Trap two: nesting without on-demand. A guide that says "nest your CLAUDE.md files to save tokens" and does not name the subtree-read trigger has flattened two mechanisms into one. Nested files save tokens only because subtree reads gate their load. A nested file in a subtree you always touch is not free; it is full price after the first turn.

Trap three: deleting rules that should have been moved. The instinct after running an analyzer is to cut the worst-scoring lines. Sometimes that is right. Often the line is fine and the file is wrong: a useful migration warning in your ~/.claude/CLAUDE.md should not be deleted, it should be moved to the one repo where the migration matters. Cutting deletes a rule. Rehoming keeps the rule and removes the unused turns.

5. How to run the audit on your own files

Four steps, no signup, no upload. The analyzer is one-file-at-a-time on purpose; the allocation logic is yours to apply.

  1. Paste ~/.claude/CLAUDE.md into the analyzer. For every rule, ask: does this rule belong on every machine you own, in every repo on it? If the answer is no, it does not belong in the user file.
  2. Paste your project ./CLAUDE.md. For every rule, ask: does this rule fire in every session in this repo? If the answer is "only when working on X," it belongs in X/CLAUDE.md (if X is a directory) or a path-scoped rules file.
  3. For every rule that is procedural (release, ship, set up, audit), check whether it belongs in a skill instead. Skills load only when invoked. A 600-token release runbook in ./CLAUDE.md fires every turn of every session for a workflow you run once a week.
  4. Re-run the analyzer on each file after rehoming. The numbers will still feel high. They will be honest about what is in your per-turn floor versus what is conditional, and the gap between the two is the budget you got back.

One closing precision note. The analyzer counts characters, and Claude Code strips block HTML comments before injecting a file, so maintainer notes wrapped in <!-- ... --> score slightly high per file. That is a rounding error compared to the wrong-file problem. A 1,400-token rule that fires on every turn but only matters in one subdirectory is 1,400 tokens × 29 unused turns × 30 sessions a month of waste. Rounding errors do not compound. Allocation mistakes do.

Want a second pair of eyes on the allocation?

15 minutes, we walk through your user file, project file, and any nested files together and rehome the rules whose scope does not match where they live. Free.

Frequently asked questions

How do I budget tokens across multiple CLAUDE.md files?

Treat each rule as having an intended scope (machine, repo, package, file pattern, one-off workflow) and place it in the file whose load frequency matches that scope. Six layers always fire on every turn of every session: managed policy, ~/.claude/CLAUDE.md, ./CLAUDE.md, ./CLAUDE.local.md, every file an @import pulls in, and .claude/rules/*.md without paths: frontmatter. Two layers fire conditionally: subdirectory CLAUDE.md files (load on first read inside the subtree, then ride every turn until /compact) and .claude/rules/*.md with paths: frontmatter (load only when a matching file is read). Skills load only when invoked. A rule in a higher-fire-rate file than its scope demands is pure waste, multiplied by every turn it sits in context.

Does splitting CLAUDE.md into @import files reduce the budget?

No. From Anthropic's memory docs, verbatim: 'Splitting into @path imports helps organization but does not reduce context, since imported files load at launch.' An @import expands inline at session start and sits in context exactly as if you pasted its content directly. The most common piece of layering advice on the internet, 'split your CLAUDE.md into imports to keep it lean,' is wrong about cost. Imports are a readability tool. They do not move a single token off your per-turn floor.

What is the only multi-file move that actually lowers the per-turn floor?

Three: nested subdirectory CLAUDE.md files (load on demand, only after Claude reads in that subtree), .claude/rules/*.md files with a paths: frontmatter field (load only when a matching file is read), and skills under .claude/skills/<name>/SKILL.md (load only when invoked). All three move tokens from 'pay every turn' to 'pay only when used.' Imports, managed policy, user file, project root, and CLAUDE.local.md are flat-rate spend that does not change with how many files you split into.

How do I work out the dollar cost of a single rule in a CLAUDE.md file?

Paste the file into the analyzer on ccmd.dev. The page reports total tokens. Divide a rule's character count by 4 (the analyzer's chars/4 heuristic, line 38 of analyzer.ts), multiply by turns per session (the analyzer assumes 30, line 266), then by Opus 4.7 input rate $15/M (line 267). A 400-character rule in ~/.claude/CLAUDE.md works out to about 100 tokens × 30 turns × $15/M = $0.045 per session. Cheap individually. Multiplied across 100 sessions a month and however many machines load that user file, it adds up to real money for a rule that fired on every turn but did its work on three of them.

How does prompt caching change the budget math?

It divides the bill on stable prefixes, but it does not change the allocation logic. Identical prefix bytes across turns hit the cache at a ~90% input discount, so a 6,000-token user file that has not changed costs about 600 tokens per turn after the first one. That makes the absolute dollar numbers smaller. It does not change which layers fire on which turns, and it does not help you the first time after any of your CLAUDE.md files change (every edit busts the cache for that turn and rebuilds it). Cache is a multiplier on the wrong-allocation cost; placing rules where they belong is the only thing that removes the cost entirely.

What about a managed policy CLAUDE.md from my employer?

Treat it as fixed spend in your budget, the same way you would treat a base salary line in a personal budget. It loads at launch, in full, on every turn, and it cannot be excluded with claudeMdExcludes. Anthropic's docs explicitly carve out managed policy files from the exclusion mechanism. The only lever you have over a managed file is to ask the team that owns it to trim it. For your own rules, budget around it: subtract its tokens from your per-turn ceiling and allocate the rest.

Do nested CLAUDE.md files leave context when Claude moves away from their subtree?

No, loading is on demand but unloading is not. Once a subdirectory CLAUDE.md is injected it becomes part of the conversation and rides every following turn, even while Claude works in completely unrelated directories. The two things that remove it are /compact (which drops nested files and does not re-inject them, until Claude next reads a file in the subtree) and the end of the session. Plan around the asymmetry: a nested file is free until first touch, full price afterwards, free again at /compact, full price after the next subtree read.

How did this page land for you?

React to reveal totals

Comments ()

Leave a comment to see what others are saying.

Public and anonymous. No signup.