Maksym Prokopov
Personal blog powered by a passion for technology.

Claude Code Worktree Workflow: Parallel AI Coding with Two Shell Functions

16.07.2025
Reading time: 2 min.

I work on multiple Jira tickets in parallel. Context switching used to mean stashing, branching, losing my train of thought. Two shell functions fixed that.

The idea

Git worktrees give you isolated working directories that share the same .git. Combine that with Jira API and Claude Code, and you get one-command parallel AI coding sessions.

Setup

First, store your Jira token in macOS Keychain:

security add-generic-password -a "[email protected]" -s "jira-api-token" -w "YOUR_TOKEN" -U

Then add these to your ~/.zshrc:

export JIRA_USER="[email protected]"
export JIRA_TOKEN=$(security find-generic-password -a "[email protected]" -s "jira-api-token" -w 2>/dev/null)

jwork() {
  local ticket="$1"
  local base="${2:-master}"
  local repo_root=$(git rev-parse --show-toplevel)
  local repo_name=$(basename "$repo_root")
  local worktree_dir="$(dirname "$repo_root")/${repo_name}-${ticket}"

  local description=$(curl -s -u "$JIRA_USER:$JIRA_TOKEN" \
    "https://your-org.atlassian.net/rest/api/2/issue/${ticket}?fields=summary,description" \
    | jq -r '"## \(.fields.summary)\n\n\(.fields.description // "No description")"')

  git worktree add "$worktree_dir" -b "$ticket" "$base" \
    && cd "$worktree_dir" \
    && echo "Jira ticket ${ticket}:\n${description}" | claude
}

jdone() {
  local ticket="$1"
  local repo_root=$(git rev-parse --show-toplevel)
  local repo_name=$(basename "$repo_root")
  local worktree_dir="$(dirname "$repo_root")/${repo_name}-${ticket}"

  cd "$repo_root"
  git worktree remove "$worktree_dir"
  echo "Removed worktree for $ticket"
}

Usage

jwork BETA-459          # create worktree off master, fetch Jira context, launch Claude
jwork BETA-459 develop  # worktree off a different base branch
jdone BETA-459          # clean up when done

What happens

  1. Fetches ticket summary and description from Jira API
  2. Creates a git worktree at ../repo-name-TICKET on a new branch
  3. Pipes the ticket context straight into Claude Code

Each worktree gets its own isolated branch and working directory. Your directory ends up looking like this:

~/Developer/
├── adminka-core/            # main repo (master)
├── adminka-core-BETA-459/   # worktree: feature A
├── adminka-core-BETA-460/   # worktree: feature B

Three parallel tasks. Three Claude Code sessions. Zero conflicts.

Why worktrees

All worktrees share the same .git — no cloning, no duplicated repos. Just lightweight isolation. Commits, branches, and reflog are visible across all of them.

Caveats

  • Don’t check out the same branch in two worktrees
  • If worktrees share a database, run migrations when switching context

The takeaway

Sometimes the best developer tools aren’t frameworks — they’re 30 lines of bash. Git worktrees are the perfect primitive for parallel AI coding: isolated enough to avoid conflicts, lightweight enough to spin up in seconds.