Skip to content

Commit 1cb9dc5

Browse files
thecodedriftclaude
andcommitted
docs(worktrees): document all three id spellings and probe .name
The contract comment said "both are read" while the implementation accepts three (.worktree_id, .worktreeId, .name). Name all three, and write down that .name rests on one captured payload rather than a guaranteed contract — an unrelated .name lands on the regex guard below and fails loudly, which is the intended floor. Restore .base_path to the documented-but-unused field list (dropped in the rewrite, not deliberately), and show a .name payload in the SKILL.md verify probe so the fallback is discoverable without reading the script. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jwc9FFroR3mTZ4hLiSkkX3
1 parent 841c918 commit 1cb9dc5

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

.agents/skills/worktrees-pnpm/SKILL.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ printf '{"hook_event_name":"WorktreeCreate","cwd":"%s","worktree_id":"probe"}' "
109109
| .agents/skills/worktrees-pnpm/scripts/worktree-create.sh
110110
# expect: <repo>/worktrees/probe on stdout, git chatter on stderr, exit 0
111111

112+
# The id field is not stable across callers, so .worktreeId and .name are read
113+
# too — `.name` is what a background agent's payload actually carries.
114+
printf '{"hook_event_name":"WorktreeCreate","cwd":"%s","name":"probe-name"}' "$PWD" \
115+
| .agents/skills/worktrees-pnpm/scripts/worktree-create.sh
116+
# expect: <repo>/worktrees/probe-name
117+
112118
printf '{"hook_event_name":"WorktreeRemove","worktree_path":"%s"}' "$PWD/worktrees/probe" \
113119
| .agents/skills/worktrees-pnpm/scripts/worktree-remove.sh
120+
# ...and the same for worktrees/probe-name
114121
```
115122

116123
**2. Add the ignores** described in the next section. Skipping this is the single most common way

.agents/skills/worktrees-pnpm/scripts/worktree-create.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
# Layout: /path/to/<repo> -> /path/to/<repo>/worktrees/<worktree_id>
1919
#
2020
# Contract (docs: code.claude.com/docs/en/hooks):
21-
# stdin - JSON identifying the worktree, plus .cwd, .session_id, ...
21+
# stdin - JSON identifying the worktree, plus .base_path, .cwd, .session_id, ...
2222
# The id field is NOT stable across callers: a background agent's
2323
# payload carries `.name` (e.g. "agent-a5e1de46e730bdfd7") and no
24-
# `.worktree_id` at all, so both are read. Accepting only one of them
24+
# `.worktree_id` at all, so all three spellings are read
25+
# (.worktree_id, .worktreeId, .name). Accepting only one of them
2526
# fails worktree creation outright with a message that reads like the
26-
# harness sent nothing.
27+
# harness sent nothing. `.name` is the weakest of the three — it is
28+
# justified by one captured payload, not a guaranteed contract — so a
29+
# caller that sends an unrelated `.name` while genuinely lacking both
30+
# id fields lands on the validation below and fails loudly, which is
31+
# the intended floor rather than an accident.
2732
# stdout - the absolute path of the created worktree, plain text, REQUIRED
2833
# exit - non-zero, or zero with empty stdout, fails worktree creation
2934
# This hook replaces the default logic entirely, so it must run `git worktree add`.

0 commit comments

Comments
 (0)