Method 04

Trim Your CLAUDE.md: Front-Loaded Token Savings

Every line in your CLAUDE.md is injected into every conversation before you even type a single character. A 500-line CLAUDE.md burns tokens on 480 lines you never needed. Trim it to 8 core rules and save on every session, forever.

Token Savings: 10–30%

The Hidden Cost of CLAUDE.md

CLAUDE.md is injected into every single conversation as a system-level preamble. Unlike your prompts, which you control per-task, CLAUDE.md is invisible overhead — you don't see it in the chat, but you pay for every token in it, every time.

Here's the math that most developers never do: if your CLAUDE.md is 500 lines long, and each line averages 8 tokens, that is roughly 4,000 tokens injected before you type anything. Now multiply that across 20 conversations per day, and you are burning 80,000 tokens daily — just on your system prompt preamble. Over a month, that is 1.6 million tokens spent on rules you probably did not need for any given conversation.

The problem compounds because CLAUDE.md is context-agnostic. It does not know whether you are writing Python, reviewing a pull request, or debugging CSS. It sends the same 500 lines regardless. Your Python linting rules go to every TypeScript session. Your Git commit message conventions go to every CSS tweak. Every line that does not apply to the current task is pure waste.

The fix is straightforward but requires discipline: keep only the 5 to 10 rules that apply universally, and move everything else into project-specific or language-specific files that load only when relevant. The token savings are front-loaded — they compound across every single session without you having to change how you work. Think of it as reclaiming context headroom: every line removed is token budget returned for actual work. Combined with strategic compaction, the compounding effect is significant — less baseline overhead means more room before each compaction trigger.

What to Keep, What to Cut

The golden rule: if a rule does not apply to every project and every language you touch, it does not belong in your global CLAUDE.md. Move it to a project-level or language-specific rules file instead.

Keep: 5–10 Core Universal Rules

Your global CLAUDE.md should only contain rules that apply regardless of project, language, or task. These are your non-negotiables — the things you want Claude to always know.

Cut: Everything Else Moves to Project Files

Here is a quick audit checklist. If you answer "yes" to any of these, the rule should leave your global CLAUDE.md:

Before vs After: Real Token Math

Here is a realistic comparison. The "before" CLAUDE.md is a typical file from a developer who has been adding rules for months without ever removing any. The "after" is the same developer after a 20-minute audit.

Before: Bloated CLAUDE.md (56 lines, ~450 tokens)

# CLAUDE.md — Before trimming

## Communication
Always reply in English. Be concise. Use active voice.

## Python Rules
Use Python 3.10+. Follow PEP 8. Use type hints on all function signatures.
Use `black` for formatting, `ruff` for linting. Run `pytest` before committing.
Prefer dataclasses over dicts. Use pathlib over os.path.

## TypeScript Rules
Use TypeScript 5.x with strict mode. Prefer interfaces over types for public APIs.
Use `eslint` with `@typescript-eslint` plugin. Run `tsc --noEmit` before committing.
No `any` unless absolutely necessary — use `unknown` and narrow.

## React Rules
Use functional components. Prefer composition over inheritance.
Use React.memo() for expensive components. Colocate styles with components.
Use React Query for server state, Zustand for client state.

## Git Conventions
Write commit messages in imperative mood. Subject under 72 chars.
Branch naming: `feature/`, `fix/`, `chore/` prefixes. Squash before merging to main.
Never force-push to main. Always rebase before opening a PR.

## Code Review
Check for: null safety, error handling, test coverage, performance implications.
Review your own PR before assigning others. Respond to all comments.

## Testing
Write unit tests for all new logic. Integration tests for API endpoints.
Use `describe`/`it` blocks in JS, `pytest` fixtures in Python. Target 80% coverage.

## Deployment
CI runs lint, typecheck, tests. Staging deploys from `main` automatically.
Production requires manual approval. Rollback with `revert` commit.

## Security
Never output secrets, API keys, or credentials. Never commit .env files.
Run `npm audit` / `pip-audit` weekly. Keep dependencies updated.

## Documentation
Write self-documenting code. Comment only when behavior is non-obvious.
Update README when adding new features. Keep CHANGELOG on releases.

## Tooling
Use VSCode with workspace settings committed. Pre-commit hooks: lint, format.
Use Docker Compose for local dev. Use Makefile for common tasks.

After: Trimmed CLAUDE.md (8 lines, ~65 tokens)

# CLAUDE.md — After trimming

## Universal Rules
Reply in English. Be concise. Use active voice.
Prefer simple, readable code. Prefer editing files over creating new ones.
Never output secrets, API keys, or credentials. Never commit .env files.
Write commit messages in imperative mood, subject under 72 chars.
Never commit unless explicitly asked. Never create documentation files unless asked.
Default to TypeScript for new projects; use Python for scripting and data tasks.

Token Cost Comparison

ScenarioCLAUDE.md TokensConversations/DayDaily Token CostMonthly Cost (Sonnet)
Before (bloated)~45020~9,000~$0.81
After (trimmed)~6520~1,300~$0.12
Savings-385 tokens--7,700 tokens~85% reduction

That 85% reduction is just from CLAUDE.md overhead. It does not include the additional savings from project-specific rules files, which only load when you are actually working in that project. Over a year of daily use, trimming your CLAUDE.md saves roughly $8 — per developer. For a team of 10, that is $80 saved annually, just from a 20-minute file audit.

Organizing Rules by Project

Once you have trimmed your global CLAUDE.md down to universal rules, the next step is organizing project-specific and language-specific rules so they load only when relevant. Claude Code supports a structured rules directory.

The .claude/rules/ Directory Structure

