Skip to content

Instantly share code, notes, and snippets.

@aviflombaum
Created July 24, 2025 14:34
Show Gist options
  • Save aviflombaum/9077e64ba42eed14a5711219fadd96c2 to your computer and use it in GitHub Desktop.
Save aviflombaum/9077e64ba42eed14a5711219fadd96c2 to your computer and use it in GitHub Desktop.
A worktree slash command for Claude Code

Create Worktree

Creates a new git worktree for a feature branch and opens it in a new terminal tab.

Usage:

  1. Set up worktrees directory

    • Default location is ../worktrees relative to project root
    • Can be customized by setting WORKTREES_DIR environment variable
  2. Create worktree with feature description

    • Pass a descriptive name for the feature branch
    • Branch name will be formatted as: YY-MM-feature-description
    • Example: worktree "add auth feature" "Build authentication system"
  3. New terminal tab opens

    • Opens worktree directory in new terminal tab
    • Any provided prompt text is displayed in the new tab
    • Use exactly osascript -e 'tell application "System Events" to keystroke "t" using command down'

Example Execution:

# Create worktree for new feature worktree "add password reset" "Implement password reset flow"

Creates:

- Branch: 24-01-add-password-reset

- Directory: ../worktrees/24-01-add-password-reset

- Opens new terminal tab in that directory

Implementation Notes:

  • Uses standard terminal commands to open new tabs

  • Maintains consistent branch naming convention

  • Keeps worktrees organized in dedicated directory

  • Do not mention the terminal app name in any osascript.

  • If not feature name is supplied, ask for a feature name first.

  • Choose descriptive feature names

  • Keep branch names consistent

  • Organize worktrees logically

  • Clean up old worktrees when no longer needed

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