[FEATURE] Session-scoped /autocompact: change a running session's window only, with separate main/subagent values
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 writesautoCompactWindowto~/.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>andCLAUDE_CODE_AUTO_COMPACT_WINDOWare 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 runningclaudeprocess.- 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
- 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.
- Precedence, highest first: managed/policy settings (as a cap) → session override →
CLAUDE_CODE_AUTO_COMPACT_WINDOW→--autocompact→autoCompactWindowin 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 sessionmust not be blocked because the env var is set. - 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>andCLAUDE_CODE_SUBAGENT_AUTO_COMPACT_WINDOW. A per-agent frontmatter value (#90347), if added, beats the session subagent value for that agent type. - 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).
- 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.
- Persistence. Session overrides are stored with the session, so
--resumeand-crestore them./clearkeeps them, because the setting belongs to the session, not to the conversation. Passing--autocompacton resume replaces the stored main value. - Visibility.
/autocompactwith no arguments and/contextshow the effective window and threshold for main and subagents, with the source of each:session,env,flag,settingsordefault. The statusLine JSON includes the same values (see #96467). - Range and syntax. Same as today:
auto, or 100k–1M tokens (500k,500000,500), plusofffor 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_DIRper 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
- I start three sessions. All of them use
autoCompactWindow: 600000from settings. - In session B the work turns out to be a narrow bug hunt. I run
/autocompact session 250kthere. Sessions A and C and my settings file stay at 600k. - 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. - 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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