Skip to content

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
AgentWrapper:mainfrom
uitlaber:fix/hooks-cwd-relative-path
Open

fix(agent-claude-code): root hook commands at $CLAUDE_PROJECT_DIR so they survive subdir cwd#2160
uitlaber wants to merge 2 commits into
AgentWrapper:mainfrom
uitlaber:fix/hooks-cwd-relative-path

Conversation

@uitlaber

Copy link
Copy Markdown

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 .cjs variants 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:

PostToolUse hook error  ⎿ /bin/sh: .claude/activity-updater.sh: No such file or directory

The errors are non-blocking (the agent keeps working), but they spam the transcript on every tool call and drop the .ao/activity.jsonl activity signal during sub-agent work, which can lead to false stuck / probe_failure lifecycle 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.cjsnode "$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's settings.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

  • Updated the hook-setup tests to assert the $CLAUDE_PROJECT_DIR-rooted form (including the Windows .cjs case and the "identical settings.json across worktrees" guarantee).
  • Added a regression test asserting that no generated hook command is cwd-relative.
  • Full agent-claude-code suite: 272/272 passing.
  • Added a changeset (patch for @aoagents/ao-plugin-agent-claude-code).

uitlaber added 2 commits June 20, 2026 01:31
…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.
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.

Lifecycle hook commands use relative paths → .claude/activity-updater.sh: not found during sub-agent (Agent/Task) tool calls

1 participant