Feature request: Allow Claude to programmatically trigger `/compact`

Resolved 💬 3 comments Opened Mar 26, 2026 by physics91 Closed Mar 26, 2026

Problem

With the 1M context window, conversations can accumulate significant token usage during long sessions. The /compact command exists but can only be triggered manually by the user.

The issue is that the user often doesn't know the optimal timing to compact — too early loses useful context, too late wastes tokens. Meanwhile, Claude has the best understanding of the current context state (e.g., exploration phase complete, switching to implementation, accumulated noise from tool outputs).

Proposed Solution

Expose a tool (e.g., CompactContext) that allows Claude to programmatically trigger context compaction with a summary/instruction, similar to how /compact [instructions] works for users.

Example use cases:

  • After a lengthy codebase exploration phase, compact before starting implementation
  • When tool outputs (file reads, grep results) have served their purpose and are no longer needed
  • When the conversation naturally transitions between distinct phases of work

Alternatives Considered

  1. Claude suggests the user type /compact — adds friction, user may miss the suggestion
  2. Hooks-based automation — hooks don't have visibility into context state
  3. Automatic compaction at context limits — already exists, but fires too late for cost optimization

Additional Context

This would give Claude agency over its own context management, leading to better cost efficiency and session quality without requiring user intervention.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