Git worktrees + Claude Code + GitHub, unified.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ cw new feat/auth โ
โ โ
โ โ Created worktree at ../myapp__wt/feat-auth โ
โ โ Copied .env โ
โ โ Created .env.local from .env โ
โ โ Updated package.json ports (Next.js: 3001) โ
โ โ Linked .claude directory โ
โ โ Installed dependencies (pnpm) โ
โ โ Assigned port 3001 โ
โ โ Starting shell session... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Problem: Working on multiple features simultaneously with Claude Code is painful:
- Manually creating worktrees with long git commands
- Copying env files and updating ports manually
- Port conflicts when running multiple dev servers
- Figuring out which ports are free
- Opening terminals, navigating, starting Claude
- Losing track of what's where
The Solution: One command does it all:
- โ
Auto-creates
.env.localfrom.envwith correct ports - โ
Updates
package.jsonports dynamically (Next.js, Inngest, etc.) - โ No port conflicts - each worktree gets a unique port
- โ Detects Claude Code (won't launch nested sessions)
- โ Cleans up merged branches automatically
- โ Organizes worktrees in one place
brew tap smitfire/cw
brew install cwOther installation methods
curl -sL https://raw.githubusercontent.com/smitfire/cw/main/install.sh | bashgit clone https://github.com/smitfire/cw.git
cd cw && cp bin/cw ~/.local/bin/ && chmod +x ~/.local/bin/cwcw init # One-time project setup
cw new feat/my-feature # Create worktree โ Claude opens automaticallyThat's it. You're coding.
- Creates
.env.localfrom.envautomatically - Updates port numbers in both files
- Updates
package.jsondev scripts with correct ports - Handles Next.js, Inngest, and other localhost URLs
- Each worktree gets a unique port (3000, 3001, 3002...)
- Automatically configures all dev scripts
- No manual port configuration needed
- No conflicts when running multiple servers
cw prune --mergedfinds branches merged into your base branch- Shows PR status before removal
- Interactive or automatic (
--yes) removal - Frees up ports and cleans up directories
- Auto-detects when running inside Claude Code
- Won't launch nested sessions
- Safe for Claude to use
cwcommands directly - Shares
.claudeconfig via symlink
Work on multiple features without stashing or losing context:
# Start auth feature
cw new feat/auth
# Claude opens, you implement OAuth...
# Urgent bug? Open another worktree
cw new fix/critical-bug
# Fix it in isolation, no context switching
# Back to auth
cw go feat/auth
# Everything's exactly where you left itReview a PR without disrupting your work:
# You're deep in feat/dashboard
# Teammate asks for review on feat/api
cw new feat/api # Opens their branch
# Review, test, approve
cw go feat/dashboard # Back to your work instantlyTry risky changes without fear:
cw new experiment/new-arch --from main
# Go wild with refactoring
# If it works: cw pr
# If it doesn't: cw rm experiment/new-arch
# Main branch never touchedSee everything at a glance:
$ cw status
โญโโโโโโโโโโโโโโโโโโโโ WORKTREES โโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ main โ Clean โ
โ feat/auth โ 3 files changed โ Port 3001 โ
โ feat/api โ PR #42 (Draft) โ Port 3002 โ
โ fix/bug-123 โ 1 ahead โ Port 3003 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโโโโโโโโโโโโโโโโโโโ YOUR PRS โโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ #42 feat/api Draft Add REST endpoints โ
โ #38 feat/search Review Full-text search โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
| Command | What it does |
|---|---|
cw new <branch> |
Create worktree + auto-configure ports |
cw go <branch> |
Jump to existing worktree |
cw ls |
List all worktrees with ports & PRs |
cw rm <branch> |
Remove a worktree |
cw pr |
Create GitHub PR |
cw prs |
List your open PRs |
cw sync |
Rebase on base branch |
cw status |
Full dashboard |
cw ports |
Show port assignments |
cw prune |
Clean up stale worktrees |
cw prune --merged |
Remove worktrees for merged branches |
cw prune --merged --yes |
Auto-remove without prompts |
cw new feat/auth --from main # Branch from specific base
cw new feat/auth --no-install # Skip package installation
cw new feat/auth --no-claude # Don't auto-start Claude
cw pr --draft # Create draft PR
cw pr -t "Title" -b "Body" # Set PR title and body
cw prune --merged # Interactive cleanup of merged branches
cw prune --merged --yes # Auto-remove all merged branchesRun cw init to create .worktreerc:
# .worktreerc
BASE_PORT=3000 # Dev server ports start here
BASE_BRANCH=dev # Default PR target
AUTO_CLAUDE=true # Auto-start Claude in new tabs
ENV_FILES=.env .env.local # Copy these to new worktrees
SYMLINK_DIRS=.claude # Symlink these directoriesEach worktree gets a unique port automatically assigned and configured:
main repo โ 3000 (BASE_PORT)
feat/auth โ 3001
feat/api โ 3002
fix/bug-123 โ 3003
What gets updated automatically:
.env- Copied with port updated.env.local- Created from.envwith correct portpackage.json- Dev scripts updated (e.g.,next dev -p 3001)- Inngest URLs - Updated to use correct localhost port
Result: Run pnpm dev in multiple worktrees simultaneously - no conflicts!
Run cw ports to see all port assignments.
| Terminal | Auto-open tabs | Auto-start Claude |
|---|---|---|
| Warp | โ | โ |
| iTerm2 | โ | โ |
| Terminal.app | โ | โ |
| Kitty | โ | โ |
| GNOME Terminal | โ | โ |
| Other | โ (prints path) | โ |
your-project/ # Main repo (stay clean)
your-project__wt/ # All worktrees live here
โโโ feat-auth/ # feat/auth branch
โ โโโ .env # Copied from main
โ โโโ .claude -> ../../.claude # Symlinked
โ โโโ ...
โโโ feat-api/
โโโ fix-bug-123/
- Worktrees share git history (fast creation)
- Each has its own working directory (no conflicts)
- Env files copied, config directories symlinked
- Git 2.15+ (for worktree features)
- GitHub CLI (
gh) - for PR features - Claude Code (
claude) - optional, for auto-start
# Install dependencies
brew install gh
gh auth loginNaming Convention: Use prefixes for organization
feat/ # New features
fix/ # Bug fixes
exp/ # Experiments
refactor/# RefactoringQuick Cleanup: Remove all merged worktrees
cw prune --merged --yes # Auto-remove merged branches
cw prune --merged # Interactive (asks y/N for each)
cw prune # Only stale/orphaned worktreesCheck What's Open:
cw ls # Quick list
cw status # Full dashboardPRs welcome! Please open an issue first to discuss changes.
git clone https://github.com/smitfire/cw.git
cd cw
# Tests use BATS
brew install bats-core
bats tests/MIT