Skip to content

Instantly share code, notes, and snippets.

@vpdn
Last active August 14, 2025 09:02
Show Gist options
  • Select an option

  • Save vpdn/49629c1049219a18a451cd1d4660834b to your computer and use it in GitHub Desktop.

Select an option

Save vpdn/49629c1049219a18a451cd1d4660834b to your computer and use it in GitHub Desktop.
Claude Code Worktree Command
allowed-tools argument-hint description
Bash, Read, Task
<branch-name>
Create a git worktree and open it in a new Terminal with Claude Code

Context

  • Current repository: !git rev-parse --show-toplevel 2>/dev/null || echo "Not in a git repository"
  • Existing worktrees: !git worktree list 2>/dev/null || echo "Not in a git repository"

Your task

Create a git worktree with the name provided in the arguments: $ARGUMENTS

Use the Task tool to execute all the git worktree creation and Terminal operations in a subtask to avoid cluttering the main context.

The subtask should:

  1. Verify we're in a git repository
  2. Create a worktree in a sibling directory (../branch-name)
  3. Use osascript to open a new Terminal tab with this exact AppleScript:
    tell application "Terminal"
        activate
        tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
        delay 0.5
        do script "cd /path/to/worktree && cc" in selected tab of the front window
    end tell
    
  4. The AppleScript MUST use keystroke "t" using command down to create a tab (NOT a new window)
  5. Use do script with in selected tab of the front window to run commands in the new tab

Requirements:

  • The worktree name should be: $ARGUMENTS
  • Create the worktree as a sibling to the current repository root
  • IMPORTANT: Use the exact AppleScript pattern shown above to create a TAB, not a window
  • The AppleScript must use keystroke "t" using command down to open a new tab
  • Use do script ... in selected tab of the front window to run commands in the new tab
  • Start Claude Code automatically in the new Terminal tab
  • Execute all operations in a subtask using the Task tool to keep the main context clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment