← All work guides

GuideClaude Code

Claude Code context window: keep the next task clear

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.

This 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.

Inspect the session before changing it

In 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.

Do 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.

Make a handoff with claims you can recheck

Suppose 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:

# Receipt Lab: next task

Goal: return the amount left to pay after a whole-percent discount.
Working files: discount.py; tests/test_discount.py.
Contract: integer cents, percent from 0 through 100; reject other percentages.
Known gap: percent=0 and percent=100 need explicit regression tests.
Verified example: total_after_discount(1200, 25) == 900.
Next action: inspect the function, then propose tests for both endpoints.
Do not edit files in this session. No dependency changes are needed.

This 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.

The current function is:

def total_after_discount(cents, percent):
    if type(cents) is not int or cents < 0:
        raise ValueError("cents must be a nonnegative integer")
    if type(percent) is not int or not 0 <= percent <= 100:
        raise ValueError("percent must be an integer from 0 to 100")
    return (cents * (100 - percent) + 50) // 100

The 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.

Test whether a fresh session can continue

Start a new session in this scratch project and give it a bounded request:

Read HANDOFF.md, discount.py and tests/test_discount.py.
Check whether the handoff matches the files. Then propose the two missing
endpoint tests, with exact inputs and expected outputs.
Do not edit files or run commands. Call out any conflict you find.

The 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.

This 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.

Choose compact, clear or delegate

For 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.

For 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.

Reduce future clutter at the source

  • Ask for the failing test and a bounded log excerpt rather than an entire build log.
  • Keep one current plan. Mark an abandoned approach as abandoned so it does not compete with the accepted one.
  • Name exact files when you already know them. Repeating a repository-wide scan can add noise without answering a new question.
  • Request a result format that fits the decision: a diff, a test result, or a short list of unresolved facts.

There 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.

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.

Sources and version notes

Checked against the current documentation on September 24, 2026. Command availability can vary with your installed version; check claude --version.

Put AI to work, one useful guide at a time.

Get Something Big: practical AI guides, reviews and the roundup. Free.