Skip to main content

Managing a Long Session

Prompt caching is about what context costs. The question you’ll face more often is what to do with that context once a session gets long, or starts going sideways.

A session is one conversation with the agent, and its context is everything the model can see in it. Both get heavier with every turn: one response to a message you send, however many files it reads or commands it runs.

Four moves

You’ve basically got four. All but the first are slash commands (commands you type that start with /):

  • Continue: Do nothing. The harness summarizes the conversation for you when it needs to. Claude Code calls this auto-compaction.
  • /compact: Summarize now, at a moment you choose.
  • /clear: Start over with an empty conversation.
  • /rewind: Truncate back to an earlier turn and, optionally, restore the files to match. The restore only covers files the agent has edited with its file tools. Recovering a Failing Session covers what it misses, and how to salvage what you learned before a /clear.

The short version: undo is for wrong; condense is for long.

If something was wrong, undo it. If it’s merely long, shrink it without losing the thread. Mix those up and you compact a mistake into a summary where it looks like a decision.

SituationReach for
Work is continuous, going well, and context is filling upContinue
You’ve hit a natural phase boundary and the work continues/compact, deliberately
The next task is unrelated to this one/clear
The original attempt and two corrections have failed, and you’re patching patches/clear, after you salvage what you learned
One specific edit was wrong/rewind
You’re in the middle of verificationNone of them. Finish the check first.

That last row matters more than it looks. After a compaction, “the tests passed” is a sentence in a summary, not an observation. Check the result before you shrink the evidence away.

Tasting notes

  • Compaction is cheap while the cache is warm: The summarization request carries your whole conversation, so it reads your main conversation’s prompt cache. That cache lasts an hour of inactivity on a Claude subscription (within your plan’s usage) and five minutes with an API key. Compact after it expires, and you pay to reprocess the entire history. Claude Code tries to save you from that: on the one-hour cache, a conversation over 200K tokens that sits idle for just under an hour gets compacted for you before the cache expires. Set idleCompaction to false in your settings if you’d rather choose the moment yourself.
  • /rewind is the cheapest move of the bunch: It truncates back to a prefix that’s already cached, as long as that cache hasn’t expired.
  • What reloads after /clear or /compact: Your project-root CLAUDE.md (the instruction file the harness loads at the start of a session; AGENTS.md in Codex) is re-read from disk. Nested CLAUDE.md files and path-scoped rules don’t come back until the agent reads a matching file again. Claude Code’s documentation lists the project-root file and rules without a paths: scope as re-injected from disk (auto memory, too), so put anything critical in one of the first two.
  • Editing CLAUDE.md mid-session does nothing yet: The change takes effect at the next /clear, /compact, or restart.
  • Summaries compound: Compact three times, and you’re working from a summary of a summary of a summary.
  • You can steer the summary: /compact focus on the auth bug fix tells the summarizer what to keep, and so does a “Compact Instructions” section in CLAUDE.md. It’s still a summary.
  • Rules can fall out of the summary: In one benchmark, agents violated a constraint 0% of the time while the constraint survived compaction, and 38% of the time once it got summarized away.

That 38% is the practical takeaway. A rule that has to survive belongs in a file that reloads or, better yet, in a permission rule (a setting that allows or denies specific tool calls) that doesn’t depend on the model remembering anything. User and Project Instructions covers where rules live, and The Enforcement Ladder covers which ones need more than a sentence.

The cheapest long session is the one where nothing important lives only in the conversation.

Last modified on .