Claude Code wrote 200 lines
Claude Code wrote 200 clean lines with passing tests, then asked what we were building. The 200K window had been eaten by file reads, command output and chat history. Treat context as a budget: pin rules in CLAUDE.md, slice tasks, clear early, delegate big reads to subagents, and keep progress in a file.
📜 Table of Contents
📖 Keep reading
Claude Code wrote 200 lines, then asked me what we were building
It did well: 200 lines, clean structure, tests green. Then I said "now add a button" and it asked what our goal was.
It wasn't confused. The context was full. Reads, command output, stack traces and my own wordy prompts had used up the 200K window before the one thing that mattered — what the project is doing — could fit.
1. Know what eats the window
| Consumer | Typical cost | Avoidable |
|---|---|---|
| Whole source files | thousands of tokens per 500-line file | yes: read one function, or let it search first |
| Test / command output | thousands per full run | yes: keep only failures |
| Stack traces | hundreds to 1k+ | yes: top three frames plus your own files |
| Chat history | grows every turn | yes: clear at phase boundaries |
| System prompt + CLAUDE.md | fixed | no, and it is worth paying for |
The counterintuitive part: save on files and history, spend on CLAUDE.md.
2. Put the rules in CLAUDE.md
Claude Code reads CLAUDE.md at the repo root every turn. Keep it short and executable:
# Conventions
- Stack: Python 3.12, FastAPI, SQLite, static frontend
- Layout: src/api routes, src/core logic, pytest in tests/
- Never touch src/legacy/* without review
- Before committing: pytest -q and ruff check
- Style: type hints and docstrings on public functions
# Current phase
- Doing: cursor pagination for /orders (no offset)
- Done: auth, checkout, inventory
- Next: pagination plus index tuning
Those last three lines let the model answer "what are we doing" at any moment. Update them when the phase changes.
3. Slice tasks so each fits one commit
Good: "add cursor pagination to /orders, with tests." Bad: "refactor the order module, add pagination, caching and new log format." Bad slices don't fail loudly — the model finishes the first three items and invents the fourth.
4. Clear vs compact
| Command | Effect | When |
|---|---|---|
/clear |
drops history | switching task or module; the default |
/compact |
summarizes history | same task, long session, keep conclusions |
/context |
shows usage breakdown | first thing when it starts forgetting |
Write conclusions to disk before clearing, or they're gone.
5. Delegate big reads to subagents
Newer builds support subagents via /agents. They have their own context and return conclusions, not file contents.
Ask for: "read src/core/pricing.py and list the discount branches and their conditions", or "scan tests/ and list uncovered public functions." You get a paragraph instead of three thousand lines.
6. Keep progress on disk
## 2026-07-05 pagination
- Changed: src/api/orders.py, cursor param, default 20
- Tested: tests/test_orders_page.py green
- Open: cursor as base64(id) vs (created_at,id); using former
- Next: index on created_at, load test 100k rows
First message of every new session: "read PROGRESS.md."
7. Budget table
| Task | Target usage | Approach |
|---|---|---|
| One-file edit | under 20% | just talk |
| 3-5 files | 40-60% | one /compact, log progress |
| Large refactor | will break above 60% | split into sessions |
| Read-only research | irrelevant | hand to a subagent |
FAQ
How long should CLAUDE.md be? One screen. Every line should be a rule that prevents a real mistake, not an encyclopedia.
Still forgetful after /compact? The key facts were never on disk. Move them into PROGRESS.md, then clear.
Do subagents share the workspace? Yes, same files. So scope their task and name the files they may edit.
Why does it start editing unrelated code after 200 lines? Old files still in the window get treated as part of the current task. Clear and restate.
Commands and features change between releases; check the official docs.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.