Skip to content

Stop hook should include recent messages to enable external memory systems #30979

Description

@Liewzheng

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 Liewzheng/codex@main...mimir-stop-messages). The changes include:

  • Added StopMessage { role, content } to codex-rs/hooks/src/schema.rs.
  • Added an optional messages field to StopCommandInput and SubagentStopCommandInput.
  • Populated messages from the last user/assistant entries in the JSONL transcript when the caller does not provide them inline.
  • Updated codex-rs/core/src/hook_runtime.rs to thread messages into the Stop request.
  • Regenerated schema fixtures for stop.command.input and subagent-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIenhancementNew feature or requesthooksIssues related to event hooksmemory

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions