Claude Code Project Context: Cut Token Waste
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
Claude Code’s project context can waste tokens when you include irrelevant files or duplicate guidance. This article explains how to structure your CLAUDE.md and memory files so the AI focuses on what matters, reducing token consumption and improving response quality.
Formula
Waste = Total context tokens – (Relevant files × Average tokens per file). The percentage is Waste ÷ Total × 100. This estimates how many tokens you spend on files or instructions that don’t help the current task.
Worked Example
With 8,000 tokens of context, 5 relevant files, and 1,500 tokens per file: Relevant tokens = 5 × 1,500 = 7,500. Waste = 8,000 – 7,500 = 500 tokens (6.3%). This shows a small overhead; trimming one irrelevant file would drop waste to zero.
Why Context Management Matters
Every token you send to Claude Code costs money and slows responses. The model reads the entire context each time you ask a question, so a bloated CLAUDE.md or a folder full of auto-included files directly increases latency and cost. Keeping context lean isn’t just about tidiness—it’s about efficiency.
How Claude Code Builds Context
Claude Code automatically loads a hierarchy of memory files: the main CLAUDE.md in your project root, plus CLAUDE.md files in subdirectories that apply when you work in those folders. It also reads the current file, and you can explicitly add more via /add or @file. The total context window is large (200k tokens for most models), but every token counts toward your usage limit.
Common Token Wasters
- Repeating instructions across multiple CLAUDE.md files—the model merges them, so duplicates waste space.
- Including generated files like
dist/ornode_modulesthat you never edit manually. - Pasting entire logs when a one-line error summary would do.
- Long-winded style guides that could be shortened to a few bullet points.
- Outdated notes about APIs or commands that no longer exist.
How to Trim Context Effectively
- Open your root
CLAUDE.mdand remove any line that doesn’t apply to most tasks. - Move project-specific notes into subdirectory
CLAUDE.mdfiles so they load only when relevant. - Use
/clearto reset the conversation when you switch tasks, dropping old file contents. - Add a
.claudeignorefile to exclude large directories from auto-inclusion. - Review your context usage with
/contextto see exactly what’s loaded.
Comparing Context Strategies
Some developers prefer a single comprehensive CLAUDE.md, while others use many small files. The right approach depends on project size. For a small script, one file is fine. For a large monorepo, per-directory files prevent the model from seeing irrelevant parts. A middle ground: keep a concise root file with global rules, and add specific ones only where needed.
Cost and Performance Impact
Token usage directly affects your bill—Claude Code charges per token in and out. Cutting 10,000 tokens from every request saves money over many interactions. It also speeds up responses because the model processes less text. For long sessions, the savings compound.
Frequently Asked Questions
Does Claude Code auto-include all files in the project?
No. It reads the current file and the relevant CLAUDE.md files. Other files are included only if you reference them with @file or #file. However, the model may read files you mention in your prompt, so be selective.
What’s the best length for a CLAUDE.md?
Keep it under 500 lines, ideally 100–200. Include only instructions that change behavior: coding style, test commands, architecture notes, and common pitfalls. Remove anything that’s obvious or that the model already knows.
Can I use .claudeignore to exclude files?
Yes. Create a .claudeignore file in your project root with patterns like dist/ or *.log. This prevents those files from being read or suggested during autocomplete, saving tokens.
Why does my context still show large file contents?
If you’ve opened a file in your editor, Claude Code may include it. Use /clear to start fresh, or explicitly close files with /remove if you added them manually.
Does trimming context hurt response quality?
No, it often improves it. The model pays more attention to relevant instructions when there’s less noise. A focused context leads to fewer hallucinations and more accurate code.
Related
Formula used
in t | Context size (tokens) | tokens | 8000 | 0 in d | Relevant files | count | 5 | 0 in e | Avg tokens per file | tokens | 1500 | 0 out waste | Estimated waste | tokens | t - d * e | 0 out pct | Waste percentage | % | (t - d * e) / t * 100 | 1
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.