worktree

worktree is a command for Claude Code from craigcossairt/trellis. It costs 44 tokens per session (571 once invoked), scanned A, original, MIT.

A command workflow for running separate coding tasks in separate Git worktrees. A Git worktree is an additional working folder linked to the same repository, so agents can edit different branches independently.

In plain words
What is it for?
Use it when two or more independent tasks need to run at the same time, especially when they involve different files or tracker issues.
Why use it?
It prevents parallel coding sessions from changing the same checkout and helps avoid branch ownership collisions. It also explains when parallel work is likely to create merge conflicts.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/craigcossairt/trellis/worktree
Clone the repo
git clone --depth 1 https://github.com/craigcossairt/trellis

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for worktree

README.md
[![agentmods](https://agentmods.dev/badge/commands/craigcossairt/trellis/worktree.svg)](https://agentmods.dev/commands/craigcossairt/trellis/worktree)
Your own site
<a href="https://agentmods.dev/commands/craigcossairt/trellis/worktree"><img src="https://agentmods.dev/badge/commands/craigcossairt/trellis/worktree.svg" alt="Measured on agentmods" height="20"></a>
Per session 44 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 571 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00044 $0.00571
Opus 5 $0.00022 $0.00285
Sonnet 5 $0.00009 $0.00114
Haiku 4.5 $0.00004 $0.00057

Measured 4d ago against content hash 3d2cc368d1e3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

worktree scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/worktree.md · 70 lines

How it starts

The opening of the file, as written. The whole thing — 70 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Git Worktree Workflow

Run parallel agent sessions on independent tasks using git worktrees.

When to Use

  • You have 2+ independent tasks that touch different files
  • Tasks are on separate tracker issues
  • You want to multiply throughput by running parallel sessions

When NOT to Use

  • Tasks touch the same files (merge conflicts)
  • One task depends on the output of another
  • Quick single-file fixes (just do them sequentially)

Step 0: Claim the Branch

Worktrees stop two sessions sharing a checkout. They do nothing about two sessions sharing a branch, which is the collision you actually hit once more than one agent runs at a time - they all authenticate as the same git identity, so nothing tells them apart.

bin/claim-branch.sh feature/<task-name>

Exit 0 free, 1 claimed by someone else (pick another branch or coordinate), 2 could not tell. Exit 2 never means free. And a clean fast-forward is not permission - that is exactly what a collision looks like from the inside, so "it merged fine" is not evidence that nobody else was there.

Run it again before pushing to any branch you did not create.

Setup a Worktree

# From the repo root
git worktree add ../<repo>-worktree-<task-name> -b feature/<task-name>

Then open a new agent session in the worktree directory and work there.

Cleanup After Merge

git worktree remove ../<repo>-worktree-<task-name>
git branch -d feature/<task-name>
git pull origin main

Rules

  1. Claim before you branch - bin/claim-branch.sh first, every time (Step 0)
  2. Each worktree gets its own agent session - don't share sessions
  3. Only for truly independent work - different files, different features
  4. Always clean up - remove worktrees after merge to avoid stale branches
  5. Start small - try 2 parallel sessions before scaling up
  6. Main stays clean - the main worktree stays on the main branch

Tips

  • Name worktrees after the tracker issue ID
  • Each worktree has its own dependency/build cache, so install runs once per worktree
  • If you need to share changes between worktrees, commit and cherry-pick

Read the full file on GitHub · 70 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 70 lines · 44 tokens per session scan A 3d2cc368d1e3

Subscribe to this mod's changes

worktree is a command published in the GitHub repository craigcossairt/trellis (4 stars, last pushed 14d ago), licensed MIT. It adds 44 tokens to every session and 571 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other commands, from other repositories

adr-review

Run the workflow in docs/playbooks/adr-review.md. You review only — never write or rewrite the ADR for me. Check problem framing, option fairness, trade-offs and consequences, reversibility, the revisit trigger, and weak reasoning. Give pointed questions and concrete suggestions; I write the words. If it supersedes an…

ahamedzoha/atelier · 0 tokens

milestone

Produce the next build doc. Run the workflow in docs/playbooks/milestone.md: read the active mode and current phase from PROJECT.md, find the next milestone in docs/progress.md, and write docs/milestones/ . - .md in the six-part format (Concept · ADR · Guided build · Challenges · Verify · Stretch). Respect the mode …

ahamedzoha/atelier · 0 tokens

mode

Run the workflow in docs/playbooks/mode.md: read the current mode from PROJECT.md, confirm the trade-off of the target mode in one line, update the Mode field and Current mode: line in PROJECT.md, and confirm the new rules. Modes: guided (I write all code), collab (split), autopilot (you write it and teach). Full…

ahamedzoha/atelier · 0 tokens

progress

Run the workflow in docs/playbooks/progress.md: read PROJECT.md, docs/progress.md, and the actual repo (trust the repo over the doc). Locate me, name concrete progress, append a dated session-log entry, propose the single next action, and check docs/learning-debt.md for anything worth pulling in. If I seem stuck…

ahamedzoha/atelier · 0 tokens

start

Turn this freshly cloned template into my project. Run the workflow in docs/playbooks/start.md: welcome me, run a short conversational interview (idea, background, goals, mode, stack, pace), then write PROJECT.md, the design skeleton, and the roadmap in docs/progress.md, and offer to write my first milestone. Keep it…

ahamedzoha/atelier · 0 tokens

crossframe-essay

使用 CrossFrame Essay 把用户给出的主题、素材或问题写成中文批判性洞察文章。.

xi-kari/crossframe-skill · 0 tokens