Keep context lean
Sessions start with less context and add less per prompt, so they compact later and stay clear of the limit of the window.
Signs you need it
Section titled “Signs you need it”Open Context with the range at 30d and read Tips. This playbook applies when one of these four tips shows. The thresholds are the app’s own.
| Tip | The app shows it when | Mark |
|---|---|---|
| Sessions start with a large context | A project’s median starting context is 30,000 tokens or more. | ▲ Warning |
| Sessions compact repeatedly | A session compacted 3 times or more. | ▲ Warning; ● Critical from 6 compactions |
| Sessions reach the limit of the window | A session peaked at 80% or more of its window. | ● Critical |
| Tool results fill the context | A main-thread tool result is 100,000 bytes or more. | ▲ Warning; ● Critical from 400,000 bytes |
With several tips, start from one marked ● Critical. The strip lists the most severe first.
The same problem shows in three other places:
- Activity, Needs attention: “N sessions reached 80%+ of the context window.”
- Project, Context: sessions near the context limit is above 0.
- Live: the context meter in the status strip above a running session’s stream is in the warning color, which it takes above 80%.
The two other tips, The prompt cache breaks within sessions and Requests are priced on the long-prompt tier, are about cost. For those, use Spend less for the same output.
Diagnose
Section titled “Diagnose”Find out which of four causes you have. All steps but step 3 are on Context. The project picker and the range are the page’s filters. Tips sits above Context’s three tabs: Overhead and pressure holds Starting context, Window of a typical session and Window pressure; Growth and bloat holds Growth, What fills context and the Largest tool results drawer; Cache health holds the cost panels.
-
In Tips, select each tip that fired to expand it, then select N matching sessions under its advice. The Sessions matching list opens. If most sessions belong to one project, pick that project in the project picker for the next steps.
-
On Overhead and pressure, start with the map Sessions by start and peak in Window pressure for a fast split. Its four quadrants cut at a 30,000-token start and an 80% peak. Many dots in Heavy start (a heavy start and room left) point to overhead; many in Grew full (a light start and a peak at 80% or more) point to growth; Heavy and full has both. Select a quadrant to narrow the bars above it to its sessions.
Then, in Starting context, read the project’s row in Starting context by project. Compare 10th percentile with Median. The 10th percentile approximates the fixed overhead: what every session reads before your first prompt.
- If the 10th percentile is close to the median, the overhead is the problem. Go to step 3. Rule of thumb: “close” is three quarters of the median or more.
- If the 10th percentile is far under the median, the first prompts are large (pasted logs, long attached files). Go to Start a new session for each task.
-
Split the overhead. Open the project’s Project page and go to Context. Select Measure now. It runs
claude -p "/context"in the project’s folder: it calls no model, but it starts the project’s MCP servers and hooks as a new session does. The grid’s legend then lists the overhead by category, such as Memory files and MCP tools, and the disclosure What loads before your first prompt ranks the categories by tokens. Open it. Under each category it ranks the MCP servers, memory files, custom agents and skills, and shows how often Claude Code called each server and skill in the view. Note the largest category and its tokens.- A Codex project has no Measure now: Codex records no
/context. Use step 4 for its MCP servers, and read itsAGENTS.mdyourself. The same holds for a Grok project:/contextis a Claude Code command.
- A Codex project has no Measure now: Codex records no
-
Back on Context, read the evidence line MCP servers called (fewest calls first) on the tip Sessions start with a large context. Set the range to 90d first. The line lists only the servers that the sessions called. Compare it with the servers you configured:
Terminal window claude mcp listFor Codex, the configured servers are the
[mcp_servers.<name>]tables in~/.codex/config.toml.A configured server that the line does not list was never called in the range. A server at the front of the line was called least. If that tip did not fire, use Largest contributors switched to By MCP server (in What fills context, on Growth and bloat): it lists the servers whose calls returned a result on the main thread.
-
On Growth and bloat, in Growth, read the tiles Added per prompt, Sessions compacted and Before the first compaction. Select Share of window above the chart and find the turn where the curve crosses the dashed line at 80%. With All projects selected, the table Growth by project gives the same figures for each project.
-
In What fills context, read Largest contributors. A row whose range reaches the dashed line at 100,000 bytes has results that large. Then open the drawer Largest tool results: Tool and Input show which file, command or query produced each of the 25 largest results. The bar Main thread / Subagents shows how much of the reading the main thread did itself.

