Skip to content

Add SubagentStop hook#22873

Open
abhinav-oai wants to merge 5 commits into
abhinav/subagent-hooks-minimalfrom
abhinav/subagent-stop-stack
Open

Add SubagentStop hook#22873
abhinav-oai wants to merge 5 commits into
abhinav/subagent-hooks-minimalfrom
abhinav/subagent-stop-stack

Conversation

@abhinav-oai
Copy link
Copy Markdown
Collaborator

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

What

SubagentStop runs when a thread-spawned subagent turn is about to finish. Thread-spawned subagents use SubagentStop instead of the normal root-agent Stop hook.

Configured handlers match on agent_type. Hook input includes the normal stop fields plus:

  • agent_id: the child thread id.
  • agent_type: the resolved subagent type.
  • agent_transcript_path: the child subagent transcript path.
  • transcript_path: the parent thread transcript path.
  • last_assistant_message: the final assistant message from the child turn, when available.
  • stop_hook_active: true when the child is already continuing because an earlier stop-like hook blocked completion.

SubagentStop shares the same completion-control semantics as Stop, scoped to the child turn:

  • No decision allows the child turn to finish.
  • decision: "block" with a non-empty reason records that reason as hook feedback and continues the child with that prompt.
  • continue: false stops the child turn. If stopReason is present, Codex surfaces it as the stop reason.

Lifecycle Scope

Only thread-spawned subagents run SubagentStop.

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

Stack

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

@abhinav-oai abhinav-oai changed the title [codex] Add SubagentStop hook Add SubagentStop hook May 15, 2026
@abhinav-oai abhinav-oai marked this pull request as ready for review May 15, 2026 23:28
@abhinav-oai abhinav-oai requested a review from a team as a code owner May 15, 2026 23:28
@abhinav-oai
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Swish!

ℹ️ 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".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant