Claude Code context reconciliation, two problems hiding under one phrase.
Most pages on this topic point at /compact and call it a day. That is half the answer. The other half, the half that actually breaks production agents on real client codebases, is the gap between what Claude Code thinks your filesystem looks like and what is actually live after parallel agents, auto-commit cron jobs, and human saves move the world. They are different problems with different fixes.
Direct answer, verified 2026-05-01 against Anthropic docs
There is no single feature called “context reconciliation.”
The phrase, as it shows up in posts, GitHub issues, and engineer chatter, is doing double duty for two different problems:
- 1. Intra-session compaction. When input tokens approach the model's context window, Claude Code summarizes older conversation turns into a
<summary>block and continues with the compacted history. The platform drives this for you. The user-facing handle is the/compactcommand and the/contextintrospection command. - 2. World-state reconciliation. The gap between Claude Code's cached beliefs about your files (and branch, and running processes, and env) and what is actually true right now after another writer (you, a teammate, a parallel agent, a cron job, a pre-commit hook) has touched the repo. The platform helps a little. Most of the fix is in your tool contract and your workflow.
Source for the compaction definition: platform.claude.com/docs/en/build-with-claude/compaction. World-state behavior is documented through the Edit tool's own error contract (see below) and through the Claude Code context window docs at code.claude.com/docs/en/context-window.
Problem 1: token-window compaction. Mostly solved.
Compaction is the part of “reconciliation” that has a real, named, platform-level mechanism behind it. The shape of the feature is well documented and stable. When the input token count approaches the configured trigger for the active model, the runtime takes the older turns of your conversation, generates a summary, wraps it in a <summary>...</summary> tag, and replaces the older raw turns with that single block. The response continues from the compacted state.
The reason this rarely surfaces as a real production bug is that the platform is the only writer to this state. Nothing else on your machine can mutate the conversation transcript. The trigger, the summary, and the resumed history all live inside one process. If you want visibility into where your tokens are sitting, the /context command in Claude Code prints the breakdown: system prompt, tools, memory files, skills, conversation history. If you want to compact early on purpose (for example before a long multi-tool stretch where you want fresh headroom), /compact triggers it manually.
The one nuance worth knowing: compaction summarizes in-context state. If a load-bearing fact for a future decision lives only inside a tool output you read twenty turns ago (a directory listing, a SQL row count, a config diff), the summary may compress it to nothing. The fix is mechanical: any time you depend on a fact that lives in a transient tool output, write it down into a CLAUDE.md note or a task scratch file. That copy survives compaction. The original turn may not.
Problem 2: world-state reconciliation. Where the bugs actually live.
Compaction has one writer. World state has many. While Claude Code is in the middle of a task, every one of these can move the truth out from under it without telling it:
- You save a file in your editor, fixing the typo Claude was about to fix.
- A teammate pushes a commit to
mainthat conflicts with the branch Claude is working on. - A pre-commit hook reformats the code Claude just wrote, so the next Read shows different bytes than the Edit produced.
- A second Claude Code session, running in another worktree, edits the same file at the same time.
- A cron job auto-commits and pushes uncommitted work every minute. The diff Claude was reading from
git diffis gone by the time it tries to act on it.
None of those raise an exception inside Claude Code. They just silently invalidate the agent's mental model of the world. The agent's next Edit, written against the stale picture, is the bug. This is what people are reaching for when they say “context reconciliation” and mean something different from /compact.
The platform's own primitive: Read-before-Edit
The most underrated thing in Claude Code is that the Edit tool refuses to run if you have not Read the file in this session. The tool description spells it out: You must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file. When you violate it, the runtime returns the same error, by name, every time:
That contract is the platform's native world-state reconciliation primitive. It forces the agent to materialize the current bytes of the file into context before proposing a diff. Most failure cases people blame on “reconciliation” are cases where this primitive is either disabled (some third-party agent frameworks let you Edit without first Reading) or technically satisfied but stale (the Read happened ten minutes ago, before another writer touched the file).
Naive workflow vs. reconciliation-aware workflow
The before/after below is the actual delta between a session that ships a broken commit on a busy repo and a session that does not. Both use the same tools. The difference is purely in when you re-materialize state.
Same task, two sessions, on a repo with a coworker and an auto-commit cron
The agent reads the file once at the start, writes a long plan, runs a build, then edits. Build errors in unrelated files panic it into reverting work that was not its own. The git state at commit time is not what it thought.
- Read src/app/page.tsx at minute 0
- Plans 8 edits across 4 files
- Edits page.tsx at minute 17 against the cached Read
- Build fails in a 5th file the coworker just pushed
- Tries to 'fix' the unrelated file from memory of the codebase
- Commit includes accidental revert of coworker's change
Five reconciliation patterns I put in every CLAUDE.md
These are not theoretical. They are the lines I add to client CLAUDE.md files when I scope an agent rollout. Each one is a workflow rule the model picks up on session start, so the cost of compliance is paid once at write time, not per turn.
Workflow rules that keep agent state in sync with reality
1. Re-Read before Edit if anything else might have written
After a build, a long-running shell command, a pause and resume, or any teammate push: Read the file again before the next Edit. The Edit tool's contract handles the cold-start case. This rule handles the in-session drift case. Cost: a few hundred input tokens. Benefit: you stop overwriting changes you did not author.
2. Treat git status and git log as ground truth, not memory
Never trust a remembered git state. Re-run `git status` and `git log -5` right before any commit, push, or branch operation. If a commit appeared that you did not author, do not investigate, it is almost certainly the auto-commit agent or a coworker. Document those external writers in CLAUDE.md so the agent expects them.
3. Quarantine unrelated build errors
If you see compile errors in files you did not edit, do not try to fix them. Wait 30 seconds and retry the build, the parallel agent (or a watcher) is likely mid-edit and will fix the break itself. Stop racing to repair other writers' transient state.
4. Pin load-bearing facts to disk before /compact
Compaction is good at preserving the shape of the conversation but lossy on facts that lived inside transient tool outputs. Before a long stretch, write the load-bearing facts into the project's CLAUDE.md or into a task note. The durable copy survives the summary.
5. Document external writers in CLAUDE.md
Cron-based auto-commit agents, watchers, formatters, and second-Claude sessions are normal in real client codebases. Spell out which ones are running where. The agent reads CLAUDE.md on start, so unexpected commits and reformatted bytes stop being surprises and become expected behavior with a known recovery path.
What does the diff between “trust memory” and “reconcile” look like in practice?
Two snippets, same task, both in the same Claude Code session on the same repo. The left is what the agent does naturally if you do not ask it to reconcile. The right is what it does if you put the rules above in CLAUDE.md.
Tool calls in the last minute before a commit
# remembered Read from minute 0
Edit("src/app/api/route.ts", { ... })
Bash("npm test")
Bash("git add -A")
Bash("git commit -m 'wire up endpoint'")
Bash("git push")
The right column adds 5 cheap calls. Two of them are pure-read git calls (no I/O on the working tree). The other three are a Read of one file plus two narrower git operations. It is a few thousand extra input tokens, which on a cached prompt is fractions of a cent. The bug it prevents is “commit includes a revert of a change you did not write,” which is the actual production failure mode of agentic coding on shared repos.
Counterpoint: when the doc-based advice is enough
The /compact and /context advice that fills most of the existing material on this topic is genuinely sufficient for a real subset of users. If you are the only writer to the repo, do not have background agents running, and your sessions are short, the platform's built-in behavior covers you. Compaction will handle long sessions. The Edit tool's Read-before-Edit contract will catch the cold-start case. You probably do not need five workflow rules in your CLAUDE.md to ship safely.
Where the existing advice runs out is the moment a second writer shows up. That is most of my client work: SMB teams where the engineer is using Claude Code, a teammate is pushing on the same branch, a formatter runs on save, a cron is auto-committing, and a second agent is open in another worktree. In that environment the world-state side of reconciliation becomes the dominant source of bugs, and /compact is irrelevant to all of it.
What this looks like as a c0nsl engagement
For most teams the work to fix this is a CLAUDE.md rewrite plus two or three repo conventions, which fits the published $500 to $2,000 small integration tier on the homepage. For teams running multiple agents in parallel, custom tool wrappers, or a self-hosted Claude SDK setup, the right shape is closer to the $2,000 to $10,000+ custom system tier: a real audit of every place state can drift, an updated tool contract, and an eval harness that exercises the multi-writer cases. Either way, the rate is on the page, the scope is named up front, and the deliverable is a repo that does not ship a broken commit because two writers disagreed about what was on disk.
Audit your Claude Code workflow against the reconciliation cases
Bring one repo where Claude Code has shipped a wrong commit and your CLAUDE.md if you have one. I come back with the specific drift sources, a fixed CLAUDE.md, and a quote at the published rate.
Frequently asked questions
What does 'context reconciliation' actually mean in Claude Code?
It is not a single feature. The phrase is used in the wild to describe two different problems. The first is intra-session compaction: when token usage gets close to the context window, Claude Code summarizes older conversation turns into a single summary block so the session can keep going. The second is world-state reconciliation: the gap between what Claude Code believes about your filesystem (file contents, branch, running processes) and what is actually live after parallel agents, cron jobs, or humans have also been writing. Token-side compaction is a closed-loop problem the platform handles for you. World-state drift is the bug that ships broken commits.
What triggers automatic compaction in Claude Code?
When input tokens approach the configured trigger threshold for the model's context window, the API generates a summary of the conversation, wraps it in a <summary></summary> block, and continues the response with the compacted history in place of the older turns. Different surfaces use different trigger points (the IDE extension is more conservative than the CLI, since it reserves headroom for the compaction call itself). The /context command shows where your tokens are sitting right now (system prompt, tools, memory files, skills, conversation), which is the right thing to look at before deciding to /compact manually.
Why is world-state reconciliation harder than compaction?
Compaction has a single source of truth: the conversation history, which only Claude Code is allowed to mutate. World state has many writers. While Claude is in the middle of a task, you might save a file in your editor, a coworker might push to main, a pre-commit hook might reformat the code Claude just wrote, an auto-commit cron might commit and push uncommitted work, or a parallel Claude session might be editing the same file. Every one of those events invalidates Claude's cached beliefs without notifying it. Compaction is fully solved by the platform. World-state reconciliation has to be solved by the agent's tool contract and by the user's workflow.
How does Claude Code's Edit tool enforce world-state reconciliation?
The Edit tool refuses to run if you have not used the Read tool on that file at least once during the session. The error reads 'File has not been read yet. Read it first before writing to it.' This is the platform's reconciliation primitive: it forces the agent to materialize the current bytes of the file into context before proposing a diff against them, rather than editing from a stale memory of what the file looked like 30 minutes ago. Inside agentic frameworks that do not enforce this, you get the classic bug where a model 'edits' a file by overwriting it with content that is missing changes the user made in the meantime.
What is the cheapest workflow change that prevents most reconciliation bugs?
Re-Read before Edit any time something else might have written to the file. In practice this means: after you run a build or a long shell command, after a teammate pushes, after you pause a session and come back to it, and at the start of every plan-mode resume. The cost of an extra Read is a few hundred input tokens. The cost of an Edit against stale state is a broken commit and a lost user change. The Edit tool's hard contract takes care of the first-time case. The pattern above takes care of the in-session drift case.
Should I trust /compact to preserve my plan state?
Mostly yes for transcript content, partly no for in-flight ambient context. Compaction preserves named state like the active plan, custom tool config, and session metadata, and it summarizes the rest. What it does not preserve well is implicit state that lives in tool outputs you read 20 turns ago (a directory listing, a database row count, a config file you grep'd). If something is load-bearing for a downstream decision, copy the relevant fact into your CLAUDE.md or into a written-down task note before /compact runs. That way the durable copy survives the summary.
What is the right way to run multiple Claude sessions on the same repo?
Treat the filesystem as the only shared truth and treat each session's context as private. Concretely: stop assuming a file is unchanged just because your last Read of it succeeded; re-Read before every Edit if any other writer has had a chance to act. If you see compile errors in files you did not edit, do not race to fix them, the other agent is most likely mid-edit and will fix its own break in the next minute. And keep a per-project CLAUDE.md that documents which agents are allowed to write where, so each session has a published convention to follow rather than a private guess.
Where do background auto-commit agents fit in?
If a cron job is auto-committing and pushing uncommitted changes across your repos every minute, that is a third writer Claude has to reconcile against. Two practical implications: (1) git status output is the single freshest source of truth for whether your changes are still local; do not rely on a `git status` you ran 10 minutes ago. (2) If a `git log` shows commits you did not author, those are almost certainly the cron, not a problem to investigate. The fix is to write the cron's existence into your CLAUDE.md so every session reads it on start, rather than re-discovering the surprise each time.
Does longer context (1M tokens) make reconciliation a non-issue?
It pushes back the compaction problem, not the world-state problem. A 1M-token window means you almost never need /compact during a long session, which is a real ergonomic win. It does nothing for stale-file drift: Claude's mental model of `app/api/route.ts` does not refresh on its own just because there is more headroom in the context. World-state reconciliation is a tool-contract problem, not a context-size problem.