Skip to content

feat(hooks): pass working_dir to the Stop hook context - #10296

Merged
alexhancock merged 2 commits into
aaif-goose:mainfrom
lunchboxfortwo:ser-stop-hook-message
Jul 17, 2026
Merged

feat(hooks): pass working_dir to the Stop hook context#10296
alexhancock merged 2 commits into
aaif-goose:mainfrom
lunchboxfortwo:ser-stop-hook-message

Conversation

@lunchboxfortwo

Copy link
Copy Markdown
Contributor

What

The Stop hook already emits last_assistant_message (#9968) but not the session working directory. A Stop hook that shells out to an external verifier (e.g. a completion/anti-confabulation check) therefore has to guess the repo from the process cwd, which isn't reliable across launch contexts.

This threads session.working_dir through emit_stop_hook / emit_stop_hook_blocking into stop_hook_context, setting it via the existing .with_working_dir builder — matching the other lifecycle events that already carry it.

Why

With both last_assistant_message and working_dir on the Stop context, a blocking Stop hook can verify the right repo against the agent's actual final message and block a false "done" deterministically — without depending on where goose was launched.

Notes

  • Additive: hooks that ignore working_dir are unaffected; no behavior change.
  • cargo check -p goose passes.

🤖 Generated with Claude Code

The Stop hook already emits last_assistant_message (aaif-goose#9968) but not the session
working directory, so a Stop hook that shells out to a verifier must guess the
repo from the process cwd. Thread session.working_dir through emit_stop_hook /
emit_stop_hook_blocking into stop_hook_context and set it via the existing
.with_working_dir builder, matching the other lifecycle events. Additive; no
behavior change for hooks that ignore working_dir.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CxaoNZnqVZjmEELjLbV4BX

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

Copy link
Copy Markdown

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: f7b2becb78

ℹ️ 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 crates/goose/src/agents/agent.rs Outdated
}

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Run cargo fmt on the hook helper signature

The repository instructions in AGENTS.md require formatting (Never: Skip cargo fmt), and RUSTUP_TOOLCHAIN=1.92.0-x86_64-unknown-linux-gnu cargo fmt --check fails on this newly expanded signature. This will fail the formatting gate until the commit is run through cargo fmt.

Useful? React with 👍 / 👎.

@alexhancock alexhancock left a comment

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.

The change LGTM but can you take a look at code formatting? A cargo fmt will likely unblock the current failing check

Wrap the emit_stop_hook signature to satisfy cargo fmt (the line exceeded
rustfmt's 100-char max_width). Unblocks the Check Rust Code Format CI job;
matches the already-wrapped emit_stop_hook_blocking sibling.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H1BcytE8qDDc511EHjQU92
@alexhancock
alexhancock merged commit c55b5fb into aaif-goose:main Jul 17, 2026
25 checks passed
michaelneale added a commit that referenced this pull request Jul 20, 2026
* origin/main: (24 commits)
  fix(session): create inventory tables atomically with schema version (#10586)
  fix(providers): rewrite oneOf to anyOf in tool schemas for OpenAI-compatible backends (#10571)
  fix(evals): report cache-aware Harbor costs (#10430)
  fix(acp): allow custom model as default for non-local providers (#10438)
  fix(config): require absolute goose path roots (#10454)
  chore(deps): bump astral-sh/setup-uv from 8.2.0 to 8.3.2 (#10541)
  fix(permissions): scope smart approval by request (#10457)
  fix(summon): preserve fixed subrecipe values (#10452)
  chore(deps): bump websocket-driver from 0.7.4 to 0.7.5 in /documentation (#10506)
  fix(flatpak): bundle git so hermit can clone its package registry (#10511)
  feat(hooks): pass working_dir to the Stop hook context (#10296)
  chore(deps): bump actions/setup-java from 5.5.0 to 5.6.0 (#10540)
  chore(deps): bump actions/setup-node from 6 to 7 (#10539)
  chore(deps): bump EmbarkStudios/cargo-deny-action from 2.0.20 to 2.1.1 (#10542)
  chore(deps): bump gradle/actions/setup-gradle from 4.4.3 to 6.2.0 (#10543)
  Add declarative Sakana AI provider for the OpenAI-compatible Fugu API (#10357)
  fix(developer): expose AGENT_SESSION_ID to shell commands (#10428)
  Clean up stale documentation audit findings (#10114)
  Restore model interactions viewer (#10205)
  fix(acp): forward image content chunks to client during live session (#10485)
  ...

# Conflicts:
#	crates/goose/src/session/session_manager.rs
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.

2 participants