Skip to content
/

spec-first (nlatuan187)

spec-first-nlatuan · nlatuan187/spec-first · ★ 2 · last commit 2026-04-06

Single-file paste-in methodology that engineers AI behavior via probability theory, with a Scope Routing table that maps error-state count to implementation route.

Best whenEvery rule must derive from The Fundamental Law (AI generates most probable token) with explicit rationale — so the AI understands why it should comply, not …
Skip ifMixing session types (Spec + Build in same session), Implementing before spec is written
vs seeds
spec-kit(Archetype 2) but radically simpler: single paste-in file vs. full Python CLI, 4 skills vs. 9+18 hooks, no CLI binary. T…
Primitive shape 9 total
Skills 4 Hooks 5
00

Summary

spec-first (nlatuan187) — Summary

A single-file paste-in methodology — snippet.md — that transforms any AI coding tool's context file into a spec-first development harness. The methodology's core insight is called "The Fundamental Law": AI generates the most statistically probable next token, not the correct one; every methodology rule derives from this law.

The framework introduces a six-section spec format (S1 error states, S2 context, S3 cross-feature integration, S4 data model, S5 API changes, S6 QA scenarios) with a "Scope Routing" decision table that determines whether implementation should proceed autonomously, with a review recommendation, or only after mandatory human review.

Installation is a one-liner curl command. The installer detects the user's AI tool and appends the methodology to the appropriate context file (CLAUDE.md, .cursorrules, .windsurfrules, etc.). For Claude Code users, it also installs four skills: /spec, /spec-review, /spec-check, /spec-stats.

Closest seed match is spec-kit (Archetype 2 — mirror commands+skills) but with a radically simpler component count (4 skills vs 9, no hooks, no CLI). The Scope Routing decision table and "S1 error states first" discipline are the standout differentiators.

01

Overview

spec-first (nlatuan187) — Overview

Origin

Created by nlatuan187. Repository description: "Atomic AI coding discipline — paste one file, fix the 5 failure modes." 2 stars, Shell language, last commit 2026-04-06. The README cites production data from "two developers, 24 days" as empirical validation.

Philosophy

Everything derives from one axiom — The Fundamental Law:

"AI generates the most statistically probable next token — not the correct one. It has no judgment. Only probability."

This law is used to rationalize every rule. For example: "The most probable token after an ambiguous request is a confident-sounding wrong answer" — hence the Clarify session. "After a build session, it's 'the code is correct'" — hence the separate Review session.

The methodology identifies five failure modes that spec-first fixes:

  1. Happy-path bias (AI skips error states)
  2. Isolation blindness (AI forgets what else exists)
  3. Scope creep (AI adds unrequested features)
  4. Build-review contamination (the AI that built the code reviews it)
  5. Debugging death spiral (repeat same wrong fix)

Manifesto-style quotes

From snippet.md:

"Every rule in this methodology derives from this single law. When you understand it, you can engineer AI behavior for any situation not covered here."

On spec value:

"Same AI. Same prompt. The spec told it what to check — so it checked. The AI didn't get smarter. It got a checklist."

On session separation:

"Each session type has a different most-probable-next-token profile. Mixing types imports probability bias."

On Scope Routing:

"Scope maps to failure probability — not preference. Bug fixes tolerate autonomous (1.5:1 fix ratio). Auth features do not (15% security bugs in production data). The data determines the route."

Production evidence cited

  • Week 1 fix:feat ratio: 5:1 (before spec-first)
  • Week 4 fix:feat ratio: 1.5:1 (after spec-first)
  • S1 + S3 prevent: 65% of review failures
  • Productivity multiplier: 10–15x
  • From 626 production commits
02

Architecture

spec-first (nlatuan187) — Architecture

Distribution

  • Type: methodology-doc (core) + optional command-pack (for Claude Code)
  • Install: curl | sh one-liner
  • Install complexity: one-liner

Install commands

# macOS/Linux
curl -fsSL https://raw.githubusercontent.com/nlatuan187/spec-first/master/install.sh | sh

# Windows PowerShell
iwr -useb https://raw.githubusercontent.com/nlatuan187/spec-first/master/install.ps1 | iex

