The user wants to work on a branch in a separate worktree. The argument is provided as: $ARGUMENTS.
If no argument was provided, ask the user which branch or issue they want.
Follow these steps:
- •
Fetch latest from remote by running
git fetch origin. - •
Determine the branch name:
- •If the argument is an existing branch name (check with
git branch -a), use it as-is. - •If the argument is an issue number (e.g.
#82or82), generate a descriptive branch name in the format<number>-short-descriptive-kebab-case-name. Use context from the issue (fetch it withgh issue view <number>) to pick a short but descriptive name. For example, issue #82 titled "Unify not-found and unauthorized responses" could become82-unify-not-found-responses.
- •If the argument is an existing branch name (check with
- •
Determine the worktree path:
../careless-<branch-name>(relative to the repo root). For example, branchazure-session-lifetime-managementbecomes../careless-azure-session-lifetime-management. - •
Check if the worktree already exists by running
git worktree listand checking if the path is already listed. - •
Ask the user for confirmation before creating or updating the worktree. Show the branch name and worktree path and ask if they want to proceed.
- •
If the worktree does NOT exist:
- •Run
git worktree add ../careless-<branch-name> <branch-name>to create it. - •If that fails because the branch doesn't exist locally, try
git worktree add -b <branch-name> ../careless-<branch-name> origin/<branch-name>to create a local branch tracking the remote. - •If that also fails (branch doesn't exist on remote either), create a new branch from master:
git worktree add -b <branch-name> ../careless-<branch-name> origin/master. - •Tell the user what happened (checked out existing branch, or created new branch from master).
- •Run
- •
If the worktree ALREADY exists:
- •Run
git -C ../careless-<branch-name> pullto get the latest changes. - •Tell the user the worktree was already set up and latest changes have been pulled.
- •Run
- •
Tell the user how to start working there. Print a message like:
codeWorktree ready! To start Claude in the worktree, run: cd ../careless-<branch-name> && claude