Allow hooks to request real compaction before continuing

Open 💬 2 comments Opened May 17, 2026 by ducan-ne

What variant of Codex are you using?

CLI

What feature would you like to see?

Support a first-class hook output action that can request real Codex compaction before continuing the turn.

Today a Stop hook can keep Codex going by returning:

{
  "decision": "block",
  "reason": "Run one more pass over the failing tests."
}

That is useful, but it only sends reason back as a model-visible continuation prompt. If the hook returns /compact as the reason, Codex treats it as prompt text; it does not invoke the real /compact control path.

The requested feature is a supported hook output contract for triggering actual history compaction from a hook, especially from Stop, before optionally continuing with a hook-provided prompt.

For example, something along these lines:

{
  "hookSpecificOutput": {
    "hookEventName": "Stop",
    "action": "compact",
    "continuationPrompt": "After compaction, continue with one more validation pass."
  }
}

or another schema chosen by maintainers that makes the same behavior explicit.

Desired semantics:

  • The hook requests the same real compaction path as manual /compact / Op::Compact, not a model prompt containing /compact.
  • Codex compacts at most once per turn to avoid hook loops.
  • If a continuation prompt is supplied, Codex resumes after compaction using that prompt.
  • The behavior should be clearly separate from existing Stop continuation via decision: "block".
  • It should interact predictably with existing PreCompact and PostCompact lifecycle hooks when those hooks are available.

Additional information

I checked the current behavior in source and docs. The gap appears to be that compaction is a control operation, while Stop hook continuation is implemented as a synthetic user prompt:

  • Stop hook decision: "block" stores the reason as continuation prompt text.
  • The continuation prompt is recorded as a user message, so slash-command text like /compact is not routed through the TUI slash-command dispatcher.
  • The real compaction path is separate: /compact dispatches to Op::Compact, which starts a CompactTask.
  • Current PreCompact / PostCompact hook outputs are lifecycle-only and do not provide an action to request compaction.

Related issues, but not exactly this request:

  • #11912 asks for custom compaction hooks / compaction lifecycle support.
  • #17148 asks for PreCompact and PostCompact lifecycle hooks.
  • #21753 tracks broader Claude Code hook parity.

This issue is specifically asking for a hook output action that can trigger real Codex compaction, rather than relying on a hook to send /compact or a summarization prompt back to the model.

View original on GitHub ↗

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