Allow hooks to request real compaction before continuing
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
Stopcontinuation viadecision: "block". - It should interact predictably with existing
PreCompactandPostCompactlifecycle 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:
Stophookdecision: "block"stores thereasonas continuation prompt text.- The continuation prompt is recorded as a user message, so slash-command text like
/compactis not routed through the TUI slash-command dispatcher. - The real compaction path is separate:
/compactdispatches toOp::Compact, which starts aCompactTask. - Current
PreCompact/PostCompacthook 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
PreCompactandPostCompactlifecycle 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