Skip to content

fix: worktree support with .worktrees/ convention and cd-first approach#10

Merged
tombakerjr merged 3 commits into
mainfrom
fix/worktree-support
Feb 10, 2026
Merged

fix: worktree support with .worktrees/ convention and cd-first approach#10
tombakerjr merged 3 commits into
mainfrom
fix/worktree-support

Conversation

@tombakerjr
Copy link
Copy Markdown
Owner

Summary

  • git-guard.py: Parse -C <path> from git commands so the commit-on-main check queries the correct worktree branch. Anchor commit regex to ^\s*git to avoid false positives from heredoc content.
  • using-git-worktrees SKILL.md: Replace sibling directory pattern (../repo-feature) with internal .worktrees/BRANCH_NAME. Use cd-into-worktree as the primary workflow; git -C documented only as a fallback.
  • agent-team-development SKILL.md: Migrate from ../REPO-team-BRANCH-impl-N to .worktrees/team-BRANCH-impl-N. Add explicit cd-into-worktree instructions in the implementer spawn prompt.
  • implementer.md: Agents work from within their worktree directly; git -C is a fallback only.
  • .gitignore: Add .worktrees/ entry.

Closes #7

Test plan

  • Verify git-guard.py allows commits in worktrees via git -C .worktrees/<branch> commit
  • Verify git-guard.py blocks commits on main from worktree context
  • Verify git-guard.py doesn't false-positive on heredoc content containing "git commit"
  • Confirm no remaining ../ sibling directory references in skills or agents
  • Confirm .worktrees/ is gitignored

🤖 Generated with Claude Code

claude and others added 2 commits February 10, 2026 01:04
Addresses #7 - three worktree support gaps:

1. git-guard.py: Parse -C <path> from git commands so the commit-on-main
   check queries the correct worktree branch instead of always checking
   the main repo. Also anchor the commit regex to line start (^\s*git)
   to avoid false positives from heredoc content.

2. SKILL.md: Replace sibling directory pattern (../repo-feature) with
   internal .worktrees/BRANCH_NAME pattern that stays within Claude
   Code's permission scope. Use git -C instead of cd for worktree ops.

3. implementer.md: Replace "don't use git -C" guidance with
   "use git -C .worktrees/<branch>" for worktree operations.

4. .gitignore: Add .worktrees/ entry.

Closes #7

https://claude.ai/code/session_0133wuXFfTNKJjnaTuc12Zco
The original commit overcorrected toward git -C for all worktree
operations. In practice, git -C triggers repeated permission approval
prompts in Claude Code. Agents should cd into their worktree and work
normally; git -C is reserved as a fallback.

Changes:
- implementer.md: "work from within worktree directly, fall back to
  git -C only when necessary"
- using-git-worktrees SKILL.md: restore cd-based workflow for Phase 3,
  Working in Worktrees, example flow, and troubleshooting sections
- agent-team-development SKILL.md: migrate from sibling directory
  pattern (../REPO-team-BRANCH-impl-N) to internal .worktrees/
  pattern; add explicit cd-into-worktree instructions in implementer
  spawn prompt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude Bot commented Feb 10, 2026

Claude finished @tombakerjr's task in 1m 26s —— View job


Review Complete

  • Read project context (CLAUDE.md)
  • Review git-guard.py changes
  • Review skill and agent markdown files
  • Review .gitignore changes
  • Post review findings

LGTM - no blocking issues

I verified the following:

git-guard.py (hooks/git-guard.py:19-26, hooks/git-guard.py:28-40, hooks/git-guard.py:68-72)

  • parse_git_c_path() correctly handles both quoted and unquoted paths
  • get_current_branch() now accepts optional cwd parameter for worktree support
  • ✅ Commit regex anchored to (?:^|&&|;|\|)\s*git prevents heredoc false positives
  • ✅ Correctly parses -C <path> and queries the right branch for worktrees

Worktree convention migration

  • ✅ All references to sibling directory pattern (../repo-feature) removed
  • ✅ Consistent use of .worktrees/BRANCH_NAME pattern throughout
  • .worktrees/ properly added to .gitignore and verified ignored by git

Documentation (skills/using-git-worktrees/SKILL.md, skills/agent-team-development/SKILL.md)

  • ✅ Clear guidance to cd into worktree first, git -C as fallback only
  • ✅ Examples updated to show .worktrees/ pattern
  • ✅ Anti-patterns section explicitly warns against sibling directories

agents/implementer.md:18

  • ✅ Updated to emphasize cd-first approach

…sitives

- parse_git_c_path: handle both quoted ("path with spaces") and
  unquoted paths in git -C arguments
- commit detection: remove re.MULTILINE (which made ^ match every
  line, including heredoc content) and instead match git commit at
  string start or after shell operators (&&, ;, |)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tombakerjr tombakerjr merged commit 0dbb03b into main Feb 10, 2026
2 checks passed
@tombakerjr tombakerjr deleted the fix/worktree-support branch February 10, 2026 06:16
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.

Worktree support: git-guard, skill, and implementer agent need updates

2 participants