[FEATURE] Let a hook or a CLI command request /compact in a running session (not only typing it)

Status Open
Reported on v2.1.294
Maintainer reply None cached
Activity 0 comments · opened Oct 8, 2026

Problem

/compact can be triggered only by typing it. A supervisor script, a hook or a remote channel cannot compact a running interactive session at a chosen moment (for example when the session is idle and its context use is high), and no tool lets the model do it either. The reactive auto-compact fires near the ceiling, which is often the worst moment.

Checked on 2.1.294 (Linux): no hook output field, CLI command or setting triggers a compaction in a running interactive session. The earlier requests #58538 (hooks) and #37721 (slash commands over MCP or external channels) were closed as duplicates and are locked, so I am filing this again with a concrete use.

Request

A sanctioned way for something other than the user's keystrokes to request a compaction of a running session, with optional custom instructions, for example one of:

  • a hook output field ("compact": {"instructions": "..."}) honoured from Stop or Notification hooks while the session is idle;
  • a CLI/IPC command addressed to a session id (claude compact <session> [--instructions ...]).

Why

A supervisor that watches context use (a "compact soon" signal at about 60 percent) can only type /compact into the terminal today. That needs the session to be idle and the prompt visible, and the typed line is recorded as a human prompt.

Environment

Claude Code 2.1.294, Linux (Bazzite, Fedora atomic), interactive terminal sessions.

---
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
🤖 Generated with Claude Code

View original on GitHub ↗