worktree-check

A command that reports the current Git worktree, branch, task file, and relationship to the main branch. A worktree is a separate working directory connected to the same Git repository.

In plain words
What is it for?
Use it to inspect worktree setup, branch naming, commits ahead of main, and the contents of .worktree-task.md.
Why use it?
It quickly shows whether you are working in the intended directory and branch, and whether a task description is present. This reduces confusion before starting work.

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/davila7/claude-code-templates/worktree-check
Clone the repo
git clone --depth 1 https://github.com/davila7/claude-code-templates

Made for: Claude Code.

Per session 11 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 504 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.00011 $0.00504
Opus 5 $0.00005 $0.00252
Sonnet 5 $0.00002 $0.00101
Haiku 4.5 $0.00001 $0.00050

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

Security

Grade A, and why

worktree-check 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 3d 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-check.md · 60 lines

What it actually says

Worktree Status Check

Verify the current worktree environment and show task details.

Instructions

You are inside a worktree (or the main repo). Gather and display the current status clearly.

Step 1: Detect Worktree

  1. Get the current directory: pwd
  2. List all worktrees: git worktree list
  3. Determine if the current directory is a worktree (not the main working tree). The main working tree is listed first in git worktree list output — if the current path matches the first entry, this is the main repo, not a worktree.

If this is not a worktree, inform the user:

You're in the main repository, not a worktree. Use /worktree-init to create worktrees.

Then list any existing worktrees and exit.

Step 2: Show Branch Info

  1. Get current branch: git branch --show-current
  2. Verify it follows the claude/*, claude-daniel/*, or review/* naming convention
  3. Show how many commits ahead of origin/main: git rev-list --count origin/main..HEAD

Step 3: Read Task

  1. Check if .worktree-task.md exists in the worktree root
  2. If it exists, read and display its contents
  3. If it doesn't exist, note that no task file was found (may have been created manually)

Step 4: Show Working Status

Run and display:

  1. git status --short — show modified, staged, and untracked files
  2. git diff --stat — show a summary of unstaged changes

Step 5: Display Summary

Present a clean summary:

Worktree Status
──────────────────────────────────
Branch:    claude/<name>
Task:      <task description from .worktree-task.md>
Commits:   <N> ahead of main
Modified:  <N> files
Staged:    <N> files
Untracked: <N> files
──────────────────────────────────

If there are changes ready to deliver, suggest: "Run /worktree-deliver when you're ready to commit, push, and create a PR."

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. 3d ago First seen · 60 lines · 11 tokens per session scan A 95dfad3d0a50

Subscribe to this mod's changes

worktree-check is a command published in the GitHub repository davila7/claude-code-templates (30,476 stars, last pushed yesterday), licensed MIT. It adds 11 tokens to every session and 504 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.