From c55b5fb62fb5b7905eee1d9e42451ccc01613eec Mon Sep 17 00:00:00 2001 From: lunchboxfortwo Date: Fri, 17 Jul 2026 16:24:08 -0400 Subject: [PATCH] feat(hooks): pass working_dir to the Stop hook context (#10296) Co-authored-by: Claude Opus 4.8 --- crates/goose/src/agents/agent.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/goose/src/agents/agent.rs b/crates/goose/src/agents/agent.rs index 7a854e176..9f556520e 100644 --- a/crates/goose/src/agents/agent.rs +++ b/crates/goose/src/agents/agent.rs @@ -459,19 +459,26 @@ impl Agent { fn stop_hook_context( session_id: &str, last_assistant_message: &str, + working_dir: &str, ) -> crate::hooks::HookContext { crate::hooks::HookContext::new(crate::hooks::HookEvent::Stop, session_id) .with_last_assistant_message(last_assistant_message.to_string()) + .with_working_dir(working_dir.to_string()) } - async fn emit_stop_hook(&self, session_id: &str, last_assistant_message: &str) { + async fn emit_stop_hook( + &self, + session_id: &str, + last_assistant_message: &str, + working_dir: &str, + ) { if !self.hook_manager.has_hooks(crate::hooks::HookEvent::Stop) { return; } self.hook_manager .emit( crate::hooks::HookEvent::Stop, - Self::stop_hook_context(session_id, last_assistant_message), + Self::stop_hook_context(session_id, last_assistant_message, working_dir), ) .await; } @@ -480,11 +487,12 @@ impl Agent { &self, session_id: &str, last_assistant_message: &str, + working_dir: &str, ) -> crate::hooks::HookDecision { self.hook_manager .emit_blocking( crate::hooks::HookEvent::Stop, - Self::stop_hook_context(session_id, last_assistant_message), + Self::stop_hook_context(session_id, last_assistant_message, working_dir), ) .await } @@ -1979,7 +1987,7 @@ impl Agent { conversation.push(message); match self - .emit_stop_hook_blocking(&session_config.id, &last_assistant_text) + .emit_stop_hook_blocking(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy()) .await { crate::hooks::HookDecision::Allow => { @@ -2885,7 +2893,7 @@ impl Agent { if exit_chat { match self - .emit_stop_hook_blocking(&session_config.id, &last_assistant_text) + .emit_stop_hook_blocking(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy()) .await { crate::hooks::HookDecision::Allow => { @@ -2918,7 +2926,7 @@ impl Agent { } if !stop_hook_handled_for_exit { - self.emit_stop_hook(&session_config.id, &last_assistant_text).await; + self.emit_stop_hook(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy()).await; } }.instrument(reply_stream_span)); Ok(inner)