Stop hook should include recent messages to enable external memory systems
Summary
External memory systems (e.g. Mimir) need to persist the user/assistant exchange at the end of a turn. The current Stop hook only exposes last_assistant_message and a transcript_path, which forces integrations to parse the Codex JSONL transcript themselves.
Request
Include an inline messages array in the Stop and SubagentStop hook payloads, containing the recent user/assistant exchange. This would make Codex easier to integrate with external memory systems without requiring them to parse transcript_path.
This request mirrors the interface introduced in MoonshotAI/kimi-code#1299.
Proposed schema
{
"messages": [
{ "role": "user", "content": "..." },
{ "role": "assistant", "content": "..." }
]
}
messages should be optional to preserve backward compatibility.
Reference implementation
I have implemented this on a fork at Liewzheng/codex in the branch mimir-stop-messages (see https://github.com/Liewzheng/codex/compare/main...mimir-stop-messages). The changes include:
- Added
StopMessage { role, content }tocodex-rs/hooks/src/schema.rs. - Added an optional
messagesfield toStopCommandInputandSubagentStopCommandInput. - Populated
messagesfrom the last user/assistant entries in the JSONL transcript when the caller does not provide them inline. - Updated
codex-rs/core/src/hook_runtime.rsto threadmessagesinto the Stop request. - Regenerated schema fixtures for
stop.command.inputandsubagent-stop.command.input. - Added unit tests for the transcript fallback.
I'd be happy to open a PR, but I see this repository currently restricts pull requests to collaborators. Please let me know if you'd like me to provide the patch in another format or if there's a process for external contributors.
2 Comments
Update: pushed a small fix to the reference branch so that SubagentStop falls back to
agent_transcript_path(the subagent transcript) when extracting recent messages, instead of the parent thread transcript.Branch: https://github.com/Liewzheng/codex/compare/main...mimir-stop-messages
I cannot run
cargo checklocally right now because crates.io is timing out from this environment, so the patch has not been machine-verified here. It will rely on CI once a maintainer can open a PR from the branch.Verification update (with proxy):
cargo check -p codex-hooks✅cargo test -p codex-hooks✅ (121 passed)cargo check -p codex-core✅Also regenerated the schema fixtures with
cargo run -p codex-hooks --bin write_hooks_schema_fixturesso the generated schemas and fixtures stay in sync.Latest branch: https://github.com/Liewzheng/codex/compare/main...mimir-stop-messages