I'm afterimaginary. I build tools and workflows for coding agents. I'm fluent in Claude Code and Codex, mostly Claude Code right now, and also use OpenCode and Pi. I'm open to work on agent tooling and developer workflows. You can see my open source work on the projects page, or say hello at hello@afterimaginary.dev.

See what Claude Code keeps when it compacts

Compaction has a bad reputation. It gets treated as something to avoid, a sign a session went on too long, or a reason to start fresh before it happens. Part of that is because it’s a black box: when a Claude Code conversation compacts, all the app shows is a “compacted” marker. It doesn’t show the summary Claude wrote, what came back after it, or what was lost.

Knowing what compaction does makes it less of a mystery, and you can configure and steer it like the rest of Claude Code.

What’s in context after a compaction

In order from the top of the context, based on Anthropic’s list of what survives and what session transcripts show:

Part After compaction
System prompt, tools, output style Unchanged
Project-root CLAUDE.md, unscoped rules, auto memory Reloaded from disk
Nested CLAUDE.md files and path-scoped rules Reloaded when the agent works in that directory again
The summary New, written by Claude from everything before the compaction
Recently read or edited files Up to five re-read; files over 5k tokens kept by path only
Invoked skills Re-attached, 5k tokens each and 25k total, oldest dropped first
Skill descriptions, the plan, git status Reloaded
Background commands and subagents Keep running; Claude gets a reminder of which ones are running
SessionStart hooks matching compact Run again, and their output is added
The end of the conversation Kept word for word
Everything else said before the compaction Gone, except what the summary kept

The last two rows are the easiest to misunderstand. Claude Code doesn’t keep the last few turns, only the tail of the current one: the latest assistant reply and whatever came right after it. If the agent was mid-task, it’s the tool calls still running and their results.

The summary

Summaries follow the same outline each time:

  • Primary Request and Intent
  • Key Technical Concepts
  • Files and Code Sections
  • Errors and fixes
  • Problem Solving
  • All user messages
  • Pending Tasks
  • Current Work
  • Optional Next Step

They’re usually a few thousand tokens, roughly 2k to 4.5k.

“All user messages” doesn’t mean all of them. Claude writes that section like the rest, so some messages are quoted and others are paraphrased or folded together. In a long session, a later summary may list only the messages since the previous compaction, with older ones reduced to a line in Primary Request and Intent.

Each compaction summarizes a conversation that starts with the previous summary, so anything one summary drops is gone from every summary after it. The full transcript is still on disk, but Claude only sees it if it reads it.

Seeing it

The compaction viewer is a plugin I built that shows what Claude Code doesn’t. It adds a panel beside the conversation, in the terminal or the desktop app. The overview breaks down what’s in context after a compaction, matching the table above:

The viewer’s overview after a compaction: about 22.4k tokens in context, made up of the summary, 2 recent messages kept word for word, 5 files (2 by name only), 2 skills, the plan, CLAUDE.md, a background task and the system prompt

In this demo session, context went from 168k tokens to about 22.4k, and most of what’s left is the system prompt and tools. The summary itself is 377 tokens.

The diff between compactions shows what got dropped. Between the demo’s second and third compaction, “Tailwind for styling” disappeared from Key Technical Concepts, along with a fixed bug from Errors and fixes:

The viewer’s Inline tab in a terminal: compaction #3’s summary compared with #2, with added lines in green and removed lines struck through, including “Tailwind for styling” and a fixed server action bug

To install it, run this at a Claude Code prompt:

/plugin install compaction-viewer --marketplace afterimaginary/claude-plugin-context-inspector

Open it with /compacted, or with the N× badge in the footer once the conversation has compacted.

Configuring when it runs

By default, Claude Code picks an auto-compact window tuned for the model. You can change it:

  • /autocompact 500k sets the window for the current model and saves it. /autocompact auto goes back to the default.
  • autoCompactWindow in settings applies to every model, as a token count of at least 100k.
  • claude --autocompact 500k sets it for one launch.
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW sets it in scripts and cloud environments, and overrides the rest.
  • CLAUDE_AUTOCOMPACT_PCT_OVERRIDE compacts at a percentage of the window, like 50. It can only make compaction happen earlier.
  • autoCompactEnabled: false turns auto-compaction off, along with idle compaction. /compact still works.

Auto-compaction can also prepare the summary in the background before the window fills. When it reuses that summary, compacting is almost instant instead of taking about a minute.

Steering what it keeps

The most reliable way to keep something is to put it in a file. CLAUDE.md, memory, the plan and recently edited files come back after every compaction. A decision that only exists in chat depends on the summary keeping it. If something is already gone, my backread plugin lets the agent search the transcript from before the compaction.

  • claude-code
  • agents
  • compaction