Feature request: per-agent compaction thresholds for Agent-tool subagents

Status Fixed / completed
Maintainer reply None cached
Activity 1 comment · opened Aug 31, 2026 · closed Aug 31, 2026

Use case: We run delegated coding subagents (via the Agent tool / .claude/agents definitions) that legitimately need 50-150 turns. On large-context models, auto-compact triggers only near the model window (roughly 95%), so a subagent can accumulate 600k-940k tokens of context before anything compacts. Measured on our fleet over 7 days: 20 of 218 subagent spawns peaked above 350k, top peaks 863k and 940k (the latter confirmed by its compact_boundary record: preTokens 940331). Every call at that size re-reads the full context at cache-read pricing, and 2026 research on long-trajectory degradation suggests quality also suffers well before the window limit.

What exists today: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is global (affects the main session and every subagent identically), and the documented agent frontmatter (model, tools, maxTurns, isolation, skills, effort...) has no compaction or context key. Subagents also cannot request compaction themselves; /compact is a session command.

Request, in preference order:

  1. A per-agent frontmatter key in .claude/agents/*.md to set the auto-compact trigger (percentage or absolute tokens) for that agent type.
  2. Alternatively or additionally: expose the Messages API context-management capability (clear_tool_uses style tool-result clearing with keep-last-N and exclude-tools) as an opt-in per agent definition, since tool results dominate the accumulation in our measurements (about 40% Bash results and 23% Read results of model-visible content in our over-200k cohort).
  3. At minimum: document whether the time-based and count-based tool-result clearing mechanisms observed in issue #42542 apply inside Agent-tool subagents, so harness authors can reason about what is already happening.

Happy to share the measurement methodology (it joins parent-transcript spawn records with subagent transcript usage records).

View original on GitHub ↗

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