Claude Code lost context after compacting. What survives, and how do I keep the rest?
Compaction replaces the conversation with a summary, so details that lived only in the chat get
vaguer or drop out. What lives in files comes back: the project-root CLAUDE.md,
unscoped rules and auto memory are re-injected from disk, and Claude Code re-reads up to five files
it recently read or edited. To keep the rest, put durable facts in CLAUDE.md, steer
the summary with /compact focus on ... or a "Compact instructions" section, and re-add
live state with a SessionStart hook that matches compact.
BuildGist is a Mac app for Claude Code, Cursor and Codex. Download for Mac.
What survives compaction, and what does not
Anthropic's context-window page lists what happens to each kind of content:
- Re-injected from disk: the project-root
CLAUDE.mdand rules withoutpaths:, auto memory, and a plan written in plan mode. - Reloaded only when needed: nested
CLAUDE.mdfiles and rules withpaths:. They come back when Claude next touches a matching file, not straight away. - Summarized: the conversation itself, including context hooks added earlier.
- Re-read: up to five files Claude read or edited, the most recently modified first. A file over 5,000 tokens comes back as a path without its content.
So the losses are predictable: an exact error message, the reason you rejected an approach, a rule you typed in chat but never wrote down, and a path-scoped rule until its file is touched again.
1. See it coming
Type /context to see what is filling the window. Claude Code compacts automatically
near the limit. /autocompact with a token count, for example
/autocompact 500k, sets how full it gets before the automatic pass runs.
2. Compact on your terms
At a natural break, compact yourself and say what matters:
/compact focus on the auth bug fix: keep the failing test name, the error text,
and the two approaches we ruled out
To compact only part of the chat, type /rewind, choose a message, and pick
Summarize from here or Summarize up to here.
3. Tell every compaction what to keep
Add a section to the project-root CLAUDE.md:
# Compact instructions
Keep test output, error messages, file paths and decisions with their reasons.
Anthropic's costs page documents this section. Since the root CLAUDE.md is
re-injected, the instruction is there for every compaction.
4. Re-add live state after compacting
A SessionStart hook with the compact matcher runs after each compaction,
and what it prints is added to the new context. In .claude/settings.json:
{
"hooks": {
"SessionStart": [
{ "matcher": "compact",
"hooks": [ { "type": "command", "command": "cat HANDOFF.md; git log --oneline -5" } ] }
]
}
}
Keep HANDOFF.md short: the goal, what is done, what failed, and the next step. If
it goes stale, the hook repeats stale facts, so update it as the task moves.
5. Move rules that must persist
Path-scoped rules and nested CLAUDE.md files are summarized away with the chat. If
one has to hold for the whole session, drop its paths: frontmatter or move it to the
project-root CLAUDE.md.
If it already happened
Run git status and git diff --stat to see what is really done. Tell
Claude Code what the summary missed, in one message. If the session has drifted too far, a fresh
one with a short note is often faster: /rename it first, so /resume can
find the old one. The same trade-off for Codex is in
what to do when the Codex context window is full,
and for Cursor in Cursor says your conversation is
too long.
Where BuildGist helps
BuildGist keeps a record outside the chat. For each meaningful run it writes a plain-English explanation in its Inbox: what changed, uncommitted work included. It records the request you typed, the files changed with line counts, and the tests that ran with their result, so a summary that lost the thread does not lose that. When you start a new session, in Claude Code or in Cursor or Codex, its card offers the task, and Continue carries your own words into the new chat.
Questions
Does Claude Code reload CLAUDE.md after compaction?
The project-root CLAUDE.md and unscoped rules are re-injected from disk. Nested CLAUDE.md files and path-scoped rules reload only when Claude touches a matching file.
Can I stop Claude Code compacting mid-task?
Claude Code compacts automatically near the limit so the session can go on. Use /context to watch it, compact yourself at a break, or change the threshold with /autocompact.
What is the difference between /compact and /clear?
/compact keeps working in the same session from a summary. /clear starts with an empty context. Run /rename before /clear, and /resume brings the old session back.
Sources
- Claude Code context window, costs and hooks guide, checked October 25, 2026.
What you need
- A Mac with Apple silicon and macOS 12 or later.
- Claude Code, Cursor or Codex.
- A Git project. No commit, push, remote or GitHub repository is needed.
- A GitHub account, to sign in. BuildGist does not access your GitHub repositories.
Codex needs you to approve BuildGist once, in Codex. BuildGist shows the steps. Setup is in Getting started.
To explain a run, your computer sends BuildGist what that run needs, and BuildGist passes it to Anthropic. BuildGist does not keep this material. It does not send your whole repository, files the run did not change, or files named like secrets, such as .env files and keys. It keeps the explanation and short cited excerpts of changed code, at most 12 lines each. Secret masking is best-effort. Privacy has the full list.
Every account gets 7 days of BuildGist Pro free, with no card. The 7 days start at your first explanation or Continue handoff. Nobody is charged when the trial ends. After that, BuildGist Pro is $12 per month, plus any applicable tax shown at checkout. See pricing.
Try BuildGist Download for Mac
Apple silicon, macOS 12 or later. United States, 18 or older.
Related
- What did Claude Code change?
- Switch from Claude Code to Codex
- Understand code an agent wrote
- Hand off Claude Code to Cursor
- Review what Codex changed
- You’ve hit your session limit in Claude Code
- You’ve hit your usage limit in Codex
- Keep context across agents
- Review AI code before merging
- BuildGist or the git diff
- Claude Code session history
- Undo Claude Code changes
- BuildGist vs CLAUDE.md, AGENTS.md and HANDOFF.md
- Keep context from Claude Code to Cursor
- Resume an agent session in another tool
- BuildGist vs Conductor
- Codex context window full
- Undo Codex changes
- Cursor usage limit reached
- Review Cursor agent changes
- Codex session history location
- Your conversation is too long in Cursor
- One default coding agent, or two?
- Tools that summarize agent sessions
- Switch from Codex to Claude Code
- Move from Cursor to Claude Code
- Switch from GitHub Copilot to Claude Code
- Move from Windsurf to Cursor
- Switch from Gemini CLI to Claude Code
- Coding agent crashed mid-task
- What commands did the agent run?
- Turn an agent session into a PR description
- Which coding agents read AGENTS.md?
Questions: kayvanandre@gmail.com.