fix(agent-claude-code): root hook commands at $CLAUDE_PROJECT_DIR so they survive subdir cwd#2160
Open
uitlaber wants to merge 2 commits into
Open
fix(agent-claude-code): root hook commands at $CLAUDE_PROJECT_DIR so they survive subdir cwd#2160uitlaber wants to merge 2 commits into
uitlaber wants to merge 2 commits into
Conversation
…they survive subdir cwd
The PostToolUse/activity hooks were registered with a bare relative path
(.claude/metadata-updater.sh, .claude/activity-updater.sh and their .cjs
variants). That path only resolves when the agent's cwd is the worktree root;
when the agent runs a command from a sub-directory (e.g. cwd=<worktree>/services/api)
the hook fails with '/bin/sh: .claude/activity-updater.sh: No such file or directory'.
The hook errors are non-blocking, so the agent keeps working, but every tool call
spams the failure.
Fix: root the hook commands at $CLAUDE_PROJECT_DIR, which Claude Code sets to the
worktree root and exposes to hooks (the updater scripts already use
${CLAUDE_PROJECT_DIR:-$(pwd)} internally). The command string is still identical
across worktrees, preserving the symlink-safe 'same settings.json everywhere'
intent (so shared/symlinked .claude/ dirs don't clobber each other), and now it
also resolves from any sub-directory. The hook upsert keys off the
'*-updater.{sh,cjs}' identifier, so existing relative/absolute entries migrate.
Tests updated to assert the env-rooted form (incl. the Windows .cjs case and the
'identical across worktrees' guarantee) plus a regression test that no generated
hook command is cwd-relative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Claude Code agent plugin registers its lifecycle hook commands with bare relative paths —
.claude/metadata-updater.sh,.claude/activity-updater.sh(and their.cjsvariants on Windows). A relative path only resolves when the hook process's cwd is the worktree root. When a tool call runs from a sub-directory — most notably sub-agent (Agent/Task) tool calls, which change the working directory — the shell can't find the script:The errors are non-blocking (the agent keeps working), but they spam the transcript on every tool call and drop the
.ao/activity.jsonlactivity signal during sub-agent work, which can lead to falsestuck/probe_failurelifecycle detection on otherwise-healthy sessions.Fixes #2090.
Fix
Root the hook commands at
$CLAUDE_PROJECT_DIR, which Claude Code sets to the worktree root and exposes to hooks (the updater scripts already use${CLAUDE_PROJECT_DIR:-$(pwd)}internally):.claude/metadata-updater.sh→"$CLAUDE_PROJECT_DIR/.claude/metadata-updater.sh".claude/activity-updater.sh→"$CLAUDE_PROJECT_DIR/.claude/activity-updater.sh"node .claude/*-updater.cjs→node "$CLAUDE_PROJECT_DIR/.claude/*-updater.cjs"This preserves the original symlink-safe intent — the command string is identical across worktrees, so shared/symlinked
.claude/dirs don't clobber each other'ssettings.json— while now also resolving correctly from any sub-directory. The hook upsert keys off the*-updater.{sh,cjs}identifier, so existing relative/absolute entries are migrated in place on the next setup.Tests
$CLAUDE_PROJECT_DIR-rooted form (including the Windows.cjscase and the "identicalsettings.jsonacross worktrees" guarantee).agent-claude-codesuite: 272/272 passing.patchfor@aoagents/ao-plugin-agent-claude-code).