The installer:

  1. Detects AI tool (Cursor → .cursorrules, Windsurf → .windsurfrules, AGENTS.md, Copilot, CLAUDE.md)
  2. Appends snippet.md to the appropriate context file
  3. Copies spec.md and review.md to project root
  4. Creates specs/ directory
  5. For Claude Code: installs four skills in .claude/skills/

Directory tree

spec-first/
├── snippet.md               ← THE product (paste into any context file)
├── spec.md                  ← Feature spec template (S1-S6)
├── review.md                ← Two-pass code review checklist
├── install.sh               ← curl-friendly installer
├── install.ps1              ← Windows installer
├── CLAUDE.md                ← Project guidelines (meta)
└── advanced/
    ├── prp.md               ← Full implementation blueprint (optional)
    ├── ETHOS.md
    ├── INTEGRATIONS.md
    ├── skills/
    │   ├── spec/SKILL.md        ← /spec slash command
    │   ├── spec-review/SKILL.md ← /spec-review slash command
    │   ├── spec-check/SKILL.md  ← /spec-check slash command
    │   └── spec-stats/SKILL.md  ← /spec-stats slash command
    ├── deep-dives/          ← ai-limitations.md, worktree-workflow.md, etc.
    ├── during-coding/       ← implementation-brief.md
    ├── templates/           ← full feature-spec.md, review-checklist.md, CLAUDE.md template
    └── examples/

Target AI tools

Multi-tool by design. From the CLAUDE.md:

"Tool-agnostic — snippet.md works on Cursor, Windsurf, Copilot, Claude Code. Do not make it Claude Code-specific."

Tool Context file
Claude Code CLAUDE.md
Cursor .cursorrules
Windsurf .windsurfrules
GitHub Copilot .github/copilot-instructions.md
Codex / other AGENTS.md

Config files

File Purpose
snippet.md Master methodology (source of truth)
spec.md Spec template in project root
review.md Review checklist in project root
specs/[slug].md Generated feature specs
03

Components

spec-first (nlatuan187) — Components

Core artifact: snippet.md

The entire methodology in one paste-able file. Contains:

  • The Fundamental Law
  • Four session types table (Clarify / Spec / Build / Review)
  • Scope Routing decision table
  • Formality Dial (scope → spec format mapping)
  • Six spec sections (S1-S6)
  • Delta Format (for changes to existing code)
  • Refactor Format
  • Bug Format
  • Debugging Protocol
  • Review Checklist (two-pass)

Skills (4, Claude Code only)

Installed to .claude/skills/ by the installer:

Skill File Purpose
/spec advanced/skills/spec/SKILL.md Generate spec for current feature
/spec-review advanced/skills/spec-review/SKILL.md Adversarial spec review before implementation
/spec-check advanced/skills/spec-check/SKILL.md Verify spec completeness after implementation
/spec-stats advanced/skills/spec-stats/SKILL.md Weekly health metrics (fix:feat ratio, spec coverage, S1/S3 quality)

Hooks (Claude Code)

5 hook files in hooks/ directory:

Hook File Event
SessionStart hooks/session-start/ Inject methodology at session start
SessionEnd hooks/session-end/ (unknown content — not publicly readable)
PreToolUse hooks/pre-tool-use/ Pre-tool validation
PreCompact hooks/pre-compact/ Pre-compaction handling
RunHook hooks/run-hook.cmd Windows hook runner

Templates

File Purpose
spec.md Feature spec template (S1-S6 format)
review.md Two-pass code review checklist
advanced/prp.md Full implementation blueprint for complex features
advanced/templates/feature-spec.md Extended spec template
advanced/templates/review-checklist.md Extended review checklist

Scripts

File Purpose
install.sh Bash installer (curl-friendly)
install.ps1 PowerShell installer (Windows)

MCP Servers

None.

Commands

None (slash commands are implemented as skills, not the separate command format).

05

Prompts

spec-first (nlatuan187) — Prompts

Excerpt 1 — The Fundamental Law + TRIGGER (from snippet.md verbatim)

## Spec-First — AI Development Methodology

> Paste into your AI context file...

