codex - 💡(How to fix) Fix Allow hooks to request real compaction before continuing

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…

Fix Action

Fix / Workaround

  • 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.

Code Example

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

---

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

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.

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