check-apm-agents-valid can never pass from a worktree under .claude/worktrees/ #199

Open
opened 2026-11-22 16:57:35 +00:00 by Claude · 0 comments
Owner

What happened

Pushing from an agent worktree (/root/ai-development/.claude/worktrees/agent-<id>) fails two pre-push gates with "4 of 4 tracked agent files were not discovered":

  • check-apm-agents-valid
  • tests/test-check-apm-agents-valid.sh (run by run-tests)

The agent files are on disk.

Cause

scripts/check-apm-agents-valid.sh discovers agents with:

find "$REPO_ROOT/plugins" -type f -name '*.agent.md' \
  -path '*/.apm/agents/*' \
  -not -path '*/.claude/worktrees/*'

The filter means "skip worktrees nested inside this checkout". When the checkout itself is a worktree, $REPO_ROOT already contains /.claude/worktrees/, so every path matches and every agent is excluded. The comment says the filter mirrors tests/run-bats.sh, which probably has the same flaw.

Fix

Anchor the exclusion to the repo root, for example -not -path "$REPO_ROOT/.claude/worktrees/*". In this script find starts at $REPO_ROOT/plugins, so a nested worktree can't be reached and the filter may simply be dropped. Apply the same change in tests/run-bats.sh and any other copies, and add a test that runs the gate from a checkout whose path contains /.claude/worktrees/.

Impact

Agent subagents launched with worktree isolation (the Claude Code Agent tool's isolation: worktree) can't push without --no-verify, which this repo forbids. They have to hand back to a session in the main checkout.

Found while working Copilot CLI agent behaviour from docs.

## What happened Pushing from an agent worktree (`/root/ai-development/.claude/worktrees/agent-<id>`) fails two pre-push gates with "4 of 4 tracked agent files were not discovered": - `check-apm-agents-valid` - `tests/test-check-apm-agents-valid.sh` (run by `run-tests`) The agent files are on disk. ## Cause `scripts/check-apm-agents-valid.sh` discovers agents with: ```sh find "$REPO_ROOT/plugins" -type f -name '*.agent.md' \ -path '*/.apm/agents/*' \ -not -path '*/.claude/worktrees/*' ``` The filter means "skip worktrees nested inside this checkout". When the checkout itself is a worktree, `$REPO_ROOT` already contains `/.claude/worktrees/`, so every path matches and every agent is excluded. The comment says the filter mirrors `tests/run-bats.sh`, which probably has the same flaw. ## Fix Anchor the exclusion to the repo root, for example `-not -path "$REPO_ROOT/.claude/worktrees/*"`. In this script `find` starts at `$REPO_ROOT/plugins`, so a nested worktree can't be reached and the filter may simply be dropped. Apply the same change in `tests/run-bats.sh` and any other copies, and add a test that runs the gate from a checkout whose path contains `/.claude/worktrees/`. ## Impact Agent subagents launched with worktree isolation (the Claude Code `Agent` tool's `isolation: worktree`) can't push without `--no-verify`, which this repo forbids. They have to hand back to a session in the main checkout. Found while working [Copilot CLI agent behaviour from docs](https://git.rkdr.net/Mortis/Holocron/issues/187).
Claude added the Kind/BugStatus/Needs Triage labels 2026-11-22 16:57:35 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#199