swarm: Command for Claude Code

.claude/commands/guard.md

guard is a command for Claude Code from swarm-ai-research/swarm. It costs 0 tokens per session (1,199 once invoked), scanned A, original, MIT.

A safety-check command for confirming the current branch and detecting files changed by another Claude Code worktree session before risky work begins.

In plain words
What is it for?
Use it to verify a branch, check selected files for concurrent edits, or do both before changing shared or potentially destructive files.
Why use it?
It reduces the chance of modifying the wrong branch or overwriting another session’s changes.

Command for Claude Code

Written for Claude Code: installed under .claude/. Also seen: mentions Claude Code.

This is swarm-ai-research/swarm's own configuration. It tells Claude Code how to work on swarm itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything swarm configures →

Reuse

Borrowing it

Nothing to install: this file belongs to swarm-ai-research/swarm. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/swarm-ai-research/swarm/main/.claude/commands/guard.md
Clone the repo
git clone --depth 1 https://github.com/swarm-ai-research/swarm

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 guard

README.md
[![agentmods](https://agentmods.dev/badge/commands/swarm-ai-research/swarm/guard.svg)](https://agentmods.dev/commands/swarm-ai-research/swarm/guard)
Your own site
<a href="https://agentmods.dev/commands/swarm-ai-research/swarm/guard"><img src="https://agentmods.dev/badge/commands/swarm-ai-research/swarm/guard.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,199 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00000 $0.01199
Opus 5 $0.00000 $0.00600
Sonnet 5 $0.00000 $0.00240
Haiku 4.5 $0.00000 $0.00120

Measured 8d ago against content hash ab47d989d651, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

guard 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 8d 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/guard.md · 127 lines

How it starts

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

/guard

Verify branch identity and detect file conflicts from concurrent Claude Code worktree sessions before starting destructive work — use when opening a worktree pane, before modifying shared files, or when you suspect another session may have touched the same paths. Use --files mode to check specific files; omit for branch-only verification. Consolidates the former /branch_guard and /session_guard commands. Distinct from /preflight (pre-commit lint/test checks) and /healthcheck (code health after external changes).

Usage

/guard [expected-branch]
/guard --files <file1> [file2] ...
/guard [expected-branch] --files <file1> [file2] ...

Examples:

  • /guard (show current branch and context)
  • /guard main (verify you're on main)
  • /guard feat/isometric-viz (verify you're on the expected branch)
  • /guard --files swarm/core/orchestrator.py (check if files were modified by other sessions)
  • /guard main --files swarm/core/orchestrator.py swarm/logging/event_log.py (both checks)

Argument parsing

  • --files <file1> [file2] ...: Check listed files for concurrent modification (session guard mode)
  • Any non-flag token that doesn't look like a file path: treated as expected branch name
  • If neither branch nor --files is given: show current branch info (default)

Branch check (default, or when branch name is given)

1) Check current branch

  • Run git branch --show-current.
  • Run git status --short to show working tree state.

2) Compare against expected

  • If an expected branch is specified and the current branch doesn't match:
    • Warn clearly: "WARNING: On branch <current>, expected <expected>"
    • Show uncommitted changes on current branch (if any).
    • Ask: "Switch to <expected>?" before doing anything.
  • If they match, confirm: "On correct branch: <expected>"

3) If no expected branch given

  • Show the current branch, its tracking remote, and how many commits ahead/behind.
  • Show any in-progress beads (bd list --status=in_progress) to remind what work is active.
  • This gives enough context to decide if you're in the right place.

Read the full file on GitHub · 127 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. 8d ago First seen · 127 lines · 0 tokens per session scan A ab47d989d651

Subscribe to this mod's changes

guard is a command published in the GitHub repository swarm-ai-research/swarm (41 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,199 tokens. 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.