Manage git worktrees (--list default, --status, --review, --merge, --discard)
Manages git worktrees for reviewing, merging, or discarding feature changes safely.
/plugin marketplace add akaszubski/autonomous-dev/plugin install autonomous-dev@autonomous-devpython3 ~/.claude/lib/worktree_command.py "$@"
Safe feature isolation with git worktrees for review/merge/discard workflow
The /worktree command provides a complete workflow for managing git worktrees created by the autonomous development pipeline. It enables reviewing changes, merging to main branch, or discarding unwanted work - all without affecting your main working directory.
# List all worktrees (default mode)
/worktree # Shows all active worktrees
/worktree --list # Explicit list mode
# Show detailed status
/worktree --status my-feature # Commits ahead/behind, uncommitted changes
# Interactive review (diff + approve/reject)
/worktree --review my-feature # Shows diff, prompts for merge approval
# Merge to target branch
/worktree --merge my-feature # Merges feature to master
# Discard worktree
/worktree --discard my-feature # Deletes worktree with confirmation
Time: 5-30 seconds (depends on mode) Interactive: Review and discard modes require confirmation Safe Operations: All destructive operations require explicit approval
Review workflow:
Isolation benefits:
Typical workflow:
/auto-implement)/worktree --review my-feature)/worktree --discard my-feature)--list) - DEFAULTShows all active worktrees with status indicators.
What it does:
When to use:
Example:
/worktree
/worktree --list
Output:
Feature Branch Status
------------------------------------------------------------
feature-auth feature/feature-auth clean
feature-logging feature/feature-logging dirty
hotfix-123 hotfix/hotfix-123 active
Status indicators:
clean - No uncommitted changes, ready to mergedirty - Has uncommitted changesactive - Currently checked outstale - Directory doesn't exist (orphaned)detached - Detached HEAD state--status FEATURE)Shows detailed information for a specific worktree.
What it does:
When to use:
Example:
/worktree --status feature-auth
Output:
Worktree Status: feature-auth
============================================================
Path: /Users/dev/project/.worktrees/feature-auth
Branch: feature/feature-auth
Status: dirty
Target Branch: master
Commits Ahead: 5
Commits Behind: 2
Uncommitted Changes (3 files):
- auth/models.py
- auth/tests.py
- README.md
Understanding output:
--review FEATURE)Interactive diff review with approve/reject workflow.
What it does:
When to use:
Example:
/worktree --review feature-auth
Output:
Diff for worktree: feature-auth
============================================================
diff --git a/auth/models.py b/auth/models.py
index 1234567..89abcde 100644
--- a/auth/models.py
+++ b/auth/models.py
@@ -10,6 +10,12 @@ class User(Model):
email = CharField()
+ def authenticate(self, password):
+ """Authenticate user with password."""
+ return check_password(password, self.password_hash)
+
[... more diff output ...]
============================================================
Approve or reject changes? [approve/reject]: approve
✓ Successfully merged 12 files
Interactive prompts:
--merge FEATURE)Directly merge worktree to target branch without review.
What it does:
When to use:
Example:
/worktree --merge feature-auth
Success output:
✓ Successfully merged 12 files
Merged files:
- auth/models.py
- auth/views.py
- auth/tests.py
- auth/__init__.py
- docs/authentication.md
- README.md
... and 6 more
Conflict output:
✗ Merge failed: Merge conflict detected
Conflicting files:
- auth/models.py
- auth/views.py
Handling conflicts:
git add <files>git commit/worktree --merge feature-authEnvironment integration:
AUTO_GIT_ENABLED environment variable--merge FEATURE --ai-merge)Merge worktree with automatic AI-powered conflict resolution.
What it does:
When to use:
Requirements:
Example:
# Merge with AI conflict resolution enabled
/worktree --merge feature-auth --ai-merge
# Without --ai-merge flag (manual resolution)
/worktree --merge feature-auth
Three-Tier Resolution Strategy:
The AI merger uses an intelligent three-tier escalation strategy:
Tier 1 (Auto-Merge): Trivial conflicts resolved instantly
Tier 2 (Conflict-Only): AI analyzes conflict blocks
Tier 3 (Full-File): Comprehensive context analysis
Output with AI resolution:
Merge detected conflicts in: auth/models.py
Attempting AI resolution...
Tier 1 (Auto-Merge): No trivial conflicts found
Tier 2 (Conflict-Only): Analyzing conflict blocks...
Conflict 1 (lines 42-58):
Confidence: 92%
Reasoning: Both sides added authentication methods. Merged by placing them sequentially.
Status: RESOLVED
Conflict 2 (lines 85-102):
Confidence: 78%
Reasoning: Import ordering conflict. Reorganized alphabetically.
Status: RESOLVED
Apply these resolutions? [yes/no]: yes
✓ All conflicts resolved with AI assistance
✓ Successfully merged 12 files
Interactive approval:
Output if confidence too low:
Conflict 1 (lines 85-102):
Confidence: 45%
Status: SKIPPED (confidence below threshold of 70%)
✗ Unable to resolve all conflicts with sufficient confidence
Manual resolution required:
1. Resolve conflicting files manually
2. Stage changes: git add <files>
3. Complete merge: git commit
4. Or run: /worktree --merge feature-auth (without --ai-merge)
Error handling:
Performance comparison:
| Scenario | Without --ai-merge | With --ai-merge |
|---|---|---|
| No conflicts | 2 seconds | 2 seconds (no AI overhead) |
| Single simple conflict | 5 minutes (manual) | 10 seconds (Tier 1-2) |
| Multiple conflicts | 15+ minutes (manual) | 30 seconds (Tier 2) |
| Complex conflict | 20+ minutes (manual) | 45 seconds (Tier 3) |
Integration with batch workflows:
# Batch merge multiple features with AI resolution
for feature in feature-1 feature-2 feature-3; do
/worktree --merge "$feature" --ai-merge
done
Cost estimation:
Security:
Known limitations:
--discard FEATURE)Delete worktree with confirmation prompt.
What it does:
When to use:
Example:
/worktree --discard feature-auth
Output with uncommitted changes:
⚠ Warning: Worktree 'feature-auth' has uncommitted changes:
- auth/models.py
- auth/tests.py
- README.md
These changes will be lost if you continue.
Are you sure you want to discard worktree 'feature-auth'? [yes/no]: yes
✓ Worktree 'feature-auth' discarded successfully
Output without changes:
Are you sure you want to discard worktree 'feature-auth'? [yes/no]: yes
✓ Worktree 'feature-auth' discarded successfully
Safety features:
The /worktree command integrates seamlessly with the autonomous development workflow:
# Step 1: Develop feature in worktree
/auto-implement #123 --worktree
# Feature is developed in isolated worktree
# Main branch stays clean during development
# Step 2: Review changes
/worktree --review feature-123
# Shows all changes, prompts for approval
# If approved → automatically merges
# If rejected → can iterate in worktree
# Step 3: Clean up
/worktree --discard feature-123
# Removes worktree after merge
Isolation:
Safety:
Productivity:
All worktree operations include security validation:
Security requirements:
Cause: Feature name doesn't match any worktree Fix: List worktrees to see available names
# List all worktrees
/worktree
# Check exact name
/worktree --status feature-auth # Use exact name from list
Cause: Feature branch conflicts with target branch Fix: Resolve conflicts manually
# Option 1: Fix in worktree
cd .worktrees/feature-auth
vim auth/models.py # Fix conflicts
git add auth/models.py
git commit -m "Resolve conflicts"
# Then retry merge
/worktree --merge feature-auth
# Option 2: Discard and start over
/worktree --discard feature-auth
Cause: Modified files not committed Fix: Commit or discard changes
# Option 1: Commit changes
cd .worktrees/feature-auth
git add .
git commit -m "Save work"
# Option 2: Discard changes
/worktree --discard feature-auth # Will warn and confirm
Cause: File in use or insufficient permissions Fix: Close editors and ensure permissions
# Close any editors with files from worktree open
# Check permissions
ls -la .worktrees/feature-auth
# If needed, fix permissions
chmod -R u+w .worktrees/feature-auth
# Retry discard
/worktree --discard feature-auth
# List features in progress
/worktree
# Check status of specific feature
/worktree --status feature-auth
# Review and approve
/worktree --review feature-auth
# Shows diff, approve to merge
# Clean up after merge
/worktree --discard feature-auth
# Start multiple features
/auto-implement #123 --worktree # feature-123
/auto-implement #124 --worktree # feature-124
/auto-implement #125 --worktree # feature-125
# Check all features
/worktree
# Merge ready features
/worktree --merge feature-123
/worktree --merge feature-124
# Discard unneeded feature
/worktree --discard feature-125
# Try experimental approach
/auto-implement "try new caching strategy" --worktree
# Review results
/worktree --review experimental-caching
# If good → approve to merge
# If bad → reject and discard
/worktree --discard experimental-caching
The /worktree command uses two core libraries:
worktree_manager.py: Low-level git worktree operations
worktree_command.py: Command-line interface
List mode: <1 second
Status mode: <2 seconds
Review mode: 5-30 seconds
Merge mode: 2-10 seconds
Discard mode: <2 seconds
Worktrees are stored in .worktrees/ directory at repository root:
project-root/
├── .git/
├── .worktrees/
│ ├── feature-auth/ # Worktree for feature-auth
│ ├── feature-logging/ # Worktree for feature-logging
│ └── hotfix-123/ # Worktree for hotfix-123
└── main-project-files...
Benefits:
/auto-implement --worktree for feature development in worktreesdocs/GIT-AUTOMATION.md for automatic commit/push/PR workflowdocs/SECURITY.md for comprehensive security documentationLast Updated: 2026-01-02
Issue: GitHub #180 - /worktree command for review/merge/discard workflow
Related: /auto-implement --worktree, git automation