create-worktree

A command for creating or reusing an isolated Git worktree for a GitHub issue or pull request. A worktree is a separate directory connected to the same Git repository, allowing work on another branch without changing the current checkout.

In plain words
What is it for?
Use it inside an authenticated Git repository to create or reuse the worktree and branch for a specified issue or pull request, with optional environment-file copying.
Why use it?
It reduces setup mistakes and keeps issue work separate from other local changes.

Command

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/gopherguides/gopher-ai/create-worktree
Clone the repo
git clone --depth 1 https://github.com/gopherguides/gopher-ai
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 900 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.00014 $0.00900
Opus 5 $0.00007 $0.00450
Sonnet 5 $0.00003 $0.00180
Haiku 4.5 $0.00001 $0.00090

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

Security

Grade A, and why

create-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 2d 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.

plugins/go-workflow/commands/create-worktree.md · 109 lines

How it starts

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

Create Worktree for Issue or PR

If $ARGUMENTS is empty or not provided:

This command creates or reuses an isolated git worktree for working on a GitHub issue or PR.

Usage: /create-worktree <issue-or-pr-number>

Examples:

  • /create-worktree 789 — create worktree for issue #789
  • /create-worktree 42 — if #42 is a PR, resolve its linked issue and create or reuse the issue worktree

What it does: detects PR vs issue → reuses an existing standard issue worktree if found → otherwise creates ../reponame-issue-<num>-<title>/ from the default branch → creates the issue branch → optionally copies env files → registers worktree state.

Prerequisites: gh authenticated; run from inside a git repository.

Ask the user: "What issue or PR number would you like to work on?"


If $ARGUMENTS is provided:

Clear Worktree State

Clear stale worktree state so the pre-tool-use hook does not block setup commands:

"${CLAUDE_PLUGIN_ROOT}/scripts/worktree-state.sh" clear 2>/dev/null || true

Environment Files

Check whether the source repo has environment files before creating or reusing the worktree:

SOURCE_DIR="$(pwd)"
"${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" env-files --source-dir "$SOURCE_DIR"

If the output starts with ENV_FILES_FOUND=true, use AskUserQuestion: "Found environment files (may contain secrets). Copy them to the worktree?" with Yes, copy them / No, skip.

Create or Reuse Worktree

If the user chose to copy env files:

SOURCE_DIR="$(pwd)"
"${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" create "$ARGUMENTS" --source-dir "$SOURCE_DIR" --copy-env

Otherwise:

SOURCE_DIR="$(pwd)"
"${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" create "$ARGUMENTS" --source-dir "$SOURCE_DIR" --no-copy-env

The script validates input and prerequisites, detects PR vs issue, derives the standard branch and path, fetches the default branch, creates or reuses the worktree, optionally copies env files, registers state, and prints:

Read the full file on GitHub · 109 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. 2d ago First seen · 109 lines · 14 tokens per session scan A 87dbe748cb9f

Subscribe to this mod's changes

create-worktree is a command published in the GitHub repository gopherguides/gopher-ai (21 stars, last pushed 2d ago), licensed MIT. It adds 14 tokens to every session and 900 once invoked, about $0.0001 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-30.

Related

Other commands, from other repositories