model2code

model2code is a command for Claude Code from punt-labs/z-spec. It costs 6 tokens per session (2,153 once invoked), scanned A, a copy of model2code-dev, MIT.

A code-generation command that translates a checked Z specification—a formal description of a system’s data and behavior—into implementation code and unit tests.

In plain words
What is it for?
Use it with Swift, TypeScript, Python, or Kotlin projects to generate code from a .tex specification.
Why use it?
It connects a precise system model with code, while checking the model first so errors are found before generation.

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 with Swift, TypeScript, Python, or Kotlin projects to generate code from a .tex specification.

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/punt-labs/z-spec/model2code/github.svg)](https://agentmods.dev/commands/punt-labs/z-spec/model2code)
Your own site
<a href="https://agentmods.dev/commands/punt-labs/z-spec/model2code"><img src="https://agentmods.dev/badge/commands/punt-labs/z-spec/model2code/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for model2code

Your own site · 80×15
<a href="https://agentmods.dev/commands/punt-labs/z-spec/model2code"><img src="https://agentmods.dev/badge/commands/punt-labs/z-spec/model2code.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 6 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,153 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 98% 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.00006 $0.02153
Opus 5.5 $0.00002 $0.00861
Sonnet 5.5 $0.00001 $0.00431
Haiku 4.5 $0.00001 $0.00215

Measured 3mo ago against content hash 082b37a102d3, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

model2code 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 3mo 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

98% identical to model2code-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/model2code.md · 350 lines

How it starts

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

/z-spec:model2code - Model to Code

Generate implementation code and unit tests from a Z specification.

Usage

/z-spec:model2code [spec.tex] [language]

Arguments:

  • spec.tex - Z specification file (default: search in docs/)
  • language - Target: swift, typescript, python, kotlin (default: detect from project)

Workflow

Step 1: Validate the Specification

Before generating code, type-check the specification with fuzz:

fuzz -t <spec.tex>

If fuzz reports errors, fix them first. Code generation from invalid specs produces invalid code.

Step 2: Detect Target Language

If no language specified, detect from project files:

File Present Language
Package.swift, *.xcodeproj Swift
package.json, tsconfig.json TypeScript
pyproject.toml, setup.py, requirements.txt Python
build.gradle.kts, pom.xml Kotlin

Step 3: Generate Code

Read the Z specification and translate each construct to idiomatic code for the target language.

Translation Principles

State Schemas → Classes/Structs

Z state schemas become data types with properties:

\begin{schema}{Account}
balance : \num \\
status : Status
\where
balance \geq 0 \lor status = suspended
\end{schema}

Swift:

struct Account {
    var balance: Int
    var status: Status

    var isValid: Bool {
        balance >= 0 || status == .suspended
    }
}

TypeScript:

interface Account {
    balance: number;
    status: Status;
}

function isValidAccount(a: Account): boolean {
    return a.balance >= 0 || a.status === Status.Suspended;
}

Free Types → Enums

\begin{zed}
Status ::= pending | active | suspended | closed
\end{zed}

Swift:

enum Status {
    case pending, active, suspended, closed
}

TypeScript:

enum Status {
    Pending = "pending",
    Active = "active",
    Suspended = "suspended",
    Closed = "closed"
}

Read the full file on GitHub · 350 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. 3mo ago First seen · 350 lines · 6 tokens per session scan A 082b37a102d3

Subscribe to this mod's changes

model2code is a command published in the GitHub repository punt-labs/z-spec (5 stars, last pushed yesterday), licensed MIT. It adds 6 tokens to every session and 2,153 once invoked, about $0.0000 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 98% identical to model2code-dev, differing in 6 lines, and is treated as a copy.

Related

model2code compared with commands from other repositories

model2code next to 6 commands from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
model2codepunt-labs/z-specCommand5yesterdayMITA6Claude Code
feedback-to-uspunt-labs/prfaqCommand262d agoMITA19Claude Code
badgepunt-labs/prfaqCommand262d agoMITA11Claude Code
importpunt-labs/prfaqCommand262d agoMITA15Claude Code
researchpunt-labs/prfaqCommand262d agoMITA12Claude Code
streamlinepunt-labs/prfaqCommand262d agoMITA18Claude Code
reviewpunt-labs/prfaqCommand262d agoMITA12Claude Code