Agentic Coding: Git Worktrees and Agent Skills for Parallel Workflows

From solo agent to parallel powerhouse: how Git worktrees and agent skills turn your agentic coding setup into a multi-tasking machine


When you're using agentic coding tools seriously, you've hit this wall:

  • πŸ€– Agent working on Feature A in one terminal
  • πŸ€– Need to start Feature B right now
  • πŸ’₯ Can't β€” same working directory, same files, chaos ensues

Whether you're running Claude Code in the terminal, using Cursor's Composer, or GitHub Copilot's agent mode in VS Code, the problem is identical: one working directory, one set of files, one task at a time.

That's frustrating when you're paying for AI horsepower and want to parallelise.

In this post, I'll show you how Git worktrees solve the isolation problem, how agent skills teach your AI to manage worktrees autonomously, and how the entire workflow β€” from branch creation to PR β€” can be streamlined across multiple parallel sessions.

πŸ’‘ This is Part 4 in my Context Engineering series. In Part 1, we covered the four pillars of context engineering. In Part 2, we introduced agent skills as portable capabilities. In Part 3, we argued why AI-powered teams need lean methodology over Scrum ceremonies. Now we put skills to work.


🌳 Git Worktrees: The Parallel Sessions Solution

Git worktrees let you check out multiple branches from the same repository into separate directories. Each worktree has its own working copy with isolated files while sharing the same Git history and .git directory. Unlike cloning the repo multiple times, worktrees are lightweight β€” they share the Git object store, refs, and hooks, so there's no duplicated history or divergent state to manage.

# Create a new worktree with a new branch
git worktree add ../project-feature-auth -b feature/authentication

# Create a worktree from an existing branch
git worktree add ../project-hotfix-123 hotfix/critical-bug-123

# List all your worktrees
git worktree list

# Remove when done
git worktree remove ../project-feature-auth  

Why this matters for agentic coding:

Single Directory Git Worktrees
One agent at a time Multiple agents in parallel
Context switching = stash/commit/switch No context switching required
Agents can step on each other's changes Complete file isolation
Wait for task completion Work on urgent fix while feature progresses

Each worktree is a fresh checkout. Depending on your stack, you'll need to install dependencies β€” pnpm install, uv sync, bundle install, etc. That's a small price for having three AI agents working simultaneously without stepping on each other.

Claude Code's own documentation recommends exactly this pattern for running parallel sessions. But the docs stop at the manual git worktree commands β€” what if we could teach the agent to handle worktree management for us?


πŸ› οΈ Agent Skills: Teaching Your AI Git Worktrees

In Part 2 of this series, I introduced agent skills β€” folders of instructions, scripts, and resources that agents can discover and use. Skills are an emerging convention adopted by Claude Code, Cursor, VS Code, GitHub, Goose, and others. The idea is simple: you drop a skill folder into your project, and the agent automatically discovers it and knows when to use it β€” no manual configuration required.

Here's the thing: you could teach your agent the git worktree commands every session. Or you could teach it once and have it just know how to manage worktrees.

That's exactly what I built: a git-worktree skill that gives Claude Code (or any skill-aware agent) full worktree management capabilities.

The Skill Structure

.claude/skills/git-worktree/
β”œβ”€β”€ SKILL.md          # Instructions the agent reads
└── scripts/
    └── worktree.py   # The actual tooling

The SKILL.md tells the agent what the skill does and β€” critically β€” when to activate. The description field acts as a trigger: when you ask something that matches, the agent discovers and loads the skill automatically:

---
name: git-worktree  
description: Git worktree management for parallel development workflows.  
  Use when the user wants to work on multiple branches simultaneously
  without stashing, create isolated environments for features/bugfixes,
  or manage worktrees (create, list, remove, prune). Triggers on
  requests like "create a worktree", "work on branch X in parallel",
  "set up a new feature branch environment".
---

The Python script handles the heavy lifting β€” creating worktrees, auto-detecting package managers, installing dependencies, and even opening your preferred editor:

# Auto-detects and installs dependencies for any stack
def install_dependencies(path: Path) -> None:  
    if (path / "package-lock.json").exists():
        subprocess.run(["npm", "ci"], cwd=path, check=False)
    elif (path / "pnpm-lock.yaml").exists():
        subprocess.run(["pnpm", "install", "--frozen-lockfile"], cwd=path, check=False)
    elif (path / "uv.lock").exists():
        subprocess.run(["uv", "sync"], cwd=path, check=False)
    elif (path / "go.mod").exists():
        subprocess.run(["go", "mod", "download"], cwd=path, check=False)
    # ... also supports yarn, bun, poetry, pipenv, bundler, cargo

Quick Reference

These are the commands the agent runs under the hood. You don't need to type them β€” just describe what you want in natural language and the skill handles the rest.

