{"slug": "claude-code-context-window-keep-the-next-task-clear", "title": "Claude Code context window: keep the next task clear", "summary": "A walkthrough published for Claude Code users recommends managing the coding agent's context window by writing a short HANDOFF.md note plus current files rather than relying on a universal token limit, since available context and compaction behavior depend on the model, plan and configuration. The guide instructs users to run the /context command to inspect what occupies the session, use /compact with a stated focus such as preserving the discount contract and checked outputs, and use /clear when switching to unrelated work. It demonstrates the approach with a Python discount function, where a fresh session reading the handoff should propose total_after_discount(1200, 0) == 1200 and total_after_discount(1200, 100) == 0 without editing files or adding dependencies.", "body_md": "A large context window is useful only if the right information is in it. When a coding conversation gets crowded, start by reducing the material that no longer helps the next decision: repeated logs, obsolete approaches, full-file dumps and work from a different task.\n\nThis walkthrough uses a small Python change to show a practical alternative: a short handoff plus the current files. The objective is continuity you can verify, not a claimed percentage reduction in tokens or cost.\n\n## Inspect the session before changing it\n\nIn Claude Code, run `/context` to inspect what is taking space. A large total alone does not tell you which part to remove. Project instructions, loaded tools and the current task's evidence serve different purposes. If a long log contains the one error you need, keep that error and the command that produced it rather than treating the entire log as equally useful.\n\nDo not work from a universal “Claude Code has exactly X tokens” rule. The available context and compaction behavior depend on the model, plan and configuration. Inspect your own session, and check the current documentation when changing models.\n\n## Make a handoff with claims you can recheck\n\nSuppose Receipt Lab already handles a 25-percent discount, and the next change is to add regression tests for the endpoints. Write this as `HANDOFF.md`:\n\n```\n# Receipt Lab: next task\n\nGoal: return the amount left to pay after a whole-percent discount.\nWorking files: discount.py; tests/test_discount.py.\nContract: integer cents, percent from 0 through 100; reject other percentages.\nKnown gap: percent=0 and percent=100 need explicit regression tests.\nVerified example: total_after_discount(1200, 25) == 900.\nNext action: inspect the function, then propose tests for both endpoints.\nDo not edit files in this session. No dependency changes are needed.\n```\n\nThis is a working note, not a transcript summary. It separates a known result from the remaining task, names the files, and says what should happen next. The “do not edit” instruction makes the first pass a review of the handoff, so you can catch a misunderstanding before changing code.\n\nThe current function is:\n\n``` python\ndef total_after_discount(cents, percent):\n    if type(cents) is not int or cents < 0:\n        raise ValueError(\"cents must be a nonnegative integer\")\n    if type(percent) is not int or not 0 <= percent <= 100:\n        raise ValueError(\"percent must be an integer from 0 to 100\")\n    return (cents * (100 - percent) + 50) // 100\n```\n\nThe accompanying test file should have the existing quarter-off and invalid-percentage checks, while the zero- and full-discount cases remain to be added. If those facts are no longer true, update the handoff before using it. A concise stale note is still stale.\n\n## Test whether a fresh session can continue\n\nStart a new session in this scratch project and give it a bounded request:\n\n```\nRead HANDOFF.md, discount.py and tests/test_discount.py.\nCheck whether the handoff matches the files. Then propose the two missing\nendpoint tests, with exact inputs and expected outputs.\nDo not edit files or run commands. Call out any conflict you find.\n```\n\nThe useful answer proposes `total_after_discount(1200, 0) == 1200` and `total_after_discount(1200, 100) == 0`. It should not reimplement the function, add a service or invent a dependency. You can run the existing tests independently and later add the proposed tests in a separate implementation step.\n\nThis is a stronger continuity check than asking, “Do you remember what we were doing?” The fresh session has to connect a claim to actual files and return outputs you can verify.\n\n## Choose compact, clear or delegate\n\nFor the same ongoing task, `/compact` accepts a focus, such as `/compact preserve the discount contract, checked outputs, changed files and next test`. Compaction summarizes context; it is not a substitute for checking the source files afterward. When moving to unrelated work, `/clear` gives you a clean conversation. Save the handoff before clearing.\n\nFor a large side investigation, ask a subagent to return a small result: relevant file paths, the conclusion and the evidence that supports it. If you bring its complete transcript back into the main session, you have moved the clutter rather than reduced it.\n\n## Reduce future clutter at the source\n\n- Ask for the failing test and a bounded log excerpt rather than an entire build log.\n- Keep one current plan. Mark an abandoned approach as abandoned so it does not compete with the accepted one.\n- Name exact files when you already know them. Repeating a repository-wide scan can add noise without answering a new question.\n- Request a result format that fits the decision: a diff, a test result, or a short list of unresolved facts.\n\nThere is no need to make every prompt tiny. Keep the context that changes the answer: constraints, examples, acceptance criteria and actual failures. Remove repeated narration before removing evidence.\n\n**What we checked:** One fresh Claude Code 2.1.281 session read the handoff and source files, identified the two missing endpoint tests, and returned the expected 1200 and 0 outputs without editing. We checked those outputs independently in Python. This tests continuity from a handoff; it does not measure compaction quality or token savings.\n\nUse [project memory](https://somethingbig.ai/work/claude-code-memory) for durable conventions and a [narrow reviewer](https://somethingbig.ai/work/claude-code-subagents) for a separate investigation.\n\n## Sources and version notes\n\nChecked against the current documentation on September 24, 2026. Command availability can vary with your installed version; check `claude --version`.", "url": "https://wpnews.pro/news/claude-code-context-window-keep-the-next-task-clear", "canonical_source": "https://somethingbig.ai/work/claude-code-context-window", "published_at": "2026-09-24 00:00:00+00:00", "updated_at": "2026-09-24 07:31:03.924430+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "developer-tools", "large-language-models"], "entities": ["Claude Code", "Anthropic", "Receipt Lab", "total_after_discount"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/claude-code-context-window-keep-the-next-task-clear", "markdown": "https://wpnews.pro/news/claude-code-context-window-keep-the-next-task-clear.md", "text": "https://wpnews.pro/news/claude-code-context-window-keep-the-next-task-clear.txt", "jsonld": "https://wpnews.pro/news/claude-code-context-window-keep-the-next-task-clear.jsonld"}}