Feature Request: Let Claude trigger context compaction via tool call
Resolved 💬 3 comments Opened Feb 8, 2026 by TweedBeetle Closed Feb 9, 2026
Summary
Allow Claude to proactively trigger context compaction via a tool call (e.g., CompactContext), rather than relying solely on automatic threshold-based triggers or user-initiated /compact.
Motivation
Current compaction is either:
- Automatic - fires at a fixed threshold (~78-80%), often at inopportune moments mid-task
- User-initiated -
/compactcommand
Neither leverages the fact that Claude itself knows best when compaction would be strategic. The model has awareness of:
- Whether it just finished a major task and context is full of now-irrelevant tool outputs
- Whether it's about to start a new phase of work that would benefit from a clean slate
- Whether the remaining context budget is tight for the upcoming task
- Whether critical context could be summarized without loss before starting something new
This would address pain points from several related issues where compaction fires at bad times (#21925, #18264, #18802) or users want more control over timing (#23711, #23419).
Proposed Behavior
- Expose a
CompactContexttool (or similar) that Claude can call like any other tool - Claude provides compaction instructions as a parameter (what to preserve, what to summarize, what to drop) - similar to how
/compactaccepts custom instructions - The tool triggers compaction immediately and returns the new context state
- Could be gated behind a setting (
allowAgentCompaction: true) for users who prefer current behavior
Example Use Cases
- After completing a multi-file refactor with hundreds of lines of tool output, Claude recognizes the diffs are no longer needed and compacts before starting the next task
- During a long planning session, Claude compacts after plan approval but before implementation begins
- When context is at ~60% but the next task requires reading many large files, Claude preemptively compacts to make room
- After a research phase with many web fetches, Claude summarizes findings and compacts before writing code
Relationship to Existing Issues
- #23261 (
/compact-next) - complementary; that's user-scheduled, this is agent-initiated - #23493 (low-context warning hook) - this would be a more capable alternative
- #23711 (configurable threshold) - this removes the need for threshold tuning entirely
- #21925 (compaction destroys workflow) - agent-controlled timing avoids mid-task disruption
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