tdd-spec
Skill1 starsChanged 12 days agoMITView on GitHub
Test-first workflow with locked, number-based spec tests for any repo with a .claude/tdd/ pack. Use when starting any new change, feature or bug fix in such a repo; when asked to write spec tests, lock tests, implement against locked tests, raise a dispute about a test, or verify a change before merge; or by name (/tdd-spec). Spec tests are written first from docs/specs/<id>.md, proven red for the right reason, locked, and merged by the human before implementation starts. Implementing agents never change them.
In this repository6 other files it gives its agents.
- skills/review-core/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ai-harness-engineeringSkill
- cost-reportSkill
- rag-ui-redesignSkill
- review-coreSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 1 is distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Use the py312 env (conda run -n py312 python ..., in PowerShell).
- Very specific: line 48
If docs/specs/<id>.md doesn't exist, draft it with these sections:
- Very specific: line 60
Write tests in <spec_root>/<id>/.
- Very specific: line 73
Run tdd lint <id> and tdd red <id> until both pass:
- Very specific: line 79
Run tdd lock <id>, commit tests, stubs, spec and .claude/tdd/locks/<id>.json together, and tell the human the branch is ready for the spec …
- Very specific: line 88
Never edit spec tests, the spec, locks or locked signatures.
- Very specific: line 92
If the gate says "lock for <id> changed on main.
- Very specific: line 93
When green, run tdd verify <id> (fresh hypothesis seeds).
- Very specific: line 95
Before the human merges, post the gh pr checks <n> output as a PR comment.
- Very specific: line 140
Add hypothesis to the project's requirements and .claude/tdd/state/ to .gitignore.
- Very specific: line 149
Never run VS Code or claude elevated.
- Very specific: line 160
Check the output names the reviewed commit, shows the new version, and OK: only administrators and SYSTEM can write to the managed install.
- Distinctive: line 163
Start VS Code normally.
- Very specific: line 165
Remove the hooks with the same command plus -Uninstall.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
tdd-spec: locked spec tests first, then implementation
Design and rationale: design/plan.md. Tools: scripts/tdd.py
(run as python <skill>/scripts/tdd.py <command>, or python tools/tdd/tdd.py inside a repo).
Use the py312 env (conda run -n py312 python ..., in PowerShell).
A repo takes part when it has .claude/tdd/profile.toml on origin/main. Its spec_root and
unit_root (tests/spec and tests/unit in faultline, test/spec and test/unit elsewhere)
are written <spec_root> and <unit_root> below.
Which role you are in
Your branch decides it. The edit guard enforces this; don't try to work around a denial.
| Branch | Role | You may change | You may not change |
spec/<id> | spec author | docs/specs/<id>.md, <spec_root>/** (not <spec_root>/conftest.py or _shared/), fixtures, new stub functions in src/ | existing functions, <unit_root>, locks by hand, maintenance paths |
impl/<id> or impl/<id>--part<N> | implementer | src/, <unit_root>/**, <dispute_dir>/<id>.md | anything under <spec_root>, docs/specs/, locks, locked signatures, maintenance paths |
| anything else | normal work | not the protected paths | spec tests, locks, protected fixtures, maintenance paths |
Maintenance paths (.claude/tdd/profile.toml, protected.txt, every file directly in
<spec_root>/ such as conftest.py, <spec_root>/_shared/**, tools/tdd/**, .github/workflows/**, .githooks/**,
.claude/settings.json, .claude/settings.local.json) are changed by the human outside Claude,
through a maintenance PR.
Code under src/ must never refer to the gate (tdd_plugin, tddlib, TDD_* variables) or import
pytest, hypothesis or pluggy; the gate and CI fail on it. That check is a tripwire, not a
barrier: never try to get around it.
On spec/<id> you may change only <id>'s tests among the active locks. Another active change's
locked tests change only on that change's own spec branch, through a re-lock.
Spec author (spec/<id>)
Work from the spec file only, in a fresh context; never from an implementation plan.
- If
docs/specs/<id>.mddoesn't exist, draft it with these sections:## Requirement: what must be true when the change is done;## Acceptance criteria: items- **C1**: <result> within <tolerance>. Oracle: <source>., each checkable (a value with a tolerance, an invariant, a required refusal or citation);## Interface: the new signatures, e.g.pkg.mod.func(x: float) -> float;## Notes: oracle sources and data snapshots (public-domain or synthetic only).
- For each new interface item add a stub to
src/. Its body is only (a docstring and)raise NotImplementedError("tdd:<id>"). Never change an existing function. Keep the header plain: no calls, lambdas or comprehensions in defaults or annotations; decorators only@staticmethod,@classmethod,@property,@abstractmethod,@overload; a new class gets no decorators and no calls in its bases or keywords. Imports you add go at module level, name what they import (no*), and never reuse a name the module already defines. Write tests in
<spec_root>/<id>/. Every test:- is tagged
@pytest.mark.criterion("C1"); - has a
# oracle: <source>comment naming where the expected value comes from (closed form computed in the test, a published example, a hand calculation shown in the test ...); never a value obtained by running code; - compares floats with
pytest.approx(..., rel=|abs=)and a one-line reason for the tolerance; - reads only committed fixtures, never
data/, the network or the current date; - mocks nothing in the project's own
srcpackage (fakes only at I/O boundaries); - doesn't skip or xfail.
Each criterion needs at least one point-oracle test and one property or metamorphic test (
@given(...)from hypothesis, or@pytest.mark.metamorphic). Put fixtures for this spec in<spec_root>/<id>/conftest.py; spec tests can't see the project's other conftest files.- is tagged
- Run
tdd lint <id>andtdd red <id>until both pass:- lint is the mechanical rubric;
- red runs the tests against the stubs (each must fail with an assertion or exactly
NotImplementedError("tdd:<id>")) and against wrong-value stubs (0,NaN,None, empty, zero-valued instances), each of which every test must also fail. If the correct answer really is one of those values, add# red-exempt: <variant> <reason>in the test for review.
- Run
tdd lock <id>, commit tests, stubs, spec and.claude/tdd/locks/<id>.jsontogether, and tell the human the branch is ready for the spec PR. The lock takes effect only once the human merges it.
Implementer (impl/<id>)
- Cut
impl/<id>from an up-to-datemainthat contains the lock (tdd statusshows it). - Loop:
tdd run <id>, read the failures, changesrc/, repeat. The Stop gate runs the same check when you stop and blocks while tests fail, up to the change's budget. - Never edit spec tests, the spec, locks or locked signatures. If you believe a test or its
oracle is wrong, write
<dispute_dir>/<id>.md(default.claude/tdd/disputes/<id>.md) with your reasoning and evidence, and stop. The human decides; a corrected test arrives through a re-lock onmain, after which you rebase. - If the gate says "lock for
<id>changed on main; rebase", rebaseimpl/<id>ontoorigin/main. - When green, run
tdd verify <id>(fresh hypothesis seeds). A failure is written to the dispute file for a re-lock; report it and stop. - Before the human merges, post the
gh pr checks <n>output as a PR comment.
Work too large for one PR goes in impl/<id>--part1, --part2, ...: each part may leave tests
failing with an assertion or the stub's NotImplementedError, never for another reason. The final
PR, from exactly impl/<id>, must make every locked test pass; its merge retires the lock.
If the gate blocks
- Tampering ("differ from origin/main or from their lock"): you changed a protected file.
Restore it with
git restore --source=origin/main -- <path>. - Not passing yet: fix
src/. Never loosen a test. - Budget used up: the gate lets you stop. Report what still fails and stop.
Commands
tdd lint <id> | red <id> | lock <id> | run <id> | verify <id>
tdd check integrity of the working tree against origin/main
tdd gate what the Stop gate would decide now (dry run)
tdd status locks, states, warnings
tdd retire <id> --record TEXT
retire a lock by record (maintenance branch; see below)
tdd path-guard --base <rev> --head <rev> [--head-ref <branch>] (CI)
tdd ci [--head-ref <branch>] (CI)
tdd init <repo> [--spec-root test/spec --unit-root test/unit]
vendor the tools into <repo>/tools/tdd; add missing pack files and workflowsRetirement by record (human, maintenance PR)
A lock normally retires when the PR from exactly impl/<id> is merged into main. When that history
is not in the repository (for example a public mirror published without its development history),
the human retires the lock by record instead: on a maintenance branch, tdd retire <id> --record
"<why, e.g. the merged PR>", committed and merged as a PR of its own. A lock with status retired
then behaves exactly like a merge-retired one: its tests are graduated (CI demands they pass), its
signatures and tests are no longer locked. The path guard classifies any lock status leaving
active as a maintenance change, so a spec or implementation PR can't retire a lock. Agents never
run tdd retire.
Setting up a repo (human, maintenance PR)
tdd init <repo>(with--spec-root test/spec --unit-root test/unitfor XbrlRag and MacroRAG). It vendors the tools and adds, where missing,.claude/tdd/profile.toml,protected.txt,<spec_root>/conftest.py(hypothesis profiles) and thetdd-path-guardandtdd-specworkflows. Review each, and fill in the project's dependency install step intdd-spec.yml.- Add
hypothesisto the project's requirements and.claude/tdd/state/to.gitignore. - The PR that adds
tdd-path-guard.ymlisn't checked by it: review it by hand. - In GitHub settings, disable squash and rebase merging.
Managed hooks (human, once per machine, elevated PowerShell)
install.ps1 copies scripts\*.py to C:\Program Files\ClaudeCode\tdd and writes
managed-settings.d\tdd.json: the edit guard (PreToolUse on Write|Edit|MultiEdit|NotebookEdit),
the Stop gate and a SessionStart logger. Events go to $CLAUDE_CONFIG_DIR/tdd-history/<project>/.
Never run VS Code or claude elevated.
Install, and reinstall after any change to scripts/. You can't run this yourself (it needs
admin rights), so give the human these steps:
- Close VS Code and
claudesessions. - Open PowerShell with Run as administrator and run
powershell -ExecutionPolicy Bypass -File <config>\skills\tdd-spec\install.ps1 -Python <project python.exe> -AcceptWritableSource. The flag acknowledges that the Python env, git and the skill's scripts are user-writable on this machine. The human should pass it only when no agent session has run since they reviewed the committed scripts. The installer refuses uncommitted script changes. - Check the output names the reviewed commit, shows the new version, and
OK: only administrators and SYSTEM can write to the managed install. AWARNINGthat Git or py312 is user-writable is expected on this machine (see design/plan.md §10.1). - Start VS Code normally.
Remove the hooks with the same command plus -Uninstall. Full procedure: design/plan.md §10.1.
Afterwards, check from the new session: tdd status shows no version mismatch, and
C:\Program Files\ClaudeCode\tdd\tddlib.py has the expected VERSION.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