### The Fundamental Law

**AI generates the most statistically probable next token — not the correct one. It has no judgment. Only probability.**

Every rule in this methodology derives from this single law. When you understand it, you can engineer AI behavior for any situation not covered here.

### TRIGGER: When asked to build, implement, create, add, fix, refactor, or debug

**Step 0 — Route the intent**: Match the user's request to the **Formality Dial** below — one table, one lookup, correct format.

**Step 1 — Clarify** (skip if intent is unambiguous):
Read the constitution. Then check: can you answer all three?
- What is the exact trigger (user action or system event)?
- What is the success outcome (what does the user see when it works)?
- Is this one operation, or multiple features bundled?

If any is unclear from the request + constitution, ask those questions. Maximum 3. About observable behavior only — never about implementation. Wait for answers.

**Terminal state**: Do not write the spec until all questions have answers.

*Derives from: The most probable next token after an ambiguous request is a confident-sounding wrong answer.*

Prompting technique: Axiomatic derivation. Every rule is followed by a "Derives from" rationale that references The Fundamental Law. This makes rules harder to override because the AI can see why they exist, not just that they exist.

Excerpt 2 — Scope Routing: Autonomous path (from snippet.md verbatim)

**Autonomous** — implement in this session, no break:

━━━ Spec written: specs/[slug].md ━━━ Scope: [Bug fix / Small change] — [N] error states, [N] integration points. Implementing now. Key risks from S1: [list items].

Then immediately, without waiting:
1. Re-read the spec you just wrote — S1 last (the section read most recently gets the most weight in your code)
2. If the project has a test framework: write failing tests from S6 scenarios before implementing
3. Implement — handle every S1 error state explicitly in code
4. If S3 has integration points: verify those touchpoints are covered
5. If stuck after 2 attempts: follow Debugging Protocol (write debug file, new session)
6. When done: run `/spec-check specs/[slug].md` and surface any gaps

Prompting technique: Ordered re-read instruction ("S1 last"). This exploits the recency effect in LLM context — the last section read gets more attention. Telling the AI to read S1 last (error states) ensures they weigh most heavily in the generated code.

Excerpt 3 — Review Required path (from snippet.md verbatim)

**Review required** — output block, then stop:

━━━ Spec written: specs/[slug].md ━━━ Scope: [Large / High-risk] — [N] error states, [N] integration points. Human review required. [Auth/payment: 15% security bug rate in production data.] Run /spec-review specs/[slug].md — must return APPROVED. Then: a human must read specs/[slug].md before implementing. /spec-review is a mechanical gate — it does not replace adversarial judgment for auth/payments/PII.

Do not implement regardless of user override request.

Prompting technique: Explicit override resistance. The instruction "Do not implement regardless of user override request" pre-handles the most common bypass attempt — the impatient user saying "just do it."

09

Uniqueness

spec-first (nlatuan187) — Uniqueness

differs_from_seeds

Closest to spec-kit (Archetype 2 — mirror commands+skills with CLI orchestration) but dramatically simpler in component count and fundamentally different in philosophy. Where spec-kit ships a full Python CLI with 9 commands, 9 skills, and 18 hooks, spec-first ships a single paste-able Markdown file as its core. The framework's key innovations over spec-kit are the Scope Routing decision table (which maps error-state count and integration-point count to an explicit implementation route) and the "Derives from" rationalization pattern that grounds every rule in the Fundamental Law. This rationalization makes rules harder to bypass because the AI understands why they exist. Compared to openspec (Archetype 2, tool-agnostic like spec-first), spec-first differs by providing explicit statistical backing ("15% security bug rate," "65% of review failures," "1.5:1 fix ratio") to justify its gate decisions — openspec does not cite production data. The session-separation discipline (Clarify/Spec/Build/Review as distinct sessions with deliberate cold starts) is unique: no seed enforces session separation as explicitly as spec-first does.

Positioning

The most psychologically sophisticated single-author SDD methodology. Rather than enforcing compliance through hooks and CLI validation, it convinces the AI why rules matter by embedding the rationale alongside the rule. The production data citations lend empirical credibility unusual in this category.

