How Claude Code worksPart 6
Context and cost
On this page
In short: Claude works at a desk of fixed size: the context window. Everything it is holding sits on that desk: your rules, the conversation, every file it opened and every log it read. A cluttered desk makes a colleague slower and vaguer, and each message costs more because the whole desk is re-read. Keep one task per desk, send noisy jobs to a helper, and load rules only where they apply.
Part 5 decided what Claude may do. This part is about keeping it sharp while it does it. The project in the examples, the Acme storefront, is made up.
The desk
Think of it like this: A colleague with a clear desk finds things fast. Pile three old projects, a printout of every log and last week’s notes on it, and they start missing the page that matters.
Every time you send a message, Claude reads the whole desk again: the rules, the conversation so far and every tool result in it. Two things follow:
- Focus drops as the desk fills. Old details compete with the task in front of it.
- Cost grows with what is on the desk, because each message carries all of it.
Under the hood: tokens, caching and compaction
- Size is measured in tokens, small pieces of text. Both the context limit and the cost are counted in tokens.
- Claude Code sends the full conversation with each request. Prompt caching makes re-reading the unchanged part cheaper, but it is still counted.
- When the desk gets close to full, Claude Code compacts automatically: it replaces older history with a summary.
/compactdoes the same on your terms, with your instructions. /compactitself reads the whole conversation, so it is a big request./clearcosts nothing.- After a compact, the project’s root
CLAUDE.mdis read in again, so your standing rules survive.
What is on the desk from the start
Some things sit on the desk in every session. Others are fetched only when the work needs them. Moving things from the first list to the second is the cheapest win there is.
CLAUDE.mdfiles from the project up to your home folder- Rules in
.claude/rules/without apathslist - The first 200 lines of auto memory
- Each skill's one-line description, and tool names
- A skill's full steps, when it is used
- Rules with a
pathslist, when Claude reads a matching file CLAUDE.mdin a subfolder, when Claude works there- An MCP tool's details, when Claude looks it up
Rule: keep CLAUDE.md under about 200 lines. The docs say longer files are followed less reliably, and every line is on the desk for every message.
---
paths:
- "src/checkout/**"
---
# Checkout rules
- Money is always integer cents. Never floats.
- Round discounts per line item, not on the total.That file lives in .claude/rules/checkout.md. It only lands on the desk when Claude opens a checkout file.
Your desk tools
/context shows what is taking up room right now: rules, tools, conversation.
/usage shows tokens and cost for this session, and on a plan, what is using your limits.
/compact keep the API decisions swaps old history for a summary of what you name.
/clear starts fresh for unrelated work. The old session is saved; /resume brings it back.
Esc stops Claude now. /rewind goes back to an earlier point when it went the wrong way.
/model and /effort: a lighter setting for simple jobs, the strongest for hard design work.
Send a helper for the big reads
Think of it like this: You do not read the whole printout yourself. You ask someone to read it and tell you the two lines that matter.
Part 2 and Part 3 introduced subagents. Here is why they matter for the desk: the helper’s reading happens on its desk. Only its answer lands on yours.
A morning on the Acme storefront
- 9:00 · One task, one session
Fix the coupon bug on the Acme storefront. Start fresh so yesterday's work is not on the desk.
claude > Fix ACME-151: coupons apply twice at checkout.
- 9:20 · Big read? Send a helper
The full test run is long. A subagent runs it and reports only the failures.
> Use a subagent to run the checkout tests and tell me only which ones fail and why.
- 10:30 · Check the desk
The session has grown.
/contextshows most of it is old file dumps./context
- 10:32 · Summarise with a focus
Keep what matters for the next step, drop the rest.
/compact Keep the coupon fix, the failing test names and the decision to round at line-item level.
- 11:15 · New task, clear desk
The bug is done. The next task, the footer links, has nothing to do with it.
/rename coupon-fix /clear
- End of day · Look at what it cost
/usageshows where tokens went. A bigCLAUDE.mdon every request is a common surprise./usage
Under the hood: other ways to save
- Ask for specific things. “Add input validation to the login function in auth.ts” reads far less than “improve this codebase”.
- Plan first for big tasks (Part 5’s plan mode). A wrong direction caught early saves a whole round of rework.
- Prefer a command-line tool like
ghto an MCP server when both work. CLI tools add nothing to the desk until used. - A hook can shrink output before Claude sees it, for example passing only failing test lines through.
- Thinking tokens are billed as output.
/effortlowers how hard Claude thinks on simple jobs.
Where this fits in the bigger picture
Think of it like this: The written spec from Part 7 is the one page that must stay on the desk. Everything else can come and go.
A setup that works like you needs focus more than it needs memory. A clear desk with the spec, the current task and the rules that apply beats a desk holding everything that ever happened. Part 10 shows how to hand over between sessions without carrying the clutter along.
Which one fits?
- I am switching to unrelated work: /clearStart fresh. Rename first with
/renameso you can/resumeit later. - Same task, but the session is long: /compact with a focusTell it what to keep: "keep the schema decisions and failing tests". Details go, decisions stay.
- A job will spit out lots of output: A subagentTests, logs, long docs. The helper reads them and returns a short answer (Part 2 and 3).
- My CLAUDE.md keeps growing: Move parts outKeep it under about 200 lines. Move procedures into skills and folder-specific advice into rules with
paths. - I do not know what fills the desk: /contextIt lists what is loaded right now, so you can see whether it is rules, tools or old conversation.
- The task is simple: A lighter model or effort
/modelor/effort. Save the strongest settings for design and hard bugs.
Your setup so far
- Part 1 · where it worksYou know which machine does what, and which folders Claude can reach.
- Part 2 · what it remembersOne task per notebook; photocopies in their own folder; helpers for noisy side jobs.
- Part 3 · how it behavesFridge rules for what is always true, recipe cards for procedures, alarms for musts, specialists for checks.
- Part 4 · what it can reachPhone lines to your tracker and tools, checked before trusted; your setup packed as one toolbox.
- Part 5 · what it may doKeys for routine work, a knock for anything that publishes, locked doors for secrets.
- Part 6 · how it stays sharpA clear desk: fresh sessions, focused summaries, helpers for big reads, rules only where they apply.
- NextPart 7 · specs as the source of truth
Three rules of thumb
Clear between unrelated tasks. Stale history costs on every message and blurs the focus.
Anything that produces pages of output runs in a subagent and comes back as a note.
A short CLAUDE.md for what is always true. Skills and path rules for the rest.
QuizYou finished a bug fix and now want to update the footer links, which has nothing to do with the fix. The session is long. What is best?
Show the answer
Answer: /rename the session, then /clear
The new task needs none of the old desk. Clearing is free and gives a sharp start, and renaming lets you /resume the bug fix later if you need it.
Words in this post:
- Context window: how much Claude can hold in mind at once. The desk.
- Token: a small piece of text. Limits and costs are counted in tokens.
- Compact: replace older history with a summary to free room.
- Path rule: a rule file with a
pathslist that loads only for matching files. - Subagent: a helper with its own desk that returns only its answer.
Facts here were checked against the Claude Code documentation on costs and memory in November 2026. These features change often, so the docs are the final word for your version.
Next, Part 7: Specs as the source of truth puts one page at the centre of the desk: the written spec.
Setting up Claude Code or AI agents for your team?
I help teams build this: agents, RAG search and Claude Code setups that hold up in production.
Series
How Claude Code works
- How Claude Code worksWhere Claude runs
- How Claude Code worksSessions and forks
- How Claude Code worksSkills, hooks and subagents
- How Claude Code worksMCP servers and plugins
- How Claude Code worksPermissions and safety
- How Claude Code worksContext and costyou are here
- How Claude Code worksSpecs as the source of truth
- How Claude Code worksContract first
- How Claude Code worksVerify against the spec
- How Claude Code worksHandoffs and memory
- How Claude Code worksYour setup as a kit
- How Claude Code worksRolling it out