b-refine

b-refine is a command for Claude Code from punt-labs/z-spec. It costs 7 tokens per session (1,362 once invoked), scanned A, a copy of b-refine-dev, MIT.

A command for the B-Method, a formal way to describe software behavior and prove that an implementation preserves it. It creates or checks a refinement, which adds concrete details to an abstract machine.

In plain words
What is it for?
Use it to generate a .ref refinement or .imp implementation from a .mch machine, or verify that a refinement correctly matches its abstract machine.
Why use it?
It helps verify that added data structures and implementation details still preserve the properties of the original specification.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the z-spec-dev plugin — 42 commands, 1 hook shipped together

Good fit Use it to generate a .ref refinement or .imp implementation from a…

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/punt-labs/z-spec/b-refine
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.

Clone the repo
git clone --depth 1 https://github.com/punt-labs/z-spec

Made for: Claude Code.

Or install z-spec-dev, the plugin that ships this one along with the rest of its 42 commands, 1 hook.

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/punt-labs/z-spec/b-refine.svg)](https://agentmods.dev/commands/punt-labs/z-spec/b-refine)
Your own site
<a href="https://agentmods.dev/commands/punt-labs/z-spec/b-refine"><img src="https://agentmods.dev/badge/commands/punt-labs/z-spec/b-refine.svg" alt="Measured on agentmods" height="20"></a>
Per session 7 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,362 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 97% copy Near-identical to another mod 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.00007 $0.01362
Opus 5 $0.00003 $0.00681
Sonnet 5 $0.00001 $0.00272
Haiku 4.5 $0.00001 $0.00136

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

Security

Grade A, and why

b-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 7d 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.

Origin

This is a copy

97% identical to b-refine-dev — 6 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

plugin/commands/b-refine.md · 195 lines

How it starts

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

/z-spec:b-refine - B Refinement

Create or verify a B refinement machine. B-Method's refinement chain (Machine -> Refinement -> Implementation) lets you introduce concrete data structures while provably preserving the abstract machine's properties.

This command has two modes:

  1. Create mode (one argument): Generate a refinement .ref from an abstract .mch
  2. Verify mode (two arguments): Check that a .ref correctly refines its .mch

Input

Arguments: $ARGUMENTS

Parse arguments:

  • One argument (.mch file): create mode — generate a refinement
  • Two arguments (.mch + .ref): verify mode — check the refinement
  • --imp: Generate an implementation (.imp) instead of a refinement (.ref)

Process

0. Check Prerequisites

Verify probcli is installed:

PROBCLI="${PROBCLI:-$HOME/Applications/ProB/probcli}"
if ! which probcli >/dev/null 2>&1 && [ ! -x "$PROBCLI" ]; then
    echo "PROBCLI_NOT_FOUND"
fi

If probcli not found: Stop and tell the user:

probcli is not installed. Run /z-spec:setup probcli first.

1a. Create Mode

Read the Abstract Machine

Load the .mch file and identify:

  • Machine name
  • SETS (deferred and enumerated)
  • VARIABLES and their types (from INVARIANT)
  • OPERATIONS (names, parameters, preconditions, effects)
  • Key invariants
Guide the Refinement Strategy

Ask the user what data refinement they want. Common strategies:

Abstract Concrete Gluing Invariant
Set Array + count ran(array(1..count)) = abstract_set
Partial function Two parallel arrays !i.(i:1..count => keys(i) |-> vals(i) : abstract_fn)
Sequence Array + length !i.(i:1..length => array(i) = abstract_seq(i))
Enumerated status Integer code status = active <=> code = 1
Unbounded NAT Bounded 0..MAX concrete_val = abstract_val

If the user doesn't specify, suggest the simplest refinement: same data representation with tighter bounds or minor restructuring.

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

Subscribe to this mod's changes

b-refine is a command published in the GitHub repository punt-labs/z-spec (5 stars, last pushed 3d ago), licensed MIT. It adds 7 tokens to every session and 1,362 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. It is 97% identical to b-refine-dev, differing in 6 lines, and is treated as a copy.