Worktree Isolation
Sequant uses Git worktrees to isolate each issue’s work, keeping your main branch clean.
What Are Worktrees?
Section titled “What Are Worktrees?”Git worktrees let you check out multiple branches simultaneously in different directories. Each worktree is an independent working copy of your repository.
project/ # Main repo (stays on main)├── .git/├── src/└── ...
../worktrees/└── feature/ └── 123-add-caching/ # Worktree for issue #123 ├── .git # Link to main .git ├── src/ └── ...Why Worktrees?
Section titled “Why Worktrees?”Problem: Branch Pollution
Section titled “Problem: Branch Pollution”Without isolation, half-finished work pollutes your main branch:
# Traditional workflowgit checkout -b feature/123# Work on feature...# Urgent bug comes in!git stashgit checkout maingit checkout -b hotfix/456# Fix bug...# Where was I with feature/123?git checkout feature/123git stash pop# Conflicts? Lost context?Solution: Worktree Isolation
Section titled “Solution: Worktree Isolation”With Sequant, each issue gets its own directory:
# Issue #123 in progresscd ../worktrees/feature/123-add-caching/# Urgent bug comes in!# Just switch directoriescd ../worktrees/feature/456-fix-auth/# Work on bug...# Return to #123 anytimecd ../worktrees/feature/123-add-caching/# Everything is exactly as you left itHow Sequant Uses Worktrees
Section titled “How Sequant Uses Worktrees”Creation
Section titled “Creation”When /exec runs, it creates a worktree:
# Automatically called by /exec./scripts/dev/new-feature.sh 123This:
- Fetches issue details from GitHub
- Creates branch:
feature/123-issue-title-slug - Creates worktree in:
../worktrees/feature/123-issue-title-slug/ - Installs dependencies
- Copies environment files
Location
Section titled “Location”Worktrees are created as siblings to your main repo:
~/projects/├── my-app/ # Main repo└── worktrees/ └── feature/ ├── 123-add-caching/ # Issue #123 ├── 124-fix-auth/ # Issue #124 └── 125-update-ui/ # Issue #125Cleanup
Section titled “Cleanup”After merging a PR, clean up the worktree:
# Manual cleanup./scripts/dev/cleanup-worktree.sh feature/123-add-caching
# Or let /clean handle it/cleanWorking in Worktrees
Section titled “Working in Worktrees”Navigate to Worktree
Section titled “Navigate to Worktree”# Find worktreesgit worktree list
# Output:# /Users/you/projects/my-app 2d22744 [main]# /Users/you/projects/worktrees/feature/123... abc1234 [feature/123-...]
# Navigatecd ../worktrees/feature/123-add-caching/Running Commands
Section titled “Running Commands”Run all commands from within the worktree:
# In worktree directorynpm testnpm run buildgit statusgit commit -m "feat: add caching"Pushing Changes
Section titled “Pushing Changes”Push from the worktree:
# In worktreegit push -u origin feature/123-add-caching
# Create PRgh pr create --fillBenefits
Section titled “Benefits”Clean Main Branch
Section titled “Clean Main Branch”Your main branch is never polluted with work-in-progress:
cd ~/projects/my-appgit status# On branch main# nothing to commit, working tree cleanParallel Work
Section titled “Parallel Work”Work on multiple issues simultaneously:
# Terminal 1: Issue #123cd ../worktrees/feature/123-add-caching/npm run dev
# Terminal 2: Issue #124cd ../worktrees/feature/124-fix-auth/npm test
# Both running independentlySafe Experimentation
Section titled “Safe Experimentation”Experiment without fear:
# In worktree# Try something crazy...rm -rf src/# Oops!
# Just delete the worktree and start overcd ..rm -rf feature/123-add-caching/git worktree prune/exec 123 # Fresh startContext Preservation
Section titled “Context Preservation”Return to any issue with full context:
- IDE state (if using workspace per worktree)
- Terminal history
- Uncommitted changes
- Development server state
Safety Safeguards
Section titled “Safety Safeguards”Sequant includes automatic safeguards to prevent accidental work loss.
Hard Reset Protection
Section titled “Hard Reset Protection”The pre-tool hook blocks git reset --hard when unpushed commits exist on main:
# This will be blocked if you have unpushed commits on maingit reset --hard origin/main# HOOK_BLOCKED: 3 unpushed commit(s) on main would be lost# Push first: git push origin main# Or stash: git stashWhy this matters: Work can be permanently lost when git reset --hard runs before changes are pushed. This safeguard prevents accidental data loss during sync operations.
To bypass (if intentional): Run the command directly in your terminal (outside Claude Code) where hooks don’t apply.
Main Branch Protection
Section titled “Main Branch Protection”The /exec skill refuses to implement directly on main/master branch:
# Check your branch before implementinggit rev-parse --abbrev-ref HEAD# If on 'main' - create a worktree first!./scripts/dev/new-feature.sh <issue-number>Why this matters:
- Work on main is vulnerable to sync operations
- No branch means no recovery via reflog
- Worktrees provide isolated, recoverable work environments
Hook Log
Section titled “Hook Log”All blocked operations are logged for debugging:
# View blocked operationscat /tmp/claude-hook.log
# View quality warningscat /tmp/claude-quality.logCommon Operations
Section titled “Common Operations”List Worktrees
Section titled “List Worktrees”git worktree listRemove a Worktree
Section titled “Remove a Worktree”# Remove worktree directoryrm -rf ../worktrees/feature/123-add-caching/
# Prune the Git referencegit worktree prune
# Delete the branch (optional)git branch -D feature/123-add-cachingClean Up Stale Worktrees
Section titled “Clean Up Stale Worktrees”# Remove worktrees for merged branches/cleanTroubleshooting
Section titled “Troubleshooting””fatal: is already checked out”
Section titled “”fatal: is already checked out””This happens when trying to check out a branch that’s in a worktree:
# Find which worktree has the branchgit worktree list | grep branch-name
# Remove that worktree firstgit worktree remove ../worktrees/feature/branch-nameDisk Space
Section titled “Disk Space”Worktrees share .git but duplicate working files. Monitor disk usage:
# Check sizedu -sh ../worktrees/feature/*
# Clean up after merging/cleanDependencies Out of Sync
Section titled “Dependencies Out of Sync”If dependencies differ between worktrees:
# In each worktreerm -rf node_modulesnpm install