From 318d10b39ac8fd36ace1ec47f758e9b8dc7726ea Mon Sep 17 00:00:00 2001 From: Steve Mostovoy Date: Mon, 23 Feb 2026 14:28:47 -0800 Subject: [PATCH] Add subagent field to notify payload For notify events, a notifier may want to behave differently for subagents than for the main thread, so we can expose that info in the notify payload. --- codex-rs/core/src/codex.rs | 4 ++++ codex-rs/core/tests/suite/user_notification.rs | 1 + codex-rs/hooks/src/registry.rs | 1 + codex-rs/hooks/src/types.rs | 3 +++ codex-rs/hooks/src/user_notification.rs | 5 +++++ 5 files changed, 14 insertions(+) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 249cb99776..34fea58fbb 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -4783,6 +4783,10 @@ pub(crate) async fn run_turn( event: HookEventAfterAgent { thread_id: sess.conversation_id, turn_id: turn_context.sub_id.clone(), + subagent: matches!( + &turn_context.session_source, + SessionSource::SubAgent(_) + ), input_messages: sampling_request_input_messages, last_assistant_message: last_agent_message.clone(), }, diff --git a/codex-rs/core/tests/suite/user_notification.rs b/codex-rs/core/tests/suite/user_notification.rs index 5ef939776b..2e61239992 100644 --- a/codex-rs/core/tests/suite/user_notification.rs +++ b/codex-rs/core/tests/suite/user_notification.rs @@ -73,6 +73,7 @@ echo -n "${@: -1}" > $(dirname "${0}")/notify.txt"#, let payload: Value = serde_json::from_str(¬ify_payload_raw)?; assert_eq!(payload["type"], json!("agent-turn-complete")); + assert_eq!(payload["subagent"], json!(false)); assert_eq!(payload["input-messages"], json!(["hello world"])); assert_eq!(payload["last-assistant-message"], json!("Done")); diff --git a/codex-rs/hooks/src/registry.rs b/codex-rs/hooks/src/registry.rs index 6568f5374f..9f7ddad3a5 100644 --- a/codex-rs/hooks/src/registry.rs +++ b/codex-rs/hooks/src/registry.rs @@ -112,6 +112,7 @@ mod tests { event: HookEventAfterAgent { thread_id: ThreadId::new(), turn_id: format!("turn-{label}"), + subagent: false, input_messages: vec![INPUT_MESSAGE.to_string()], last_assistant_message: Some("hi".to_string()), }, diff --git a/codex-rs/hooks/src/types.rs b/codex-rs/hooks/src/types.rs index 5131580128..4cf4cd8710 100644 --- a/codex-rs/hooks/src/types.rs +++ b/codex-rs/hooks/src/types.rs @@ -75,6 +75,7 @@ pub struct HookPayload { pub struct HookEventAfterAgent { pub thread_id: ThreadId, pub turn_id: String, + pub subagent: bool, pub input_messages: Vec, pub last_assistant_message: Option, } @@ -189,6 +190,7 @@ mod tests { event: HookEventAfterAgent { thread_id, turn_id: "turn-1".to_string(), + subagent: false, input_messages: vec!["hello".to_string()], last_assistant_message: Some("hi".to_string()), }, @@ -204,6 +206,7 @@ mod tests { "event_type": "after_agent", "thread_id": thread_id.to_string(), "turn_id": "turn-1", + "subagent": false, "input_messages": ["hello"], "last_assistant_message": "hi", }, diff --git a/codex-rs/hooks/src/user_notification.rs b/codex-rs/hooks/src/user_notification.rs index 50472225e4..6c8dcb4b54 100644 --- a/codex-rs/hooks/src/user_notification.rs +++ b/codex-rs/hooks/src/user_notification.rs @@ -19,6 +19,7 @@ enum UserNotification { thread_id: String, turn_id: String, cwd: String, + subagent: bool, /// Messages that the user sent to the agent to initiate the turn. input_messages: Vec, @@ -35,6 +36,7 @@ pub fn legacy_notify_json(hook_event: &HookEvent, cwd: &Path) -> Result