This guide helps diagnose and resolve common issues with the sc-git-worktree package for Synaptic Canvas.
Run these commands to verify your setup:
# Verify git version (requires >= 2.20)
git --version
# Check if sc-git-worktree package is installed
ls -la .claude/commands/sc-git-worktree.md
ls -la .claude/skills/sc-managing-worktrees/
# List existing worktrees
git worktree list
# Check tracking document (if enabled)
ls -la ../$(basename $(git rev-parse --show-toplevel))-worktrees/worktree-tracking.md
# Verify repo name token expansion
basename $(git rev-parse --show-toplevel)
# Check agent registry
cat .claude/agents/registry.yaml | grep worktreeProblem: When you run /sc-git-worktree, Claude doesn't recognize the command.
Symptoms:
Unknown command: /sc-git-worktree
Root Causes:
- Package only installed globally (requires local installation)
- Not inside a git repository
- Installation path incorrect
Resolution:
- Verify you're in a git repository:
git rev-parse --git-dir
# Should output: .git- Install locally (sc-git-worktree is local-only):
# WRONG - global install not supported
python3 tools/sc-install.py install sc-git-worktree --dest ~/Documents/.claude
# CORRECT - local install
python3 tools/sc-install.py install sc-git-worktree --dest ./.claude- Verify installation:
ls .claude/commands/sc-git-worktree.md
ls .claude/agents/worktree-*.md- If missing, reinstall:
python3 tools/sc-install.py install sc-git-worktree --dest ./.claudePrevention:
- sc-git-worktree is local-only by design (repo-specific operations)
- Always install in the repository's
.claudedirectory
Problem: Tracking document becomes corrupted or contains invalid data.
Symptoms:
Error: Cannot parse tracking document
Tracking row format invalid
Duplicate branch entries in tracking
Root Causes:
- Manual edits breaking Markdown table format
- Concurrent updates from multiple agents
- Partial writes due to interruption
Resolution:
- Check tracking file format:
TRACKING_FILE="../$(basename $(git rev-parse --show-toplevel))-worktrees/worktree-tracking.md"
cat "$TRACKING_FILE"Expected format:
# Worktree Tracking
| Branch | Path | Base | Purpose | Owner | Created | Status | LastChecked | Notes |
|--------|------|------|---------|-------|---------|--------|-------------|-------|
| feature-x | ../repo-worktrees/feature-x | main | Feature X | user | 2025-12-02T10:00:00Z | active | 2025-12-02T10:00:00Z | |- Fix formatting issues:
# Backup first
cp "$TRACKING_FILE" "$TRACKING_FILE.backup"
# Manually edit to fix table alignment
# Ensure all rows have 9 pipe-separated columns
nano "$TRACKING_FILE"- Remove duplicates:
# Find duplicate branches
awk -F'|' 'NR>2 {print $2}' "$TRACKING_FILE" | sort | uniq -d- Regenerate if severely corrupted:
# Backup and remove
mv "$TRACKING_FILE" "$TRACKING_FILE.old"
# Scan worktrees to rebuild
/sc-git-worktree --scanPrevention:
- Don't manually edit tracking file during agent operations
- Use
/sc-git-worktree --scanto rebuild from actual worktrees - Enable tracking only if you need audit trail
Problem: Cannot create or remove worktree due to locks.
Symptoms:
fatal: 'worktrees/feature-x' is already locked
fatal: another git process seems to be running in this repository
Root Causes:
- Previous git operation crashed or was interrupted
- Stale lock files from abnormal termination
- Concurrent git operations in same worktree
Resolution:
- Check for lock files:
# Main repo locks
ls -la .git/*.lock
ls -la .git/worktrees/*/locked
# Worktree-specific locks
WORKTREE_PATH="../$(basename $(git rev-parse --show-toplevel))-worktrees/feature-x"
ls -la "$WORKTREE_PATH/.git"- Remove stale locks (CAUTION):
# Only if you're SURE no git operations are running
rm -f .git/*.lock
rm -f .git/worktrees/*/locked
# For specific worktree
rm -f .git/worktrees/feature-x/locked- Check for running git processes:
ps aux | grep git- If worktree administrative entry is locked:
# Unlock specific worktree
git worktree unlock feature-x
# Or by path
git worktree unlock ../repo-worktrees/feature-x- Force unlock if necessary:
# Use with caution
rm -f .git/worktrees/*/lockedPrevention:
- Always let git operations complete
- Don't Ctrl+C during git commands
- Use
/sc-git-worktree --abortfor safe cancellation
Problem: Cannot create worktree because target path exists.
Symptoms:
fatal: 'path/to/worktree' already exists
Error: worktree path exists with content
Root Causes:
- Previous worktree not cleaned up properly
- Directory created manually
- Partial cleanup from failed operation
Resolution:
- Check what exists at the path:
WORKTREE_PATH="../$(basename $(git rev-parse --show-toplevel))-worktrees/feature-x"
ls -la "$WORKTREE_PATH"- If it's a valid worktree:
# List all worktrees
git worktree list
# If listed, use existing worktree
cd "$WORKTREE_PATH"
# Or remove properly
/sc-git-worktree --cleanup feature-x- If it's not registered but directory exists:
# Check git's worktree registry
git worktree list | grep feature-x
# If not listed, it's orphaned - safe to remove manually
rm -rf "$WORKTREE_PATH"- If it's a different branch's worktree:
# List what branch it contains
cd "$WORKTREE_PATH"
git branch --show-current
# If wrong branch, go back to main repo and prune
cd -
git worktree prune- Force cleanup (CAUTION - data loss risk):
# Backup first
cp -r "$WORKTREE_PATH" "$WORKTREE_PATH.backup"
# Remove directory
rm -rf "$WORKTREE_PATH"
# Remove git's tracking
git worktree prunePrevention:
- Always use
/sc-git-worktree --cleanupor--abortto remove worktrees - Never manually delete worktree directories without
git worktree remove - Check path before creating:
ls -la ../repo-worktrees/
Problem: Cannot push or modify protected branches in worktree.
Symptoms:
remote: error: GH006: Protected branch update failed
! [remote rejected] main -> main (protected branch hook declined)
Root Causes:
- Attempting to push directly to protected branch (main, master, develop)
- Branch protection rules on remote repository
- Creating worktree from protected branch base
Resolution:
- Check branch protection status:
# Via GitHub CLI (if available)
gh api repos/:owner/:repo/branches/main/protection
# Or check remote rules
git ls-remote --heads origin- Never commit directly to protected branches:
# WRONG - creating worktree for main
/sc-git-worktree --create main main
# CORRECT - create feature branch from main
/sc-git-worktree --create feature-x main- If accidentally in protected branch:
cd worktree-path
git checkout -b feature-x # Create new branch
git push origin feature-x # Push to new branch- Use proper workflow:
# Create feature branches from protected base
/sc-git-worktree --create feature-123 main
/sc-git-worktree --create hotfix-456 release/1.0Prevention:
- Never create worktrees directly on protected branches
- Always branch from protected branches (main, master, develop, release/*)
- Follow repository's branching strategy
Problem: Cannot cleanup or abort because worktree has uncommitted changes.
Symptoms:
Error: worktree has uncommitted changes
fatal: worktree contains modified or untracked files
worktree.dirty: cannot proceed
Root Causes:
- Uncommitted changes in worktree
- Untracked files present
- Stash applied but not committed
Resolution:
- Check status:
cd ../repo-worktrees/feature-x
git status- Commit changes:
git add .
git commit -m "WIP: feature progress"
git push origin feature-x- Stash changes:
git stash push -m "WIP feature-x"
# Note: stash is tied to this worktree- Discard changes (CAUTION - data loss):
# Discard uncommitted changes
git reset --hard HEAD
# Remove untracked files
git clean -fd- Return to main repo and cleanup:
cd - # Back to main repo
/sc-git-worktree --cleanup feature-xPrevention:
- Commit or stash before cleanup operations
- Use
git statusto check cleanliness - Enable git hooks to prevent dirty commits
Problem: Token {{REPO_NAME}} not replaced during installation.
Symptoms:
Path created: ../{{REPO_NAME}}-worktrees/feature-x
Error: directory not found: ../{{REPO_NAME}}-worktrees
Root Causes:
- Installation used
--no-expandflag - Not inside git repository during installation
- Git not detecting repository name correctly
Resolution:
- Check if tokens are expanded:
# Check installed files for tokens
grep -r "{{REPO_NAME}}" .claude/- Verify repository detection:
# Get repo name
basename $(git rev-parse --show-toplevel)
# Should output your repo name, e.g., "my-repo"- Reinstall with expansion:
# Ensure you're in the repo root
git rev-parse --show-toplevel
# Reinstall (expansion is default)
python3 tools/sc-install.py install sc-git-worktree --dest ./.claude --force- Manual fix (if needed):
# Find actual repo name
REPO=$(basename $(git rev-parse --show-toplevel))
# Replace tokens in installed files
find .claude/ -type f -exec sed -i.bak "s/{{REPO_NAME}}/$REPO/g" {} \;
# Clean up backup files
find .claude/ -name "*.bak" -deletePrevention:
- Always install from within the repository
- Don't use
--no-expandflag - Verify git is working:
git status
Problem: /sc-git-worktree --cleanup fails to remove worktree.
Symptoms:
Error: cannot remove worktree
fatal: validation failed, cannot remove working tree
Cleanup incomplete: worktree still exists
Root Causes:
- Worktree is locked
- Directory has open file handles
- Permission issues
- Worktree is dirty
Resolution:
- Check worktree status:
git worktree list- Navigate to worktree and check:
cd ../repo-worktrees/feature-x
git status
lsof +D . # Check for open files (macOS/Linux)- Close all programs using the worktree:
# Find processes
lsof +D ../repo-worktrees/feature-x
# Or on Linux
fuser -v ../repo-worktrees/feature-x- Try cleanup again:
cd - # Back to main repo
/sc-git-worktree --cleanup feature-x- Force cleanup (CAUTION):
# Remove git's tracking first
git worktree remove --force feature-x
# Then remove directory if still exists
rm -rf ../repo-worktrees/feature-x
# Prune stale entries
git worktree prune- Fix permissions if needed:
# Grant permissions
chmod -R u+rwX ../repo-worktrees/feature-x
# Then retry cleanupPrevention:
- Close editors and terminals before cleanup
- Commit or stash changes first
- Use
--abortfor safer cancellation during development
Problem:
git worktree: command not supported
fatal: unknown option: worktreeResolution:
- Check git version:
git --version
# Requires >= 2.20- Upgrade git:
macOS:
brew update
brew upgrade gitLinux (Ubuntu/Debian):
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install gitWindows:
- Download latest from git-scm.com
- Verify upgrade:
git --version
git worktree --helpProblem:
fatal: not a git repository (or any of the parent directories): .gitResolution:
- Verify you're in a git repo:
git status- If not initialized:
git init- Or navigate to correct directory:
cd /path/to/your/repo
git status # VerifyProblem:
Package installed to ~/Documents/.claude but commands not foundResolution:
sc-git-worktree is local-only:
# WRONG - global install
python3 tools/sc-install.py install sc-git-worktree --dest ~/Documents/.claude
# CORRECT - local install
cd /path/to/your/repo
python3 tools/sc-install.py install sc-git-worktree --dest ./.claudeProblem: Worktrees created in wrong location.
Resolution:
- Default structure (automatic):
your-repo/ # Main repository
your-repo-worktrees/ # Worktree container (sibling)
├── feature-x/ # Individual worktrees
├── feature-y/
└── worktree-tracking.md
- Verify expected path:
REPO=$(basename $(git rev-parse --show-toplevel))
echo "../${REPO}-worktrees"- If worktrees in wrong location, you may have:
- Modified agent files manually
- Token expansion not applied
- See "REPO_NAME Token Not Expanding" above
Problem: Tracking document exists but agents don't update it.
Resolution:
- Check agent configuration:
grep -A5 "tracking_enabled" .claude/agents/worktree-*.md- Tracking is enabled by default. To disable:
# Edit agent invocation to pass tracking_enabled: false
# This requires modifying the skill or command- Or manually manage:
# Keep tracking file but manage manually
# Agents won't touch it if tracking_enabled=falseProblem: Branch names conflict with filesystem paths.
Resolution:
Avoid problematic branch names:
# AVOID - filesystem conflicts
feature/new-thing # Contains slash
main.backup # Hidden file confusion
-hotfix # Starts with dash
# PREFER
feature-new-thing
main-backup
hotfix-123Problem: Worktrees not pushing to remote.
Resolution:
- Each worktree is independent:
cd ../repo-worktrees/feature-x
git remote -v # Should show same remotes as main repo- Push from worktree:
cd ../repo-worktrees/feature-x
git push origin feature-x- If remote missing, add:
git remote add origin <url>Problem: Tracking conflicts in shared repositories.
Resolution:
- Tracking is local (not committed to git):
# tracking.md is in ../repo-worktrees/, not in repo
ls -la ../repo-worktrees/worktree-tracking.md-
Each user has own tracking file.
-
For team coordination, commit to repo:
# Create team tracking in repo
mkdir -p .worktrees
touch .worktrees/team-tracking.md
git add .worktrees/team-tracking.md
git commit -m "docs: add team worktree tracking"Problem: CI systems can't use worktrees effectively.
Resolution:
-
Worktrees are for local development only
- Don't use in CI pipelines
- CI should use fresh clones
-
For CI that needs multiple branches:
# Use separate clones, not worktrees
git clone <url> repo-main
git clone <url> repo-featureProblem: Worktree operations slow in large repos.
Resolution:
- Use shallow clones:
# Initial clone
git clone --depth 1 <url>
# Worktrees inherit from main repo
# Performance improved via shared .git- Limit fetch operations:
# Don't fetch all remotes
git fetch origin
# Instead of
git fetch --all- Use sparse checkout if needed:
cd ../repo-worktrees/feature-x
git sparse-checkout init --cone
git sparse-checkout set src/Problem: Managing dozens of worktrees becomes unwieldy.
Resolution:
- Regularly cleanup inactive worktrees:
# List all
git worktree list
# Remove unused
/sc-git-worktree --cleanup old-feature-1
/sc-git-worktree --cleanup old-feature-2- Use tracking to audit:
# Review tracking document
cat ../repo-worktrees/worktree-tracking.md- Prune stale entries:
git worktree prune -vProblem: Case-insensitive filesystem causes conflicts.
Resolution:
- Be careful with branch names:
# AVOID - seen as same on macOS default filesystem
feature-Test
feature-test- For case-sensitive needs:
# Create case-sensitive APFS volume
diskutil apfs addVolume disk1 "Case-sensitive APFS" RepoVolumeProblem: Permissions differ from macOS.
Resolution:
- Ensure executable permissions:
chmod +x .claude/scripts/*.sh 2>/dev/null || true- Check ownership:
ls -la ../repo-worktrees/
# Should match your userProblem: Path separators and Git Bash interactions.
Resolution:
- Use Git Bash (comes with Git for Windows):
# Always use forward slashes
cd ../repo-worktrees/feature-x- Or use WSL:
# Better Linux compatibility
wsl
cd /mnt/c/path/to/repo- Watch for line endings:
git config core.autocrlf trueEscalate to GitHub issues if you encounter:
- Tracking file corruption that can't be resolved
- Git worktree commands failing unexpectedly
- Token expansion not working after reinstall
- Data loss from cleanup operations
- Integration issues with git hooks or remotes
Include the following information:
- Environment details:
git --version
python3 --version
uname -a # or systeminfo on Windows
basename $(git rev-parse --show-toplevel)- Installation details:
ls -la .claude/commands/sc-git-worktree.md
ls -la .claude/agents/worktree-*.md
cat .claude/agents/registry.yaml | grep worktree- Git worktree state:
git worktree list
git branch -a
ls -la ../$(basename $(git rev-parse --show-toplevel))-worktrees/- Command that failed:
# Exact command
/sc-git-worktree --create feature-x main- Error output:
# Full error message
- Tracking document (if applicable):
cat ../repo-worktrees/worktree-tracking.mdBasic diagnostics:
# Git and repo info
git --version
git worktree list
git status
git remote -v
# Installation check
ls -la .claude/commands/sc-git-worktree.md
ls -la .claude/agents/worktree-*.md
ls -la .claude/skills/sc-managing-worktrees/
# Token expansion check
grep -r "{{REPO_NAME}}" .claude/ || echo "No tokens found (good)"For worktree issues:
# List all worktrees
git worktree list
# Check specific worktree
cd ../repo-worktrees/feature-x
git status
git log --oneline -5
cd -
# Check git internals
ls -la .git/worktrees/For tracking issues:
# Show tracking file
TRACKING="../$(basename $(git rev-parse --show-toplevel))-worktrees/worktree-tracking.md"
cat "$TRACKING"
# Verify format
head -5 "$TRACKING"A: The sc-git-worktree package enforces a standard layout for consistency:
parent/
├── your-repo/ # Main repo
└── your-repo-worktrees/ # Worktrees container
For custom paths, use git commands directly:
git worktree add /custom/path/feature-x feature-xBut you'll lose tracking and agent management features.
A:
- Git still tracks it:
git worktree listshows it - Path is broken
- Fix with:
git worktree prune
Always use:
/sc-git-worktree --cleanup branch-name
# or
git worktree remove path/to/worktreeA: No, worktrees are tied to their path. To "move":
- Commit and push all changes
- Cleanup old worktree:
/sc-git-worktree --cleanup old-branch - Create new worktree at new location (requires custom git commands)
Or just create a new worktree and delete the old one.
A:
- Worktrees share the same
.git/with main repo - All remotes are identical
- Fetch in main repo updates all worktrees
- Push from any worktree affects the remote
A: No, git prevents this:
fatal: 'feature-x' is already checked out at '../repo-worktrees/feature-x'One branch = one worktree (or main repo) at a time.
A:
--cleanup: Remove completed worktree (expects clean state, removes branch)--abort: Cancel in-progress work (handles dirty state, preserves branch)
Use --cleanup when done with a feature.
Use --abort when canceling exploratory work.
A: Generally positive:
- Faster than cloning (shares objects)
- No network needed to switch contexts
- Minimal disk overhead
But many worktrees (>20) may slow down some operations.
A: Yes, excellent for monorepos:
- Work on multiple features simultaneously
- Test integration locally
- Each worktree can have different build artifacts
But tracking may become verbose with many worktrees.
A:
# Pull latest changes
cd /path/to/synaptic-canvas
git pull origin main
# Reinstall (force overwrites existing)
cd /path/to/your/repo
python3 /path/to/synaptic-canvas/tools/sc-install.py \
install sc-git-worktree --dest ./.claude --forceA: Not recommended:
- Tracking is in
../repo-worktrees/(outside repo) - Intended as local developer tool
- Conflicts if multiple devs use worktrees
For team coordination, create separate tracking in-repo:
mkdir .worktrees
# Add team tracking here
git add .worktrees/- Package README:
packages/sc-git-worktree/README.md - Use Cases:
packages/sc-git-worktree/USE-CASES.md - Changelog:
packages/sc-git-worktree/CHANGELOG.md - Skill Documentation:
packages/sc-git-worktree/skills/sc-managing-worktrees/SKILL.md - Agent Specifications:
packages/sc-git-worktree/agents/sc-worktree-create.mdpackages/sc-git-worktree/agents/sc-worktree-scan.mdpackages/sc-git-worktree/agents/sc-worktree-cleanup.mdpackages/sc-git-worktree/agents/sc-worktree-abort.md
- Git Worktree Docs:
git help worktree - Repository: https://github.com/randlee/synaptic-canvas
- Issues: https://github.com/randlee/synaptic-canvas/issues