oprogramadorreal/optimus-claude/tdd
Claude Code and agent skill by oprogramadorreal/optimus-claude
- community
Checking that the SKILL.md file is still in the repository.
Guides test-driven development — decomposes a feature or bug fix into testable behaviors, then runs Red-Green-Refactor cycles with a failing test before every implementation. Auto-detects specs from docs/specs/ or docs/jira/, creates a feature branch (optional worktree), commits per cycle, and pushes. Recommends /optimus:init (falls back to general best practices on your choice); requires a passing test suite.
Install
npx vskill@latest install oprogramadorreal/optimus-claude/tddSKILL.md
Test-Driven Development
Implement a feature or bug fix test-first: for each behavior, write a failing test (Red), write the minimum code to pass it (Green), then clean up while tests stay green (Refactor). This skill builds new behavior — for restructuring without behavior change, use /optimus:refactor.
The Iron Law: no production code without a failing test first. If this cycle's implementation is written before its test, undo only that implementation using the ownership record below and begin the cycle fresh. Preserve pre-existing code and user edits; write the cycle's implementation once the failing test exists.
If this conversation is in plan mode, stop: TDD needs normal mode. Tell the user to toggle plan mode off without approving, save any refined plan to its spec, and invoke TDD in a fresh conversation.
Step 1: Pre-flight
If git rev-parse --is-inside-work-tree does not return true, read $CLAUDE_PLUGIN_ROOT/skills/init/references/multi-repo-detection.md and apply it; if a multi-repo workspace is detected, work inside the repo the user is targeting — ask which one if ambiguous. When it returns true, resolve the repository root with git rev-parse --show-toplevel, including in a linked worktree or subdirectory.
Preserve starting work
Record the current branch/HEAD and staged, unstaged, and untracked paths before setup or edits. These changes belong to the user unless the conversation explicitly includes them in this task. Existing authorization persists; ask only when ownership or scope is genuinely ambiguous. A new branch does not isolate dirty work, and a new worktree starts from committed state rather than carrying the user's dirty changes.
Before the first edit to each file in a cycle, record its existence and SHA-256 over its raw bytes. An empty Git status/diff does not prove those bytes are recoverable: index flags and filters can hide differences. Read a candidate HEAD/index blob with git cat-file blob <blob-oid>, capturing binary stdout; use Git as the rollback source only when its bytes exactly match the current file. Save that immutable blob ID and the verified hash. Otherwise copy the exact bytes to the private session scratchpad — or a temporary directory outside the repository when the host offers none — and verify the copy before editing. Keep the recovery source until the cycle is committed or safely rolled back.
For every edited path, record the last bytes/hash and existence written by the cycle, regardless of recovery source. Before any rollback, compare the current state with that last-written state. Restore or delete a whole file only on a match; if it changed independently, remove only identifiable cycle changes, preserving other work. If separation is uncertain, preserve it and show the ambiguity. Delete a newly created file only when it was absent at the cycle boundary and still matches the cycle's last version.
For restoration, load the saved blob or copy and verify its raw-byte hash before overwriting the original; preserve it on any read or verification failure. Restore those verified bytes directly, without checkout filters or reliance on the current HEAD/index. Never use hard reset, broad stash/pop, or cleanup as a substitute for this boundary; never replace the user's starting index or stage unrelated work.
If .claude/CLAUDE.md or .claude/docs/coding-guidelines.md is missing, recommend /optimus:init first; on the user's choice, continue with general best practices. Load:
.claude/CLAUDE.md— project overview, tech stack, test runner command.claude/docs/coding-guidelines.md— applied during Refactortesting.md— test conventions: framework, file location, naming, mocking patterns. In a monorepo, load the target subproject's owndocs/testing.md/docs/files; shared guidelines come from root.claude/docs/docs/product/tech-stack.mdanddocs/product/mvp-prd.md, only if present — low-priority steering that informs decomposition and Refactor but never overrides the task source (precedence:$CLAUDE_PLUGIN_ROOT/references/sdd-mapping.md)
Verify test infrastructure
Locate the test runner command (from testing.md, CLAUDE.md, or project manifests) and run it once:
- Tests pass — proceed
- Tests fail — stop and report; a failing baseline makes Red/Green indistinguishable
- No runner found — stop and recommend
/optimus:initto set up test infrastructure (its Scaffold option covers projects with no code yet)
Then find a coverage command — first match wins: the coverage section of testing.md, a runner flag (vitest --coverage, pytest --cov=., go test -cover, dotnet test --collect:"XPlat Code Coverage"), or a package.json coverage script. If found, run it once and record the Before percentage; Step 8 runs only the After measurement.
Step 2: Task and Suitability
Resolve the task — first match wins; run this even when the user also gave an inline description:
- Explicit reference — the input names a
.mdfile insidedocs/specs/ordocs/jira/: read it and use the sections item 2 (spec) or item 3 (JIRA) names as the task. - Build spec (wins over JIRA context: a brainstorm-authored spec already incorporates it) —
docs/specs/holds.mdfiles: take the most recent (filename date prefix, else modification time) and useAskUserQuestion— header "Build spec", question "Found build spec<path>— use it as the basis?", options "Use it" / "Ignore — describe a different task". When that date is older than 7 days, add to the question: "(This spec is [N] days old — if it is a/optimus:brainstorm-authored spec, you may want to re-run brainstorm for a fresh design.)" From a brainstorm-authored spec use Goal, Components, and Interfaces; from a human-authored one, Goal and Acceptance Criteria. Its## Scenariossection feeds Step 3's scenario-driven shortcut. - JIRA context — no build spec resolved (none found, or ignored) and
docs/jira/holds.mdfiles: take the one with the newest frontmatterdescription-refresh-dateand useAskUserQuestion— header "JIRA context", question "Found JIRA context<path>— use it as the basis?", options "Use it" / "Ignore — describe a different task". When that date is older than 7 days, add to the question: "(This context is [N] days old — you may want to re-run/optimus:jirafor fresh data.)" Use its Goal and Acceptance Criteria. - Nothing resolved — use the inline argument; with none, ask in plain text what feature or bug fix to implement.
Whichever item resolves a file, a ### Refined plan section in it (appended by the plan-mode handoff) takes precedence over the original approach — build from it.
Whatever the source, if the final description is longer than ~2-3 sentences (a pasted spec, JIRA ticket, or acceptance-criteria list), distill it into a single-sentence goal and confirm with AskUserQuestion — header "Distilled goal", question "I've distilled your spec to: '[single-sentence summary]'. Is this accurate?", options Looks good — "Proceed with this goal" / Adjust — "Let me refine the focus". Resolved context feeds this step — it does not bypass Step 3 decomposition (except the scenario-driven shortcut).
Classify the task:
- Suitable — new features with testable behavior, bug fixes reproducible with a test, capabilities added to existing modules, large multi-component features (they just need careful decomposition). Proceed silently.
- Not suitable — stop and report the task, the reason, and the recommended alternative: refactoring →
/optimus:refactor; documentation-only, pure styling, configuration changes, code deletion, or generated code → no testable behavior to build. - Ambiguous — use
AskUserQuestion— header "TDD fit", stating the specific concern, options Proceed with TDD / Use [alternative].
Step 3: Branch, Worktree, Decompose
Feature branch
All work happens on a new branch; the original branch recorded in Step 1 (<original-branch>) is never modified. Name the new branch per $CLAUDE_PLUGIN_ROOT/skills/commit/references/branch-naming.md (feat for a feature, fix for a bug fix), create it with git checkout -b <branch-name>, and report both branch names.
Worktree isolation (optional)
Run git worktree list; if the current directory is inside a linked worktree, skip this offer — the environment is already isolated. Otherwise use AskUserQuestion — header "Workspace", question "Use a git worktree for isolated development? Your main workspace stays on the original branch.", options Use worktree (Recommended) / Stay on branch. On yes, follow the Setup section of $CLAUDE_PLUGIN_ROOT/skills/worktree/references/worktree-setup.md with <branch-name> and <original-branch>; if creation fails, follow its Failure handling, then run git checkout <branch-name> and continue on the branch without a worktree; say so. Otherwise all subsequent commands run inside the worktree.
Decompose into behaviors
Each behavior must be observable (phrase as "When [input/action], then [outcome]"), independent (testable without the others being done), and small (one test, one assertion focus).
Scenario-driven shortcut: if the build spec contains a ## Scenarios section with ### Scenario: headings in Given/When/Then form, use those scenarios directly as the behavior list, in order — one cycle per scenario. They are stakeholder-approved acceptance criteria; do not re-derive a parallel list. Split a scenario only when a compound Then implies multiple sub-behaviors. For scenario-driven bug fixes, verify Scenario 1 reproduces the bug; prepend one if missing.
Otherwise decompose by task type: API endpoints — one behavior per response scenario; business logic — one per rule or edge case; bug fixes — the first behavior is always "reproduce the bug"; data transformations — one per step or boundary.
If more than 10 behaviors result, split into milestones of ~5-8 that each deliver a coherent slice; present the first as the current scope and list the rest as future milestones (the boundary prompt is in Step 7).
Present the numbered behavior list, then use AskUserQuestion — header "Behaviors", question "Does this decomposition look right?", options Start cycling / Adjust.
Anti-pattern — horizontal slicing. Never write all tests first, then all implementations: bulk-written tests check imagined shape, not behavior, and go insensitive to real changes. Work vertically — each cycle responds to what the previous one taught.
Step 4: Red — Write a Failing Test
Write one minimal test for the current behavior: follow testing.md conventions, test exactly one behavior, and name it as a behavior specification (e.g., "returns 401 when token is expired"). Before writing mocks, read $CLAUDE_PLUGIN_ROOT/skills/tdd/references/testing-anti-patterns.md — prefer real code over mocks, never assert on mock behavior.
Test-result honesty (every test run in Steps 4-8): run the command fresh, read the complete output, and state the actual result (e.g., "14 passed, 1 failed") — never "should pass". Red and Green both turn on a real observed result, so a guessed one silently breaks the discipline.
Run the test suite. The new test must fail on its assertion for the right reason, and all other tests must still pass.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/tdd/SKILL.md
Popularity
- Repository stars
- 75
- Repository forks
- 15
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/oprogramadorreal/optimus-claude/tdd)