claude-code - 💡(How to fix) Fix Feature request: let hooks invoke slash commands (e.g. /compact) via hookSpecificOutput [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54822Fetched 2026-04-30 06:34:58
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

Fix Action

Fix / Workaround

Just filed #54819 (percentage-based autoCompactWindow) — the underlying limitation is that even if you wanted to compute "compact at 55% of any model's window" yourself, a Stop hook can't trigger compaction. invokeCommand would unblock the entire user-land workaround path for compaction and a long tail of other automations.

Code Example

{
  "hookSpecificOutput": {
    "hookEventName": "Stop",
    "invokeCommand": "/compact"
  }
}
RAW_BUFFERClick to expand / collapse

Problem

Hook output supports systemMessage, additionalContext, permissionDecision, decision: "block", and similar — but no field that triggers a slash command. This blocks a class of useful automations:

  • Auto-compact when context crosses a threshold (Stop hook detects size, can't run /compact).
  • Auto-/clear after a long idle.
  • Trigger /memory save after specific tool patterns.
  • Run /<custom-skill> post-condition from a Stop hook.

Today the only way to get any of these is to inject a systemMessage asking the model to run the command, which is brittle (model can ignore it, costs a turn, pollutes transcripts).

Proposed

Add to hookSpecificOutput:

{
  "hookSpecificOutput": {
    "hookEventName": "Stop",
    "invokeCommand": "/compact"
  }
}

Harness queues the slash command to run after the current turn settles, same way user-typed slash commands are handled. Should respect the same permissioning as user invocation (no privilege escalation).

Why this matters now

Just filed #54819 (percentage-based autoCompactWindow) — the underlying limitation is that even if you wanted to compute "compact at 55% of any model's window" yourself, a Stop hook can't trigger compaction. invokeCommand would unblock the entire user-land workaround path for compaction and a long tail of other automations.

extent analysis

TL;DR

Adding an invokeCommand field to hookSpecificOutput could enable triggering slash commands from Stop hooks, unblocking various automations.

Guidance

  • Consider adding the proposed invokeCommand field to hookSpecificOutput to allow triggering slash commands like /compact or /clear from Stop hooks.
  • Verify that the invokeCommand field respects the same permissioning as user invocation to prevent privilege escalation.
  • Test the proposed solution with different automations, such as auto-compact and auto-/clear, to ensure it works as expected.
  • Evaluate the potential impact of this change on existing workflows and transcripts, considering the removal of brittle systemMessage workarounds.

Example

{
  "hookSpecificOutput": {
    "hookEventName": "Stop",
    "invokeCommand": "/compact"
  }
}

Notes

The proposed solution assumes that the invokeCommand field will be handled similarly to user-typed slash commands, with the same permissioning and queuing behavior.

Recommendation

Apply workaround: Add the proposed invokeCommand field to hookSpecificOutput to enable triggering slash commands from Stop hooks, as it addresses the current limitation and enables various automations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Feature request: let hooks invoke slash commands (e.g. /compact) via hookSpecificOutput [1 participants]