[FEATURE] Session-scoped /autocompact: change a running session's window only, with separate main/subagent values

Status Open
Reported on v2.1.280
Maintainer reply None cached
Activity 1 comment · opened Sep 28, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet (related: #90347, #90212, #86716, #83355, #19470; none asks for a session-only runtime change, see below)
  • [x] This is a single feature request (not multiple features)

Problem Statement

I run several Claude Code sessions at the same time, and they need different auto-compact windows. For example, a long coordinator session needs 600k, while a short investigation session is better off at 200k. I also need to change the window while a session is running, once I see how the conversation is going. Today there is no way to do that for one session only:

  • /autocompact <value> always writes autoCompactWindow to ~/.claude/settings.json (user scope). That changes the default for every future session, and every running session that reloads settings picks it up too.
  • --autocompact <tokens> and CLAUDE_CODE_AUTO_COMPACT_WINDOW are per session, but only at launch. A running session can't change them: a slash command or a Bash call can't change the environment of the running claude process.
  • The only workaround is to exit and run claude -c --autocompact <value>. That interrupts running background work and subagents.
  • The main session and its subagents always share one window (see #90347). A coordinator needs a large window, but workers should compact early.

Checked on Claude Code 2.1.280, Linux.

Proposed Solution

Add a session scope to /autocompact, with separate values for the main thread and for subagents.

Commands

/autocompact session 300k              # main thread of this session only
/autocompact session subagents 150k    # subagents spawned by this session only
/autocompact session off               # disable auto-compact for this session only
/autocompact session reset             # drop the session overrides, fall back to env/flag/settings
/autocompact                           # show effective values for main + subagents and where each comes from

/autocompact <value> without session keeps today's behaviour (it writes user settings), so nothing changes for existing users.

Rules

  1. Scope. A session override applies only to the session where it was set. It is never written to any settings file, and it never affects other running sessions or new ones.
  2. Precedence, highest first: managed/policy settings (as a cap) → session override → CLAUDE_CODE_AUTO_COMPACT_WINDOW → --autocompact → autoCompactWindow in settings → model default. A command typed in the running session is the most recent explicit choice, so it wins over the launch-time inputs. Unlike today, /autocompact session must not be blocked because the env var is set.
  3. Main vs subagents. The main thread and subagents are resolved separately. If no subagent value is set anywhere, subagents inherit the main value (today's behaviour). Launch-time equivalents for parity: --autocompact-subagents <auto|tokens> and CLAUDE_CODE_SUBAGENT_AUTO_COMPACT_WINDOW. A per-agent frontmatter value (#90347), if added, beats the session subagent value for that agent type.
  4. When it takes effect. At the next turn of the main thread, and at the next turn of every subagent that is already running. There is no need to restart anything. If context usage is already above the new threshold, compaction runs at the start of that next turn (compare #95194).
  5. Model cap. Each value is capped at the context window of the model that thread actually runs on, i.e. the subagent's own model, not the coordinator's (see #83355). The command prints the capped value when it caps.
  6. Persistence. Session overrides are stored with the session, so --resume and -c restore them. /clear keeps them, because the setting belongs to the session, not to the conversation. Passing --autocompact on resume replaces the stored main value.
  7. Visibility. /autocompact with no arguments and /context show the effective window and threshold for main and subagents, with the source of each: session, env, flag, settings or default. The statusLine JSON includes the same values (see #96467).
  8. Range and syntax. Same as today: auto, or 100k–1M tokens (500k, 500000, 500), plus off for the session only.

Alternative Solutions

  • Exit and run claude -c --autocompact <value>: works, but kills in-flight background work and subagents, and cannot split main and subagents.
  • CLAUDE_CONFIG_DIR per session (suggested in #19470): duplicates the whole config for one number.
  • The third-party plugin approach from #90347 (PreCompact hook that blocks compaction until a per-party threshold): works around the split, but needs the env window set to the lowest value and cannot be changed at runtime either.

Priority

Medium - Would be very helpful

Feature Category

Configuration and settings

Use Case Example

  1. I start three sessions. All of them use autoCompactWindow: 600000 from settings.
  2. In session B the work turns out to be a narrow bug hunt. I run /autocompact session 250k there. Sessions A and C and my settings file stay at 600k.
  3. In session A, the coordinator, I run /autocompact session subagents 150k. The coordinator keeps 600k, and its workers compact at 150k from their next turn.
  4. The next day I run claude --resume <A>. It comes back with 600k main and 150k subagents without any flags.

Additional Context

Related issues and how this differs:

  • #90347: per-agent-role window split, set in frontmatter/settings. This request adds the runtime, session-only layer and the main/subagent split for it, and defers to #90347 for per-agent-type values.
  • #90212: its ask 3 ("runtime-adjustable autocompact") is one item in a fleet-compaction bundle. This request covers only that item and defines its scope and precedence rules.
  • #19470 (closed, stale): per-session autoCompactEnabled, launch-time only.
  • #83355: subagents resolve the window from the coordinator's model. Rule 5 depends on that being fixed.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