| What you see | Cause | Fix |
|---|---|---|
| The 10th percentile is close to the median, and Memory files is the largest category. | The instruction files are long. | Trim CLAUDE.md or AGENTS.md |
| MCP tools is the largest category, or a configured server is missing from the called list. | MCP servers you do not call. | Remove the MCP servers you do not call |
| Added per prompt is high, and Largest tool results lists whole files, full logs or unbounded searches. | Large tool results. | Keep tool results small |
| Sessions compact or peak at 80% with an ordinary start and no large result. | Sessions run across many tasks. | Start a new session for each task |
More than one cause can apply. Fix the largest category first.
Trim CLAUDE.md or AGENTS.md
Section titled “Trim CLAUDE.md or AGENTS.md”The file to edit is under Memory files in What loads before your first prompt. The line under each file gives its folder. Every line of it is read at the start of every session.
-
Delete what the agent can read in the repository when it needs it: file listings, copied API documentation, code samples that exist in the code.
-
Delete the rules that a formatter, a linter or a test already enforces.
-
In
CLAUDE.md, replace each@pathimport of a long file with the plain path. An import loads the whole file at the start; a path costs one line, and the agent reads the file when the task needs it:## Reference (read only when the task needs it)- Release steps: docs/release.md- Database schema: docs/schema.md -
In Claude Code, move the rules for one directory into a
CLAUDE.mdin that directory. Claude Code loads it only when it works on files there.
If Skills or Custom agents is the largest category instead, remove the skills, plugins or agents you do not use. Under Skills, the list ranks the skills by tokens and says how often Claude Code called each.
Then select Measure now again. Memory files shows the new size at once.
Remove the MCP servers you do not call
Section titled “Remove the MCP servers you do not call”A configured server puts its tool definitions in the prompt of every session, called or not, unless the agent defers them (see the note under the steps).
-
Remove each server that step 4 found configured and never called in 90 days:
Terminal window claude mcp remove <name> -
If the server is defined in the project’s
.mcp.json, delete its entry there. That file is in git, so the change reaches everyone who uses the repository. -
For Codex, delete the server’s
[mcp_servers.<name>]table in~/.codex/config.toml. For Grok, remove the server in the Grok CLI’s own MCP configuration:claude mcpand.mcp.jsondo not reach it. See Supported agents. -
For a server you call in a few projects only, remove it as in step 1, then run
claude mcp addfor it inside each of those projects. Without a scope option,claude mcp addadds the server to the current project only.
Before you remove anything, read the line under the legend in the Project page’s Context: “N deferred tokens of tools are not loaded”. Deferred tools take no context. If most of the tokens of the MCP tools are deferred, removing servers frees little: fix another cause first.
Then select Measure now again. MCP tools shows the new size at once.
Keep tool results small
Section titled “Keep tool results small”Paste this into the project’s CLAUDE.md. It adds six lines to the starting context.
## Context hygiene- Read a large file in parts: use `Read` with `offset` and `limit`.- Pipe long shell output through `head`, `tail` or `grep`. Never print a whole log or a whole test run.- Cap a search: use `head_limit`, or list file names only.- Ask an MCP tool for a small page: pass its limit or page-size argument.- For bulk reading (many files, a long log, a broad search), use a subagent and keep only its short report.For Codex or Grok, paste it into the agent’s instruction file, such as AGENTS.md, without the first and the third line, which name Claude Code tools.
Keep only the lines that match the Tool column of Largest tool results:
| Tool in the list | Line to keep |
|---|---|
Read |
Read a large file in parts. |
Bash, Codex’s exec_command or Grok’s run_terminal_command |
Pipe long shell output. |
Grep, Glob |
Cap a search. |
| A tool with an MCP server under its name | Ask an MCP tool for a small page. |
| Any of them, when Main thread holds nearly all of the bar | Use a subagent for bulk reading. |
Start a new session for each task
Section titled “Start a new session for each task”These are habits. Each has a trigger.
- When a task is done and committed, start a new session, or run
/clearin Claude Code, before the next task. In Codex or Grok, start a new session:/clearand/compactbelow are Claude Code commands. - When the context meter in Live’s status strip turns to the warning color, finish the step, then run
/compactor start a new session. As the tip says, the last 20% of the window costs the most and compacts the worst. - When you are about to paste a log or a long file, give the agent the path instead.
- When a session has compacted twice (two marks on that meter), start the next task in a new session. The tip Sessions compact repeatedly counts a session from its third compaction.
Verify
Section titled “Verify”Before you act, note today’s figures. On Context, set the project filter to the project and the range to 30d, then write down Median in Starting context by project, and the tiles Added per prompt and Before the first compaction in Growth. The app has no custom date range, so you need these to compare with.
The same day, for a trimmed file or a removed server: Measure now shows a smaller Memory files or MCP tools figure than the one you noted in step 3 of Diagnose.
After 7 days of work in the project, set the range to 7d on Context, with the same project filter, and read:
| Figure | Where | Expected |
|---|---|---|
| Median starting context | Starting context by project | Lower than your note. Under 30,000 tokens, the tick sits left of the dashed line and the tip Sessions start with a large context no longer names the project. |
| Newest point | Median start by week | Lower than the point before it. A hollow dot rests on fewer than 3 sessions: wait one more week. |
| Added per prompt | Growth | Lower than your note. |
| Before the first compaction (median turns) | Growth | Higher than your note. Better still, the tile is gone and a line in its place starts “No session in this view compacted”. |
| “N sessions reached 80%+ of the context window.” | Activity, Needs attention, at 7d | A smaller N, or no such line. |
If a figure did not move:
- A session is in the view when it has a request in the range, with the figures of its whole life. A session you started before the change and resumed since still shows its old start. Wait until the view holds only new sessions.
- A change to
CLAUDE.md,AGENTS.mdor the MCP servers applies to new sessions only. - If the median fell but sessions still compact, the cause is growth, not the start: go back to step 5 of Diagnose.
Related
Section titled “Related”- Context: every panel and tip used here.
- Project: the context grid, the snapshot and Measure now.
- Live: the context meter in a running session’s status strip.
- Supported agents: what each agent records, and which commands it has.
- Context windows and plan limit windows: what a context window is and how the app measures it.
- Metric glossary: the definition of each figure.
- Spend less for the same output: cache breaks and the long-prompt tier.
- Weekly 15-minute review: where this check sits in a routine.