Best fit: individual developers and small teams using any AI coding tool who want a lightweight methodology that explains itself.

Observable failure modes

  1. No enforcement beyond the spec itself: If the AI decides to bypass a rule (e.g., implement without writing a spec), there is no hook or CLI to stop it — only the probability-engineering in the context file.
  2. Session separation is manual: Users must explicitly start new sessions. Impatient users frequently skip this (the README acknowledges this with the "skip review" escape hatch).
  3. Scope Routing complexity: The S1/S3 threshold table requires counting error states and integration points accurately. Miscounting leads to wrong routing.
  4. 2-star repo: Very low adoption signal, making it hard to assess real-world effectiveness of the claimed production data.
  5. Hook content unknown: Three of the five hook files were not publicly readable during analysis — their exact enforcement behavior is unclear.
04

Workflow

spec-first (nlatuan187) — Workflow

Session types

Each request is classified into one of four session types:

Session AI reads AI produces Terminal action
Clarify Constitution + feature request 3 questions max Wait for answers
Spec Constitution + answers specs/[slug].md Scope Routing
Build Constitution + spec Working code "Start new session to review"
Review Constitution + diff Pass 1 + Pass 2 findings "No new session needed"

Scope Routing decision table

After every spec, Scope Routing determines the next action:

S1 error states S3 integration points Category Route
≤ 3 ≤ 1 Standard Autonomous — implement now
4–7 2–3 Standard Recommend review
≥ 8 ≥ 4 Any Review required
any any High-risk† Review required

†High-risk: auth, payments, database schema changes, data migration, user PII, infrastructure-as-code.

Autonomous requires BOTH thresholds met (AND). Review-triggers on EITHER column (OR).

Formality Dial

Scope Spec format Sections
Emergency Fix first → retroactive Bug Format S1 + S6
Bug fix Bug Format S1 + S6
Small change S1 + S3 + S6 3 sections
Spike No spec → spec chosen approach S1 + S3
Refactor Refactor Format S3 + S6
Brownfield delta Delta Format Depends on scope
New feature Full S1–S6 All 6
Large feature Full S1–S6 + Implementation Notes All 6 + notes

Spec sections (S1-S6)

Section Content
S1 Error states (failures FIRST — happy path last)
S2 Context (how the feature fits into the codebase)
S3 Cross-feature integration (what else is affected)
S4 Data model changes
S5 API changes
S6 Manual QA scenarios (testable, observable outcomes)

Approval gates

Gate When Type
Scope Routing After every spec choice-list (Autonomous / Recommend review / Review required)
Spec review (/spec-review) Before Build session for Review-required specs file-review
Human reads spec For auth/payments/PII, mandatory regardless of /spec-review output human-required
Post-implementation spec-check (/spec-check) After implement file-review

Weekly health check

/spec-stats produces:

  • Fix:feat ratio
  • Spec coverage percentage
  • S1/S3 quality scores
  • Health score out of 10
06

Memory Context

spec-first (nlatuan187) — Memory & Context

State storage

File-based. Specs are stored as Markdown files in specs/:

specs/
└── [feature-slug].md    ← Feature spec with YAML frontmatter
    # Frontmatter: title, status, scope, s1_count, s3_count

Persistence

Project-level. The specs/ directory is committed to the repository, providing full history of spec evolution via git.

Context injection

The methodology is injected at session start via two mechanisms:

  1. snippet.md content in context file (CLAUDE.md, .cursorrules, etc.) — passively loaded at every session
  2. SessionStart hook — for Claude Code users, the hook re-injects methodology if not present

Cross-session handoff

The "Project Constitution" concept (CLAUDE.md / .cursorrules) serves as persistent cross-session context:

"Your AI context file is your project constitution — the document that anchors every AI decision to your stack, conventions, and constraints. Before any session: the AI reads the constitution. Every spec, every review, every debug starts from the same ground truth."

Spec frontmatter (YAML in each spec file)

---
title: "Feature Name"
status: "Draft | Approved | Implemented"
scope: "New feature | Bug fix | Small change | ..."
s1_count: 4
s3_count: 2
---

s1_count and s3_count feed the Scope Routing decision table.

