[Feature Request] Allow programmatic/agent-initiated compaction

Resolved 💬 2 comments Opened Apr 22, 2026 by cnighswonger Closed Jun 8, 2026

Feature Description

Currently /compact is only available as a user-initiated slash command. The agent cannot trigger compaction itself, even when it detects that context is approaching the limit.

For long-running autonomous sessions (loops, background agents, overnight runs), there is no way for the agent to proactively manage its own context window. It works until it hits the ceiling, then stops and waits for a human to intervene.

Proposed Solution

Expose compaction as a tool the agent can invoke, or allow it to be triggered via a hook or MCP tool. This would let autonomous agents manage their own context lifecycle without human intervention.

Use Case

  • Autonomous agents running /loop or background tasks that may exceed context limits
  • Multi-agent workflows where a coordinator can't constantly monitor each agent's context usage
  • Any session where the human is away and the agent hits the context ceiling

Current Workaround

None for autonomous sessions. The agent cannot call /compact, cannot programmatically trigger it via hooks, and cannot continue once the context limit is reached. The only option is a human running /compact or /clear manually.

Additional Context

The PreCompact and PostCompact hooks are excellent — they let external systems preserve state around compaction events. The missing piece is letting the agent initiate the compaction itself when it determines the time is right.

View original on GitHub ↗

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