Skip to content

fix(#881): scope parallel-group marker filename per project - #888

Merged
admarble merged 5 commits into
mainfrom
feature/881-bug-exec-hooks-parallel-group-marker-filename-is-g
Aug 3, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/881-bug-exec-hooks-parallel-group-marker-filename-is-g

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Fixes #881 — the /exec parallel-group marker filename was a global constant, so a parallel group in one project silently redirected worktree enforcement for every concurrently-running Claude session on the machine.

  • Root cause: the marker was created with a hardcoded name (/tmp/claude-parallel-group-1.marker) and both hooks resolved the enforced worktree by globbing the whole ${TMPDIR} namespace and taking the first matching marker, with no project scoping.
  • Fix: the marker name now carries a per-project hash — ${TMPDIR}/claude-parallel-<project-hash>-<group-id>.marker — and the readers glob only their own project-scoped prefix. The naming scheme lives in a single sourced helper (parallel-marker.sh) shared by the writer (the /exec skill) and the two readers (the hooks), so they cannot drift. The marker also stores its owning project root (line 2), and the enforcement reader ignores any marker whose stored root ≠ the current project as defense-in-depth.

AC coverage

AC Description Status Evidence
AC-1 Marker filename includes a per-project component ✅ parallel-marker.sh:parallel_marker_prefix → claude-parallel-<md5(project-root)>-
AC-2 Hooks match only current-project markers (all glob sites) ✅ pre-tool.sh enforcement (~648) + agent-id (~250); post-tool.sh agent-id (~84) — all use the project-scoped prefix
AC-3 Foreign marker ignored, not enforced ✅ line-2 owning-root guard at pre-tool.sh enforcement; implemented via stored project root, not worktree-path containment (per spec's flagged tension)
AC-4 Marker name defined in exactly one shared place ✅ parallel-marker.sh is the only site constructing the name; hooks + skill source it. claude-parallel-group literal survives in zero other sites
AC-5 Regression: foreign live marker doesn't block a real-worktree edit ✅ new #881 describe block in pre-tool-hook.integration.test.ts, parametrized over all 3 hook copies

Mutation verification (AC-5 hard gate)

Per the repo testing rule, AC-5 was mutation-verified:

  1. Reverted the reader scoping in templates/hooks/pre-tool.sh (global glob claude-parallel-* restored and the line-2 owner guard neutralized to if false).
  2. Ran the #881 block: exactly AC-5 [templates/hooks/pre-tool.sh] failed (1 failed, 5 passed) — the foreign live marker blocked the real-worktree edit with HOOK_BLOCKED: File operation must be within worktree, exactly the original bug.
  3. Restored via git checkout and confirmed all 6 #881 assertions pass.

The suite also includes a positive control proving the scoping did not disable enforcement: a marker under this project's own scoped name + owner still blocks an edit outside its worktree.

Files changed

  • templates/hooks/parallel-marker.sh (new) + mirrors in hooks/, .claude/hooks/
  • pre-tool.sh / post-tool.sh across all three hook dirs
  • exec/SKILL.md across all three skill dirs
  • __tests__/pre-tool-hook.integration.test.ts (AC-5 regression + positive control)
  • CHANGELOG.md

All three skill copies and all three hook mirrors updated in sync (check-skill-sync + sync-hooks pass).

Test plan

  • npm run build (tsc clean)
  • npm run lint (eslint clean)
  • pre-tool-hook.integration.test.ts + hook-sync.test.ts + check-skill-sync.test.ts — 198 passed
  • AC-5 mutation-verified (see above)

Closes #881

🤖 Generated with Claude Code

admarble added 2 commits July 31, 2026 01:59
The /exec parallel-group marker filename was a global constant
(`claude-parallel-group-1.marker`), and the hooks globbed the whole
`$TMPDIR` namespace and took the first hit. A parallel group in one
project therefore redirected worktree enforcement for every concurrent
Claude session on the machine — blocking legitimate edits with a foreign
worktree path and, for the session that lost the race, silently pointing
the guard nowhere.

- Add hooks/parallel-marker.sh: the single shared naming contract
  (AC-4). It exposes parallel_marker_path/prefix and derives the owning
  project root identically in skill- and hook-context (CLAUDE_PROJECT_DIR,
  falling back to git toplevel). Mirrored in all three hook dirs.
- Filename is now `claude-parallel-<project-hash>-<group-id>.marker`
  (AC-1); readers glob only the project-scoped prefix at all three sites
  (pre-tool enforcement + agent-id, post-tool agent-id) (AC-2).
- Marker stores worktree path (line 1) + owning project root (line 2);
  the enforcement reader skips any marker whose stored root != current,
  as defense-in-depth (AC-3).
- /exec skill sources the helper instead of hardcoding the path.
- Regression test (AC-5): a foreign live marker no longer blocks an edit
  in the real worktree; a positive control proves same-project
  enforcement still fires. Parametrized over all three hook copies.

All three skill copies and all three hook mirrors updated in sync
(check-skill-sync + sync-hooks pass).

Entire-Checkpoint: f9e68dba3115
admarble added 3 commits July 31, 2026 14:37
…hooks-parallel-group-marker-filename-is-g

# Conflicts:
#	CHANGELOG.md
…hooks-parallel-group-marker-filename-is-g

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit ea1f9af into main Aug 3, 2026
8 checks passed
@admarble
admarble deleted the feature/881-bug-exec-hooks-parallel-group-marker-filename-is-g branch August 3, 2026 13:58
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.

bug(exec/hooks): parallel-group marker filename is global — one project's /exec run redirects worktree enforcement for every concurrent session

1 participant