Skip to content

Instantly share code, notes, and snippets.

@dipendra-sharma
Created July 9, 2025 09:10
Show Gist options
  • Select an option

  • Save dipendra-sharma/0e1b08655684228afbaeabfcaab10b9d to your computer and use it in GitHub Desktop.

Select an option

Save dipendra-sharma/0e1b08655684228afbaeabfcaab10b9d to your computer and use it in GitHub Desktop.
A Claude command that creates git worktrees in adjacent directories and automatically launches a new terminal session with Claude running. Perfect for quickly setting up isolated workspaces for different branches while maintaining your current work context.
allowed-tools description
Bash(git:*), Bash(mkdir:*), Bash(open:*), Bash(gnome-terminal:*), Bash(xterm:*), Bash(konsole:*)
Create git worktree in adjacent directory and open terminal with claude

Git Worktree Creator

Creates a git worktree in an adjacent directory structure and opens a new terminal with claude running.

Current Repository Info

  • Git root: !git rev-parse --show-toplevel 2>/dev/null || echo "Not a git repository"
  • Current branch: !git branch --show-current 2>/dev/null || echo "No current branch"
  • Git status: !git status --porcelain 2>/dev/null || echo "Not a git repository"

Your Task

Create a git worktree for branch: $ARGUMENTS

Follow these steps:

  1. Verify we're in a git repository
  2. Get the git root directory name
  3. Create adjacent directory structure: {root_dir}_worktree
  4. Create git worktree inside that directory with branch name from arguments
  5. Copy .claude directory to worktree directory
  6. Open new terminal in the worktree directory
  7. Run claude command in the new terminal

Requirements:

  • If branch doesn't exist, create it from current branch
  • Handle existing worktree directories gracefully
  • Support both macOS and Linux terminal opening
  • Auto-start claude in the new terminal session

Example usage: /worktree feature-branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment