Expose microcompact's keep/trigger settings, and stop excluding headless/SDK sessions from it

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

Claude Code 2.1.284 contains exactly the context mechanism long-running agent sessions need — the
"KEEP-RECENT MC" pass that keeps the last N tool results and replaces the rest with
[Old tool result content cleared] or a <persisted-output> pointer. Three things stop it being
usable, and I'd like to ask for each.

1. It is unavailable to headless / SDK sessions at all.
createContextHintController returns null unless
querySource.startsWith("repl_main_thread"). Sessions driven through claude -p and through
--input-format stream-json run as querySource:"sdk" and are therefore excluded by
construction. These are precisely the long-running, tool-heavy sessions that accumulate context
fastest. Ask: let sdk opt in.

2. keepRecent and the savings floor are hardcoded with no setting or env var.
keepRecent = 5 and clearAtLeastTokens = 20000 are literals; the advertised
target_tokens_saved floor is 75,000 (tengu_hazel_osprey_floor). I checked 2.1.220 and 2.1.284:
the same three numbers (5 / 20,000 / 75,000) in both. There is no settings key and no env var that
reads any of them — the only compaction knobs exposed are the full auto-compact window
(CLAUDE_CODE_AUTO_COMPACT_WINDOW, autoCompactWindow, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE,
DISABLE_AUTO_COMPACT). Ask: a microcompact: { keepToolUses, clearAtLeastTokens, targetTokensSaved }
settings block, and/or the matching env vars.

3. There is no client-side "fire after N tool results" trigger.
Today the client only advertises context_hint and waits for the server to answer 422/424. The
idle path added in 2.1.284 (clear_tool_uses_20250919, minIdleSeconds: 3900,
keepToolUses: 5, minTriggerToolUses: 20) shows the shape I want already exists — it is just
bound to a 65-minute idle gap and gated off (tengu_zany_pike). Ask: expose the same
context_management edit parameters — trigger, keep, clear_at_least, exclude_tools — as
user configuration, per role/agent type, so a worker session can say "keep the last 10 tool
results, clear anything above 20k tokens, every turn."

Why it matters, with numbers. A headless session I ran read 30 files of ~12,000 chars each. It
reached 223,519 tokens against a 200,000 ceiling and then died — terminal_reason:
"prompt_too_long"
. No microcompact fired (excluded by querySource). No auto-compact fired
either: with no window configured, zT(...).source === "auto", and Dko's if (XW() && !VZ(n,r))
return false
skips the check entirely — I measured zero autocompact: debug lines at 93% of the
window. The only thing that woke up was the post-400 reactive compact, which reported
round ladder exhausted, last resort and then still too long after 1 head truncations, giving
up
. A keep-last-5 pass would have cleared the session comfortably under the ceiling. Instead the
session was lost.

Smaller, related ask: the per-tool output thresholds (maxResultSizeChars, clamped by a 50,000
ceiling; Bash measured at exactly 30,000 chars on both 2.1.220 and 2.1.284) are adjustable only
through the tengu_velvet_ibis remote dynamic config. A local override would let heavy users tune
what enters context without waiting on a rollout.

---

View original on GitHub ↗

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