Memory type

File-based (Markdown with YAML frontmatter). No database, no vector store.

Compaction handling

The PreCompact hook suggests compaction-aware behavior is addressed, though exact content was not publicly available.

State files

File Content
CLAUDE.md / .cursorrules Project constitution (methodology + project context)
spec.md Blank spec template
review.md Review checklist
specs/[slug].md Feature specs (with status tracking in frontmatter)
07

Orchestration

spec-first (nlatuan187) — Orchestration

Multi-agent support

No. Single-agent workflow. The Scope Routing table routes to either autonomous (single session), review-then-build (two sessions in sequence), or blocked-until-human (manual gate).

Orchestration pattern

Sequential with session separation. The key pattern is deliberate session isolation:

  • Spec session → New session → Build session → New session → Review session
  • Session separation prevents "build-review contamination" (AI that built the code reviewing it)

Isolation mechanism

Session boundary. Each session starts fresh with only the constitution and the relevant artifact (spec file or diff). No git worktrees, no containers.

Execution mode

Interactive-loop with deliberate session breaks. The user must manually start new sessions between spec/build/review phases (for non-autonomous scope).

Multi-model routing

None. Tool-agnostic design — no model configuration.

Prompt chaining

Yes, by session handoff:

  1. Clarify session → writes answers
  2. Spec session reads constitution + answers → writes specs/[slug].md
  3. Build session reads constitution + spec → writes code
  4. Review session reads constitution + diff → writes findings

Consensus mechanism

None.

Auto-validators

  • /spec-check — post-implementation spec completeness check (manual invocation)
  • /spec-stats — weekly health metrics

No automatically-triggered validators on commit or file save.

Crash recovery

Implicit. Session-based — if a session is interrupted, the user restarts from the last created artifact.

08

Ui Cli Surface

spec-first (nlatuan187) — UI / CLI Surface

Dedicated CLI binary

None.

Local web dashboard

None.

IDE integration

Multi-tool, via context file append. For Claude Code specifically, four skills are installed as slash commands.

Slash commands / Skills (Claude Code)

Command Trigger Purpose
/spec advanced/skills/spec/SKILL.md Write spec for current feature
/spec-review advanced/skills/spec-review/SKILL.md Adversarial spec review
/spec-check advanced/skills/spec-check/SKILL.md Post-implementation spec verification
/spec-stats advanced/skills/spec-stats/SKILL.md Weekly metrics report

Hooks

5 hook files in hooks/:

  • session-start — re-inject methodology if context is stale
  • session-end — (content not publicly accessible)
  • pre-tool-use — (content not publicly accessible)
  • pre-compact — (content not publicly accessible)
  • run-hook.cmd — Windows hook runner

Installer output

curl -fsSL .../install.sh | sh

The installer prints:

spec-first installer
─────────────────────
Project: /your/project
Context file: CLAUDE.md

✓ Appended to CLAUDE.md
✓ spec.md → project root
✓ review.md → project root
✓ specs/ ready

Cross-tool portability

High. snippet.md is designed to be tool-agnostic. The installer handles 5 different context file targets automatically.

Related frameworks

same archetype · same primary tool · same memory type

Context-Engineering Handbook ★ 9.0k

Provides a first-principles, research-grounded vocabulary and learning path for context engineering — the discipline of designing…

walkinglabs/learn-harness-engineering ★ 6.6k

Teach harness engineering from first principles (12 lectures + 6 projects) and provide a scaffolding skill (harness-creator) that…

Awesome Harness Engineering (walkinglabs) ★ 2.7k

Curate the authoritative reference list of articles, benchmarks, and tools for harness engineering — the practice of shaping the…

cline-memory-bank (nickbaumann98) ★ 581

Custom instructions + 6-file hierarchical Markdown memory bank so Cline maintains full project context across sessions, with a…

FPF (First Principles Framework) ★ 372

Provides a formal pattern language for making reasoning explicit, traceable, and publishable in mixed human/AI engineering work —…

nexu-io/harness-engineering-guide ★ 134

Provide a practical, code-first reference guide to harness engineering — from first principles to production patterns —…