Task Command
Create worktree python scripts/worktree.py create <branch>
Create + install deps python scripts/worktree.py create <branch> -i
Create + open editor python scripts/worktree.py create <branch> -e code
List worktrees python scripts/worktree.py list
Remove worktree python scripts/worktree.py remove <path>
Prune stale refs python scripts/worktree.py prune

Supported editors: VS Code, Cursor, IntelliJ IDEA, WebStorm, PyCharm, Zed, Sublime Text, Vim, Neovim.


⚑ The Skill in Action

Here's what a parallel agentic workflow looks like with the skill installed.

Scenario: Feature work + urgent hotfix

You're halfway through a feature when a critical bug lands. Instead of stashing or committing half-finished work:

# Terminal 1: You're working on the feature
claude  
> "Create a worktree for fix/critical-bug-123 from main, install deps"

# The agent recognises the request, activates the git-worktree skill,
# and runs the script:
# βœ“ Created worktree at ../project-fix/critical-bug-123
# βœ“ New branch 'fix/critical-bug-123' from 'main'
# βœ“ Running pnpm install --frozen-lockfile...
# βœ“ Worktree ready: ../project-fix/critical-bug-123
# Terminal 2: Open a new Claude Code session in the hotfix worktree
cd ../project-fix/critical-bug-123  
claude  
> "Fix the null pointer in the payment handler"
# Agent works in complete isolation from your feature branch
# Terminal 1: Meanwhile, your feature work continues uninterrupted
> "Continue implementing the user auth flow"

Scenario: Reviewing a PR without context switching

> "Create a worktree from origin/feat/someone-elses-work for code review"

# Agent:
# βœ“ Created worktree at ../project-feat/someone-elses-work
# βœ“ Using existing branch 'feat/someone-elses-work'
# βœ“ Worktree ready

No stashing. No committing half-finished work. No branch juggling. Each agent gets its own isolated directory, its own dependencies, its own context.


πŸš€ The Full Loop: Commit Commands Plugin

Git worktrees handle the beginning of the workflow β€” creating isolated environments. But what about the end? Committing, pushing, and opening a PR.

This is where Claude Code's commit-commands plugin completes the loop.

A quick distinction: skills teach the agent domain knowledge (like worktree management) and are activated automatically when relevant, while plugins are installable packages that bundle slash commands, hooks, and other extensions. You install plugins from Claude Code's marketplace:

# Browse available plugins
> /plugin

# Or install directly from the official marketplace
> /plugin install commit-commands@claude-plugins-official

Plugins are namespaced, so the commit-commands plugin provides commands like /commit-commands:commit. For details on the plugin system, see the Claude Code plugins documentation.

The commit-commands plugin provides three slash commands that work beautifully in tandem with the worktree skill:

/commit-commands:commit β€” Context-Aware Commits

> /commit-commands:commit

# Claude will:
# - Review staged and unstaged changes
# - Match your repo's commit message style
# - Draft an appropriate message
# - Stage and commit

The AI reads your recent commit history and generates messages that match your team's conventions. No more generic "fix stuff" commits.

/commit-commands:commit-push-pr β€” Branch to PR in One Step

This is the real power move. After finishing work in your worktree:

> /commit-commands:commit-push-pr

# Claude will:
# - Create a feature branch (if needed)
# - Commit with a meaningful message
# - Push to origin with tracking
# - Create a PR via GitHub CLI with auto-generated description
# - Return the PR URL

The PR description includes a summary of all commits in the branch (not just the latest), a test plan checklist, and proper attribution.

/commit-commands:clean_gone β€” Worktree Cleanup

After your PRs are merged and remote branches deleted, cleanup is one command:

> /commit-commands:clean_gone

# Claude will:
# - Find branches marked as [gone]
# - Remove associated worktrees
# - Delete stale local branches
# - Report what was cleaned up

The Complete Workflow

Here's the full loop in practice:

# 1. Create isolated worktree (git-worktree skill)
> "Create a worktree for feat/user-auth, install deps, open in VS Code"
# βœ“ Worktree ready: ../project-feat/user-auth

# 2. Open a new Claude Code session in the worktree
cd ../project-feat/user-auth  
claude  
> "Implement OAuth2 integration"

# 3. Work is done β€” commit and create PR (commit-commands plugin)
> /commit-commands:commit-push-pr
# βœ“ Committed: Add OAuth2 provider integration
# βœ“ Pushed to origin/feat/user-auth
# βœ“ PR #142 created: https://github.com/...

# 4. PR is reviewed, approved, and merged on GitHub
# Back in your main worktree, clean up stale branches:
> /commit-commands:clean_gone
# βœ“ Removed worktree: ../project-feat/user-auth
# βœ“ Deleted branch: feat/user-auth

