Skip to content

Add SubagentStart hook#22782

Open
abhinav-oai wants to merge 4 commits into
mainfrom
abhinav/subagent-hooks-minimal
Open

Add SubagentStart hook#22782
abhinav-oai wants to merge 4 commits into
mainfrom
abhinav/subagent-hooks-minimal

Conversation

@abhinav-oai
Copy link
Copy Markdown
Collaborator

@abhinav-oai abhinav-oai commented May 15, 2026

What

SubagentStart runs once when Codex creates a thread-spawned subagent, before that child sends its first model request. Thread-spawned subagents use SubagentStart instead of the normal root-agent SessionStart hook.

Configured handlers match on the subagent agent_type, using the same value passed to spawn_agent. When no agent type is specified, Codex uses the default agent type.

Hook input includes the normal session-start fields plus:

  • agent_id: the child thread id.
  • agent_type: the resolved subagent type.

SubagentStart may return hookSpecificOutput.additionalContext. That context is added to the child conversation before the first model request.

Lifecycle Scope

Only thread-spawned subagents run SubagentStart.

Internal/system subagents such as Review, Compact, MemoryConsolidation, and Other do not run normal SessionStart hooks and do not run SubagentStart. This avoids exposing synthetic matcher labels for internal implementation paths.

Also the SessionStart hook no longer fires for subagents, this matches behavior with other coding agents' implementation

Stack

  1. This PR: add SubagentStart.
  2. Add SubagentStop hook #22873: add SubagentStop.
  3. [codex] Add subagent identity to hook inputs #22882: add subagent identity to normal hook inputs.

@abhinav-oai abhinav-oai force-pushed the abhinav/subagent-hooks-minimal branch 2 times, most recently from cf04847 to 0292d97 Compare May 15, 2026 15:58
@abhinav-oai abhinav-oai changed the title [codex] Reuse hook lifecycle for subagent hooks [codex] Add SubagentStart and SubagentStop hooks May 15, 2026
@abhinav-oai abhinav-oai force-pushed the abhinav/subagent-hooks-minimal branch from 0292d97 to 6b0ba2f Compare May 15, 2026 16:40
@abhinav-oai abhinav-oai force-pushed the abhinav/subagent-hooks-minimal branch from 6b0ba2f to bd8ee83 Compare May 15, 2026 18:02
@abhinav-oai abhinav-oai changed the title [codex] Add SubagentStart and SubagentStop hooks [codex] Add SubagentStart hook May 15, 2026
@abhinav-oai abhinav-oai changed the title [codex] Add SubagentStart hook Add SubagentStart hook May 15, 2026
@abhinav-oai abhinav-oai marked this pull request as ready for review May 15, 2026 22:35
@abhinav-oai abhinav-oai requested a review from a team as a code owner May 15, 2026 22:35
@abhinav-oai
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8dfeb972c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/hooks/src/events/session_start.rs
))
}

pub(crate) fn parse_subagent_start(stdout: &str) -> Option<SessionStartOutput> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codex finding not specific to this pr, feel free to ignore if wrong:

the parser doesnt verify the hookEventName is actually the corresponding hook, so itd accept the equivalently shaped SessionStart hook event because we dont validate the name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is true but only catches a hook-author mistake

hooks.json remains the dispatch source of truth while hookSpecificOutput.hookEventName is not used to route or authorize behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants