Claude Code’s Remote Auto-Compaction Bug Turns Context Management Into Hidden Runtime State
Context compaction is the garbage collector for coding-agent state. Nobody wants to think about it until it silently stops running.
That is why Claude Code issue #70477 is more interesting than a routine token-cost complaint. The report says remote or bridge-attached Claude Code sessions can skip threshold auto-compaction and ignore CLAUDE_AUTOCOMPACT_PCT_OVERRIDE unless an explicit auto-compact window is configured. The observed result: a remote session grew to roughly 238k tokens with no synchronous auto-compaction, despite an 80% override and signs that background precompute was otherwise enabled.
If true, this is a state-machine bug with a billing symptom. The user believes they are operating under one context policy. The runtime is effectively operating under another. In long agent sessions, that difference affects cost, latency, model behavior, prompt caching, and reliability.
Remote should not mean different invisible semantics
The reported environment is specific: Claude Code 2.1.186, claude-opus-4-8, a remote/bridge worker session, and settings containing CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=80. The configuration did not include CLAUDE_CODE_AUTO_COMPACT_WINDOW or settings.autoCompactWindow. The user expected the natural behavior: auto-compact at 80%.
Instead, the session reportedly grew to about 238k tokens. Debug logs contained zero lines of the form autocompact: tokens=... level=..., while manual /compact worked every time. The reporter’s root-cause theory is that the trigger predicate returns early for remote sessions when the auto-compact-window source is the default auto or experiment, before calculating token level or applying the percentage override. A commenter said that traced root cause looked real and suggested an explicit window workaround such as CLAUDE_CODE_AUTO_COMPACT_WINDOW=150000.
That workaround matters because it narrows the issue. This is not “compaction is flaky.” It is “one session mode and one config-source path can bypass the threshold logic, while manual compaction takes a different path.” That is precisely the kind of hidden branch that turns operational policy into runtime trivia.
Remote-control sessions are not a side show anymore. Agent tooling increasingly runs through bridges, web UIs, background workers, chat integrations, and local processes controlled from elsewhere. The files and commands may remain local, but the control plane changes shape. If that shape changes compaction behavior without making it visible, operators lose the ability to reason about cost and context.
Compaction is not just cleanup
Claude Code’s prompt-caching documentation explains the underlying economics: every turn resends the full context, and actions such as /compact change the cached prefix. That means compaction changes both what the model sees and how efficiently the session can continue. Claude Code’s cost documentation tells users to manage context proactively, use /usage, clear between tasks, and customize compaction behavior because token costs scale with context size.
Those docs are right, but they assume the configured policy is actually in force. If a remote-attached session ignores the percentage override, the user may think the agent will compact near the threshold while the context keeps growing. At small sizes, that is a cost leak. At larger sizes, it becomes a quality and reliability issue. Long contexts accumulate stale plans, abandoned branches, old tool output, background notifications, and half-relevant discussion. They make every later decision happen in a noisier room.
Compaction is therefore not just a bill-reduction feature. It is state hygiene. It decides which parts of the working memory survive, which get summarized, and where the model’s attention is spent. A system that changes compaction behavior based on session mode is changing the agent’s cognitive environment.
This is especially important for bridge-driven workflows because they tend to be long-lived. A developer may attach from Slack, a web app, or a remote controller, ask the agent to keep working in the background, receive task notifications, recover leases, reconnect MCP servers, and return later. That session is not a clean REPL. It is an event ledger. Without predictable compaction, the ledger becomes both expensive and weird.
The practitioner checklist is boring and necessary
If you use Claude Code through a bridge or remote-control path, verify compaction empirically. Do not assume an environment variable is active because it appears in settings. Watch token growth. Check debug logs for actual compaction events. Run manual /compact at task boundaries. If you rely on percentage-based auto-compaction, consider setting an explicit CLAUDE_CODE_AUTO_COMPACT_WINDOW until the bug class is resolved.
Teams should also record compaction state in their agent runbooks. For long-running tasks, the run log should include session mode, current context size, compaction window or percentage, last compaction time, and whether manual compaction was used before critical steps. That sounds fussy until you are trying to explain why one agent session cost twice as much, slowed down, and started reasoning from stale context while another behaved normally.
For tool builders, the fix class is explicit state. Session mode, compaction window source, percentage override, cache prefix, manual compaction, background precompute, and remote bridge flags are not incidental implementation details. They are runtime state that affects user outcomes. The UI should show the active policy, not merely the configured inputs. Logs should explain why compaction did or did not fire. If remote sessions have a different path, that difference should be tested and documented.
The wider agent market should learn from this quickly. Coding agents are becoming operating environments, not just chat boxes. Operating environments need boring invariants. “Auto-compaction means the same thing locally and remotely” is one of them.
The take: context management is a control plane. If it is hidden, mode-dependent, or silently bypassed, the agent is not merely more expensive. It is less inspectable.
Sources: Anthropic Claude Code issue #70477, Claude Code prompt-caching documentation, Claude Code costs documentation, Claude Code settings documentation