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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