[FEATURE] Programmatic / fleet compaction: compact-on-idle, cross-session /compact, runtime-adjustable autocompact

Status Open
Maintainer reply None cached
Activity 0 comments · opened Aug 27, 2026

Use case

I run several coordinated Claude Code sessions concurrently (desktop app) as a working team on one program — a lead session, a review session, worker sessions. At usage-window boundaries the fleet pauses gracefully: every session commits durable state and idles. The natural last step of that pause is compact every session at this clean point, so each resumes lean next window.

Today that requires a human to type /compact into each session individually. Verified against current docs and claude --help:

  • /compact is strictly client-side — no tool, SDK method, or MCP surface lets the model compact its own context at a chosen quiet point;
  • nothing can trigger compaction on another session (no claude compact <session-id>); the closest workaround, claude -p --resume <id> "/compact", re-engages an app-owned session's transcript from outside the app, which risks state divergence;
  • --autocompact <tokens> sets the threshold only at launch; it cannot be adjusted at runtime, and auto-compact fires only on context fullness — never on a schedule or an idle signal;
  • PreCompact / SessionStart(compact) hooks fire around compaction but cannot cause it.

Asks (any subset would help)

  1. Compact-on-idle / compact-on-demand for the session itself — a supported way for an agent (or a hook) to request compaction of its own context at a clean point, e.g. a Compact tool gated by permission, or a hook return value that requests it.
  2. Cross-session compactionclaude compact <session-id> (or SDK equivalent) that safely compacts a stored session without interactively resuming it.
  3. Runtime-adjustable autocompact threshold — let /config or an API change the --autocompact value on a live session, so a fleet can be told "compact aggressively now."

The session-owned design is understandable for a single interactive session; it breaks down for coordinated multi-session workflows, which the session-messaging features otherwise support well.

🤖 Generated with Claude Code on behalf of the account owner.

View original on GitHub ↗