# Recommended directory layout
~/.claude/
├── CLAUDE.md # Global universal rules (5-10 lines)
├── rules/
│ ├── python.md # Python-specific: linting, typing, testing
│ ├── typescript.md # TypeScript/JS: eslint, tsc, conventions
│ ├── react.md # React patterns: hooks, state, composition
│ ├── git.md # Git workflows: branching, commit style
│ ├── testing.md # Test conventions: frameworks, coverage
│ └── security.md # Security: audit, secrets, dependencies

Language-specific rule files (like python.md or typescript.md) are loaded automatically when Claude detects you are working in that language. This means your Python linting rules only cost tokens when you are actually writing Python — not when you are debugging CSS or reviewing a markdown file.

For project-level conventions, place a CLAUDE.md or .claude/rules/ directory in the project repository itself. These files only load when your working directory is inside that project. If you contribute to 5 different repos, each with its own conventions, none of those project-specific rules burn tokens in the other 4.

The key principle is locality: rules should live as close as possible to where they apply. Universal rules at the user level, language rules in named files, project rules in the repo. Every rule further down the hierarchy is less likely to apply to any given conversation, so keeping it local prevents it from leaking into unrelated sessions.

Maintenance Tips

Trimming your CLAUDE.md is not a one-time task. Rules accumulate over time, and without periodic maintenance, your lean 8-line file will grow back to 50+ lines within months.

Schedule a Quarterly Audit

Set a calendar reminder to review your CLAUDE.md and rules directory every 3 months. Ask yourself three questions for each rule: (1) Do I still follow this rule in practice? (2) Does this rule apply to all projects, or can it move to a language-specific file? (3) Has this rule been superseded by a tool config or team convention?

Remove Stale Rules Immediately

When you change jobs, switch primary languages, or adopt a new framework, remove the old rules right away. References to Python 3.8 conventions when you are on 3.12, or React class component rules when you use hooks exclusively, are dead weight. Every stale rule costs tokens to deliver zero value.

Use Version Control for Rules

Keep your user-level CLAUDE.md and rules directory in a dotfiles repo. This gives you a history of changes, makes it easy to sync across machines, and provides a natural review step before committing rule changes. If a rule was important enough to add, it should be important enough to justify in a commit message.

Watch for Rule Creep

The most common failure mode is "just one more line." You encounter a situation, think "Claude should know this," and add a rule. Over weeks, these one-liners accumulate. To combat this, adopt a hard cap: your global CLAUDE.md must never exceed 15 lines. If you want to add a new rule, you must remove or relocate an existing one first. This forces prioritization.

Common Mistakes

Trimming your CLAUDE.md is simple in principle, but there are a few ways to get it wrong. Here are the most common pitfalls and how to avoid them.

1. Cutting Too Aggressively

The goal is not zero lines — it is the right lines. Removing your security rules ("never output secrets") to save 10 tokens is false economy. Some rules earn their token cost many times over by preventing expensive mistakes. Keep rules that prevent catastrophic failures (security, data loss, destructive git operations) even if they feel obvious. The model benefits from explicit guardrails.

2. Forgetting to Move Rules (Instead of Just Deleting)

The most common mistake: you delete rules from your global CLAUDE.md but never create the corresponding language-specific or project-specific files. The rules are gone, and Claude no longer follows them anywhere. Always verify that a rule has a new home before removing it from the global file. A good practice: create the new rules file first, then delete from global.

3. Keeping Rules as Documentation

CLAUDE.md is not a README. If a line describes something rather than instructing something, it is documentation, not a rule. "This project uses React 18 with TypeScript" is documentation — useful, but better placed in the project README. "Use functional components, prefer hooks over classes" is a rule. Audit your CLAUDE.md for descriptive statements masquerading as rules.

4. Ignoring Context Window Tradeoffs

A very lean CLAUDE.md saves tokens, but it also gives the model less initial guidance. There is a sweet spot — typically 5 to 15 universal rules — where you get most of the behavioral benefits with minimal token cost. Going below 3 lines risks losing important context that shapes the model's default behavior. Experiment: trim aggressively, then add back rules when you notice the model making mistakes it did not make before.

5. Not Testing After Trimming

After trimming your CLAUDE.md, run a few representative tasks to verify the model still behaves as expected. Check that your security rules are still respected, your commit message format is still followed, and your language conventions are still applied. A 10-minute test session is cheap insurance against discovering a missing rule days later when it matters.

FAQ

Aim for 5 to 10 universal rules — roughly 8 to 15 lines total. If every rule truly applies to every project and every language you touch, you are in the right range. Anything beyond 20 lines almost certainly includes rules that belong in language-specific or project-specific files. A good test: read each line and ask, "Would I want Claude to follow this rule when writing a Python script, a TypeScript component, and a shell script?" If the answer is no for any of those, move that rule to a more specific file.

Place a CLAUDE.md file in the root of your project repository. Claude Code will load it automatically when your working directory is inside that project. For more granular organization, create a .claude/rules/ directory in the project repo with named files (e.g., api-conventions.md, testing.md, deployment.md). These project-level rules only cost tokens when you are actively working in that repository — they do not leak into your other projects or your general usage. For language-specific rules that apply across multiple projects (like Python conventions you use everywhere), place them in your user-level ~/.claude/rules/python.md.

This is exactly why the rules directory exists. Create separate files for each context: ~/.claude/rules/client-a.md, ~/.claude/rules/oss-contributing.md, ~/.claude/rules/internal-tooling.md. Claude Code loads rules based on the current working directory and project structure, so client-specific rules in a client's repo folder will only apply when you are in that folder. Your global CLAUDE.md remains the lightweight intersection of all your work — the rules that apply no matter which client or project you are currently serving.

← Back to all 5 methods