From worktree creation to PR to cleanup β€” streamlined across your parallel sessions.


πŸ”„ Transferable to Other Tools

I'm showcasing this with Claude Code because it's my primary agentic tool, but the concept is transferable. The worktree workflow isn't tied to any single tool β€” it's a pattern you can bring to any agentic coding environment.

If you're using GitHub Copilot's agent mode, you can achieve the same worktree workflow with a reusable prompt. Create a file at .github/prompts/git-worktree.prompt.md:

---
description: Create and manage Git worktrees for parallel development  
tools: ['run_in_terminal', 'get_terminal_output']  
---

# Git Worktree Management

When the user asks to create a worktree, work on a branch in parallel,  
or set up an isolated environment:

1. Determine the branch name and base branch (default: main)  
2. Create a sibling directory: `git worktree add ../repo-name-branch -b <branch>`  
3. Detect and install dependencies (check for package-lock.json, pnpm-lock.yaml,  
   uv.lock, go.mod, etc.)
4. Report the worktree path so the user can open a new agent session there  

Then invoke it in Copilot's agent mode with /git-worktree.

The key difference is structural: Claude Code skills can bundle executable scripts alongside the instructions (like the worktree.py script), while Copilot reusable prompts rely on the agent generating and running commands from the prompt's instructions alone.

The key insight from Part 2 holds: agent skills and reusable prompts are two implementations of the same idea β€” teaching your AI once so you never repeat yourself.

Tool Mechanism Location
Claude Code Agent Skills + Plugins .claude/skills/
GitHub Copilot Reusable Prompts .github/prompts/
Cursor Rules / Skills .cursor/rules/

πŸ“Š Why This Matters for Agentic Workflows

The combination of Git worktrees + agent skills + commit commands creates a workflow that's more than the sum of its parts:

Traditional Agentic + Worktrees + Skills
Work on one task at a time Parallel agents on multiple tasks
Manual branch creation and naming AI-managed with dependency installation
Write commit messages manually Context-aware message generation
Copy-paste PR descriptions Auto-generated from actual changes
Manual worktree cleanup One-command cleanup of merged branches
Teach the AI every session Teach once via skills, reuse forever

πŸ’‘ The key insight: Git worktrees solve the parallelisation problem at the file system level. Agent skills solve the repetitive teaching problem at the cognitive level. Commit commands solve the Git ceremony problem at the workflow level. Together, they let you focus on directing the AI agents, not managing the infrastructure around them.


🎬 Getting Started

Prerequisites: Claude Code installed and authenticated, Python 3.10+, and GitHub CLI (gh) installed and authenticated (needed for PR creation).

1. Add the git-worktree skill to your project

Copy the skill into your project's .claude/skills/ directory. You can grab it directly from the repository:

# From your project root
mkdir -p .claude/skills/git-worktree/scripts

# Download the skill files
curl -sL https://raw.githubusercontent.com/shavo007/langchain-anthropic-pdf-support/main/.claude/skills/git-worktree/SKILL.md \  
  -o .claude/skills/git-worktree/SKILL.md

curl -sL https://raw.githubusercontent.com/shavo007/langchain-anthropic-pdf-support/main/.claude/skills/git-worktree/scripts/worktree.py \  
  -o .claude/skills/git-worktree/scripts/worktree.py

Claude Code automatically discovers skills in .claude/skills/ β€” no configuration needed.

The full skill source is at: github.com/shavo007/langchain-anthropic-pdf-support/.claude/skills/git-worktree

2. Install the commit-commands plugin

Install it from Claude Code's official marketplace:

> /plugin install commit-commands@claude-plugins-official

Once installed, /commit-commands:commit, /commit-commands:commit-push-pr, and /commit-commands:clean_gone are available in any session. See the commit-commands README for full details.

3. Create your first parallel worktree

claude  
> "Create a worktree for feat/my-first-parallel-task, install deps"

The agent will activate the skill, create a sibling directory, set up the branch, and install your project's dependencies. Then open a new terminal, cd into the worktree path the agent reports, and run claude to start a parallel session.

4. For Copilot users

Create .github/prompts/git-worktree.prompt.md in your repository using the reusable prompt example from the Copilot section above. Then invoke it in agent mode with /git-worktree.


🎯 Key Takeaways

  1. Git worktrees provide complete file isolation for running multiple agentic sessions in parallel
  2. Agent skills teach your AI worktree management once β€” no more repeating instructions
  3. The concept is transferable across tools: Claude Code skills, Copilot reusable prompts, Cursor rules
  4. Plugins like commit-commands complete the loop: from worktree creation through PR and cleanup
  5. Teach once, reuse forever β€” the core principle of context engineering applied to your Git workflow

πŸ”— Resources