Skip to content

Commit a1b8a4e

Browse files
authored
feat: include cwd in notify payload (openai#5415)
Expose the session cwd in the notify payload and update docs so scripts and extensions receive the real project path; users get accurate project-aware notifications in CLI and VS Code. Fixes openai#5387
1 parent b408a50 commit a1b8a4e

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

codex-rs/core/src/codex.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ pub(crate) async fn run_task(
17151715
.notify(&UserNotification::AgentTurnComplete {
17161716
thread_id: sess.conversation_id.to_string(),
17171717
turn_id: sub_id.clone(),
1718+
cwd: turn_context.cwd.display().to_string(),
17181719
input_messages: turn_input_messages,
17191720
last_assistant_message: last_agent_message.clone(),
17201721
});

codex-rs/core/src/user_notification.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub(crate) enum UserNotification {
5151
AgentTurnComplete {
5252
thread_id: String,
5353
turn_id: String,
54+
cwd: String,
5455

5556
/// Messages that the user sent to the agent to initiate the turn.
5657
input_messages: Vec<String>,
@@ -70,6 +71,7 @@ mod tests {
7071
let notification = UserNotification::AgentTurnComplete {
7172
thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(),
7273
turn_id: "12345".to_string(),
74+
cwd: "/Users/example/project".to_string(),
7375
input_messages: vec!["Rename `foo` to `bar` and update the callsites.".to_string()],
7476
last_assistant_message: Some(
7577
"Rename complete and verified `cargo build` succeeds.".to_string(),
@@ -78,7 +80,7 @@ mod tests {
7880
let serialized = serde_json::to_string(&notification)?;
7981
assert_eq!(
8082
serialized,
81-
r#"{"type":"agent-turn-complete","thread-id":"b5f6c1c2-1111-2222-3333-444455556666","turn-id":"12345","input-messages":["Rename `foo` to `bar` and update the callsites."],"last-assistant-message":"Rename complete and verified `cargo build` succeeds."}"#
83+
r#"{"type":"agent-turn-complete","thread-id":"b5f6c1c2-1111-2222-3333-444455556666","turn-id":"12345","cwd":"/Users/example/project","input-messages":["Rename `foo` to `bar` and update the callsites."],"last-assistant-message":"Rename complete and verified `cargo build` succeeds."}"#
8284
);
8385
Ok(())
8486
}

docs/config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ Specify a program that will be executed to get notified about events generated b
626626
"type": "agent-turn-complete",
627627
"thread-id": "b5f6c1c2-1111-2222-3333-444455556666",
628628
"turn-id": "12345",
629+
"cwd": "/Users/alice/projects/example",
629630
"input-messages": ["Rename `foo` to `bar` and update the callsites."],
630631
"last-assistant-message": "Rename complete and verified `cargo build` succeeds."
631632
}
@@ -635,6 +636,8 @@ The `"type"` property will always be set. Currently, `"agent-turn-complete"` is
635636

636637
`"thread-id"` contains a string that identifies the Codex session that produced the notification; you can use it to correlate multiple turns that belong to the same task.
637638

639+
`"cwd"` reports the absolute working directory for the session so scripts can disambiguate which project triggered the notification.
640+
638641
As an example, here is a Python script that parses the JSON and decides whether to show a desktop push notification using [terminal-notifier](https://github.com/julienXX/terminal-notifier) on macOS:
639642

640643
```python

0 commit comments

Comments
 (0)