refine

A command for recursively reviewing and improving an existing code branch and pull request. A pull request is a proposed code change submitted for review before it is merged.

In plain words
What is it for?
Reviewing a branch and pull request, applying refinement outcomes, coordinating the refinement workflow, and preparing the changes for delivery.
Why use it?
It helps address review findings and refine the branch through another review cycle without restarting the earlier research and approval stages.

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/dheerg/swarms/refine
Clone the repo
git clone --depth 1 https://github.com/DheerG/swarms
Per session 9 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,780 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.00009 $0.02780
Opus 5 $0.00005 $0.01390
Sonnet 5 $0.00002 $0.00556
Haiku 4.5 $0.00001 $0.00278

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

Security

Grade A, and why

refine 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.

commands/refine.md · 81 lines

How it starts

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

/swarm:refine

Recursive refinement on an existing branch and pull request. Skips Research/Converge/Approve/Execute — the team enters at Review, then Refine, then Deliver.

Pass outcomes inline (/swarm:refine <outcomes>) or run without arguments to be prompted.

Read ${CLAUDE_PLUGIN_ROOT}/commands/launch.md for Step 0 (pre-flight), Step 1 (invoke swarm:workflow-rules — the governance spec), Steps 8a–8e (team creation, member spawning, pulse setup), and the Universal rules that apply across all modes in Step 8f — especially the governance spec's Live-team gate prompts rule (the AFK-timeout / durable plain-text-restatement recovery), which governs this command's decision gates (Finish, ship-approval) too. This command replaces Steps 2–7 and overrides Step 8f's phase arc — not those universal rules.

No lead research unless enabled. The pre-flight reads below are housekeeping, not research — they run unconditionally (analogous to launch.md's ship-definition detection). All other research is delegated to teammates.

Settings

  • Mode: Code
  • Outcomes question: "What outcomes was this branch/PR supposed to achieve? (Describe what was meant to be working differently or better — the team will refine the work against these outcomes.)"
  • Cost tier: Ultra
  • Lead research: No
  • Roster (fixed): Principal Engineer (facilitator), Correctness Reviewer, Outcomes Reviewer, Regression Reviewer

User-Provided Context

$ARGUMENTS

Workflow

  1. Pre-flight reads. Run via Bash, capture each output as a raw string. Use the exact abort messages below — they are the user's only signal that something is wrong, so consistency matters across invocations.

    • git rev-parse --is-inside-work-tree — if not in a git repo, abort with: Not in a git repository. /swarm:refine works on a branch and pull request.
    • git branch --show-current — capture. If empty (detached HEAD), abort with: Cannot run /swarm:refine in detached HEAD state. Run "git checkout <branch-name>" to switch to a branch first. If equal to the repo's default branch (resolved via git symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null then stripping origin/), abort with: Cannot refine the default branch directly. Switch to a feature branch.
    • gh pr view --json title,body,baseRefName,url 2>/dev/null — capture PR data if present. Extract baseRefName for the diff base. If no PR exists, fall back to the repo's default branch resolved earlier via git symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null (stripped of origin/) — master, develop, or whatever the repo actually uses. Do not hardcode main. If git symbolic-ref itself returns nothing (no origin/HEAD set), abort with: Cannot determine the default branch — origin/HEAD is not set. Run "git remote set-head origin -a" or open a PR with the correct base before re-running /swarm:refine. Surface the fallback (whichever branch was resolved) explicitly in the Step 7 confirmation summary so the user can correct the base before launch.
    • git diff <base>...HEAD — capture. If empty (HEAD == base), abort with: No changes detected between <branch> and <base>. Nothing to refine. If this is unexpected, verify the diff base is correct. (substitute the actual branch and base names).
    • git diff --stat <base>...HEAD | tail -1 — capture the one-line diff stat (e.g., 12 files changed, 340 insertions(+), 45 deletions(-)) for the Step 3 confirmation summary. If the diff is empty this is moot — the empty-diff abort above fires first.

Read the full file on GitHub · 81 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 · 81 lines · 9 tokens per session scan A 41a803ea51fa

Subscribe to this mod's changes

refine is a command published in the GitHub repository DheerG/swarms (86 stars, last pushed 1mo ago), licensed MIT. It adds 9 tokens to every session and 2,780 once invoked, about $0.0000 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.