fix(agent-claude-code): use $CLAUDE_PROJECT_DIR for hook commands (fixes #2090)#2091
Open
vikt0r0 wants to merge 1 commit into
Open
fix(agent-claude-code): use $CLAUDE_PROJECT_DIR for hook commands (fixes #2090)#2091vikt0r0 wants to merge 1 commit into
vikt0r0 wants to merge 1 commit into
Conversation
The activity/metadata lifecycle hooks were registered with relative command paths (.claude/activity-updater.sh, .claude/metadata-updater.sh) for every hook event, including PreToolUse/PostToolUse/SubagentStart/SubagentStop. When a hook fires from a sub-agent (Agent/Task) tool call, the process cwd is not the worktree root, so the shell cannot resolve the relative path: /bin/sh: 1: .claude/activity-updater.sh: not found This is non-blocking but spams the transcript and drops the .ao/activity.jsonl signal during sub-agent runs, which can cause false stuck/probe_failure detection on healthy sessions. Prefix the commands with $CLAUDE_PROJECT_DIR (exported by Claude Code for hook execution and always pointing at the worktree root). This keeps settings.json content identical across worktrees while resolving correctly regardless of the hook's cwd. Applied to both the unix (.sh) and windows (.cjs) branches; tests updated to the new contract. Fixes AgentWrapper#2090 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 activity/metadata lifecycle hooks with relative command paths (
.claude/activity-updater.sh,.claude/metadata-updater.sh) for every hook event, includingPreToolUse/PostToolUse/SubagentStart/SubagentStop.When a hook fires from a sub-agent (
Agent/Tasktool) call, the process working directory is not the worktree root, so the shell can't resolve the relative path:It's non-blocking, but it (a) spams the agent transcript while sub-agents run and (b) drops the
.ao/activity.jsonlsignal during sub-agent work, which can cause falsestuck/probe_failurelifecycle detection on otherwise-healthy sessions. At the top-level agent cwd (worktree root) the relative path resolves fine — which is why it only shows up once the agent dispatches parallelExplore/Tasksub-agents.Fix
Prefix the hook commands with
$CLAUDE_PROJECT_DIR, which Claude Code exports for hook execution and which always points at the worktree root:This resolves correctly regardless of the hook's cwd, while keeping
settings.jsoncontent identical across worktrees (no hardcoded absolute path — preserving the existing "different worktree paths produce identical settings.json" guarantee). The dedup/upsert logic keys off the bare filenames (activity-updater.sh, …), so existing settings migrate cleanly.Applied to both the unix (
.sh) and windows (.cjs) branches.Tests
index.test.tsassertions to the new$CLAUDE_PROJECT_DIRcontract (including the "updates an existing absolute hook path" migration test).pnpm --filter @aoagents/ao-plugin-agent-claude-code typecheck✅pnpm --filter @aoagents/ao-plugin-agent-claude-code test→ 270 passing. The one failing test (activity-updater.integration.test.ts, a special-character escaping round-trip) also fails on pristinemainin this environment (/bin/shescaping), and is unrelated to this change — it touches neither the hook command paths nor the updater scripts.Fixes #2090