Skip to content

Worktree Isolation

Sequant uses Git worktrees to isolate each issue’s work, keeping your main branch clean.

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/
└── ...

Without isolation, half-finished work pollutes your main branch:

Terminal window
# Traditional workflow
git checkout -b feature/123
# Work on feature...
# Urgent bug comes in!
git stash
git checkout main
git checkout -b hotfix/456
# Fix bug...
# Where was I with feature/123?
git checkout feature/123
git stash pop
# Conflicts? Lost context?

With Sequant, each issue gets its own directory:

Terminal window
# Issue #123 in progress
cd ../worktrees/feature/123-add-caching/
# Urgent bug comes in!
# Just switch directories
cd ../worktrees/feature/456-fix-auth/
# Work on bug...
# Return to #123 anytime
cd ../worktrees/feature/123-add-caching/
# Everything is exactly as you left it

When /exec runs, it creates a worktree:

Terminal window
# Automatically called by /exec
./scripts/dev/new-feature.sh 123

This:

  1. Fetches issue details from GitHub
  2. Creates branch: feature/123-issue-title-slug
  3. Creates worktree in: ../worktrees/feature/123-issue-title-slug/
  4. Installs dependencies
  5. Copies environment files

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 #125

After merging a PR, clean up the worktree:

Terminal window
# Manual cleanup
./scripts/dev/cleanup-worktree.sh feature/123-add-caching
# Or let /clean handle it
/clean
Terminal window
# Find worktrees
git worktree list
# Output:
# /Users/you/projects/my-app 2d22744 [main]
# /Users/you/projects/worktrees/feature/123... abc1234 [feature/123-...]
# Navigate
cd ../worktrees/feature/123-add-caching/

Run all commands from within the worktree:

Terminal window
# In worktree directory
npm test
npm run build
git status
git commit -m "feat: add caching"

Push from the worktree:

Terminal window
# In worktree
git push -u origin feature/123-add-caching
# Create PR
gh pr create --fill

Your main branch is never polluted with work-in-progress:

Terminal window
cd ~/projects/my-app
git status
# On branch main
# nothing to commit, working tree clean

Work on multiple issues simultaneously:

Terminal window
# Terminal 1: Issue #123
cd ../worktrees/feature/123-add-caching/
npm run dev
# Terminal 2: Issue #124
cd ../worktrees/feature/124-fix-auth/
npm test
# Both running independently

Experiment without fear:

Terminal window
# In worktree
# Try something crazy...
rm -rf src/
# Oops!
# Just delete the worktree and start over
cd ..
rm -rf feature/123-add-caching/
git worktree prune
/exec 123 # Fresh start

Return to any issue with full context:

  • IDE state (if using workspace per worktree)
  • Terminal history
  • Uncommitted changes
  • Development server state

Sequant includes automatic safeguards to prevent accidental work loss.

The pre-tool hook blocks git reset --hard when unpushed commits exist on main:

Terminal window
# This will be blocked if you have unpushed commits on main
git reset --hard origin/main
# HOOK_BLOCKED: 3 unpushed commit(s) on main would be lost
# Push first: git push origin main
# Or stash: git stash

Why 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.

The /exec skill refuses to implement directly on main/master branch:

Terminal window
# Check your branch before implementing
git 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

All blocked operations are logged for debugging:

Terminal window
# View blocked operations
cat /tmp/claude-hook.log
# View quality warnings
cat /tmp/claude-quality.log
Terminal window
git worktree list
Terminal window
# Remove worktree directory
rm -rf ../worktrees/feature/123-add-caching/
# Prune the Git reference
git worktree prune
# Delete the branch (optional)
git branch -D feature/123-add-caching
Terminal window
# Remove worktrees for merged branches
/clean

This happens when trying to check out a branch that’s in a worktree:

Terminal window
# Find which worktree has the branch
git worktree list | grep branch-name
# Remove that worktree first
git worktree remove ../worktrees/feature/branch-name

Worktrees share .git but duplicate working files. Monitor disk usage:

Terminal window
# Check size
du -sh ../worktrees/feature/*
# Clean up after merging
/clean

If dependencies differ between worktrees:

Terminal window
# In each worktree
rm -rf node_modules
npm install