Skip to content

[BUG] 2.1.286 idle compaction silently discards working context in long-running sessions; no opt-out, logged as "manual" #98747

Description

@natefosterwarner

Summary

Since 2.1.286, idle sessions are compacted automatically before the prompt cache expires ("Compacted while idle, before the prompt cache expired"). There is no opt-out and no warning. For long-running working sessions this discards the grounding the session was built on. I'd like to suggest that compaction stay user-initiated, or at least opt-in or announced in advance, except in the genuine emergency of hitting the context limit.

Environment

  • Claude Code 2.1.286, native install, macOS
  • Not seen on 2.1.285 or earlier

What happened

I keep roughly 20 Claude Code sessions open in parallel on long-running projects. Each one accumulates detailed working context over hours: the exact instructions I've given, decisions and their reasons, the methods we settled on, and in-flight state.

Overnight after updating to 2.1.286, 7 of those sessions were compacted while idle. None was close to the context limit. When I came back, each had a summary in place of its working context: my exact instructions, the reasoning behind decisions, and the methods we'd agreed on were gone from what the session actually sees. I had to rebuild the grounding by hand from the transcripts on disk.

I understand the cost logic (compacting before the cache expires avoids paying to reprocess a long uncached context on the next turn), and I can see it was requested in #66115. But for this way of working, the trade is backwards: the context is the valuable part, and a cache re-read is a cost I'd gladly pay to keep it.

Expected behavior

  • Compaction should never happen silently while the user is away, unless the session is at the hard context limit and has no other option.
  • If the cost-saving behavior stays, it should be opt-in, or at least announced (for example "this session will compact in N minutes unless you interact") with a one-keystroke way to decline.

Additional issues found

  1. Mislabelled trigger. These idle compactions are recorded in the transcript as compactMetadata.trigger: "manual", although I never ran /compact. That makes them indistinguishable from user-initiated compactions, which makes the behavior hard to diagnose.
  2. No documented hook. I couldn't find documentation confirming that PreCompact fires for idle compaction, which would let users save state first.

Suggested fixes

  1. A setting to disable idle compaction, for example "idleCompaction": false in settings.json, or an env var.
  2. A distinct trigger value (for example "idle") in compactMetadata.
  3. Documented PreCompact and SessionStart (compact) hook support for idle compaction, so state can be saved before it runs and restored after.

Related: #66115 (the feature request), #71254, #91836.

Thanks. The full transcripts remained on disk, which made recovery possible, and I appreciate that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corebugSomething isn't workingplatform:macosIssue specifically occurs on macOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions