tdd-atomic-commits
Skill1 starsChanged 4 months agoMITView on GitHub
Create atomic Conventional Commits for TDD workflows. Splits a working tree containing both implementation and test changes into two commits per feature — implementation first, then its test — so git history reads like a clean, bisectable TDD story. Use this skill whenever the user asks to commit, says "commit this", "commit the changes", "make the commits", "finalize the commit", or whenever the staged/unstaged diff contains paired source and test files (foo.ts + foo.test.ts, foo.py + test_foo.py, foo.go + foo_test.go, Foo.java + FooTest.java, etc.) — even if the user doesn't explicitly say "atomic" or "conventional commits". Prefer this skill over a plain commit whenever implementation and test files appear together in the diff.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- explainSkill
- staff-engineerSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 10
Commit history should read like the story of the change, not a snapshot of the working tree.
- Distinctive: line 29
Do not trust whatever is already staged.
- Distinctive: line 43
Secondary — by context: If filenames don't line up, read the diffs: does the test file import/exercise a symbol the impl file just …
- Distinctive: line 45
If a file plausibly belongs to more than one pair, or you cannot confidently pair it, stop and ask the user which grouping they want.
- Very specific: line 49
Use Conventional Commits types: feat, fix, refactor, perf, docs, style, chore, build, ci.
- Distinctive: line 68
Stage by explicit filename: Never use git add -A, git add ., or git add -u — they sweep up unrelated files and break the atomic split.
- Very specific: line 75
If yes, commit with the appropriate type (feat / fix / refactor / …).
- Very specific: line 80
After committing, run git status and git log -n <commits_created> --oneline and show the result to the user so they can confirm the history …
- Distinctive: line 88
When in doubt, ask. Good examples:
- Distinctive: line 98
Do not use git add -A, git add ., or git add -u.
- Distinctive: line 99
Do not amend earlier commits unless the user explicitly asks.
- Very specific: line 100
Do not pass --no-verify to skip hooks.
- Distinctive: line 101
Do not invert the order (test before impl).
- Distinctive: line 102
Do not bundle multiple logical units into one commit even when they share a scope.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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 Atomic Commits
Principle
Commit history should read like the story of the change, not a snapshot of the working tree. For TDD work, each logical feature becomes two atomic commits:
- The implementation commit (
feat/fix/refactor/ …) - The test commit (
test)
Implementation is committed first so that every commit in the history is self-contained: checking out the impl commit gives working code, and checking out the test commit gives working code plus the tests that prove it. The history is bisectable and each commit stands on its own.
This skill runs because the user explicitly asked for a commit. It is not a shell hook.
Workflow
Step 1 — Inspect the working tree
Run in parallel:
git status(never-uall)git diff— unstaged changesgit diff --staged— already staged changesgit log -n 5 --oneline— so your subjects match the repo's existing style
Do not trust whatever is already staged. Review all changes and decide what belongs in which commit.
Step 2 — Group changes into logical units
A logical unit is usually one implementation file plus its test file. Pair them:
Primary — by filename convention:
- TypeScript/JavaScript:
foo.ts↔foo.test.ts/foo.spec.ts/__tests__/foo.ts - Python:
foo.py↔test_foo.py/tests/test_foo.py/foo_test.py - Go:
foo.go↔foo_test.go - Ruby:
foo.rb↔foo_spec.rb/spec/foo_spec.rb - Java/Kotlin:
Foo.java↔FooTest.javaundersrc/test/… - Rust: inline
#[cfg(test)]belongs with its impl file; files undertests/are their own unit
Secondary — by context. If filenames don't line up, read the diffs: does the test file import/exercise a symbol the impl file just introduced? Does a single natural subject describe both? Pair them.
If a file plausibly belongs to more than one pair, or you cannot confidently pair it, stop and ask the user which grouping they want.
Step 3 — Determine the commit type per unit
Use Conventional Commits types: feat, fix, refactor, perf, docs, style, chore, build, ci. Reserve test for the test half of a pair (or for commits that only touch tests).
Derive the scope from the module, feature, or domain concept — usually the directory name or the component being changed.
Step 4 — Commit the implementation first, then the test
For each pair:
- Stage only the implementation file by explicit path, then commit:
<type>(<scope>): <imperative subject> - Stage only the test file by explicit path, then commit:
test(<scope>): <what the tests now cover>
The test-commit subject is a loose guideline — e.g. "ensure token expiry rejects skewed clocks", "cover session lookup edge cases", "add regression test for null user id". Match the repo's existing git log style first; fall back to a short, specific description of what the tests now verify.
Stage by explicit filename. Never use git add -A, git add ., or git add -u — they sweep up unrelated files and break the atomic split. Always pass explicit paths to git add.
Step 5 — Handle unpaired files
- Only the test file changed → one commit:
test(<scope>): <subject>. - Only the implementation file changed → tell the user:
"
path/to/filehas no corresponding test changes. Continue with the commit anyway?" If yes, commit with the appropriate type (feat/fix/refactor/ …). If no, stop and let the user decide. - Unrelated files (configs, docs, unrelated source) → ask the user whether to include, leave, or commit them separately with their own conventional type. Do not silently lump them in.
Step 6 — Verify
After committing, run git status and git log -n <commits_created> --oneline and show the result to the user so they can confirm the history looks right and the working tree is clean.
Fix workflow
For fix changes the impl-first rule still holds: commit the implementation fix first, then — if the test had to change to catch the regression or reflect the corrected behavior — commit the updated test as test(<scope>): <subject>. If the existing test was already adequate and nothing in the test file changed, a single fix commit is correct — do not invent a test commit.
Complex cases — ask the user
When in doubt, ask. Good examples:
- Multiple features mixed in one working tree and it's unclear which files belong together
- One impl file that touches behavior exercised by two different test files (or vice versa)
- Renames/moves that git has recorded as add+delete
- Generated files, lockfiles, migrations, or snapshots that aren't obviously impl or test
A short clarifying question is cheaper than a wrong commit.
Things to avoid
- Do not use
git add -A,git add ., orgit add -u. Stage by explicit path. - Do not amend earlier commits unless the user explicitly asks. Always create new commits.
- Do not pass
--no-verifyto skip hooks. If a hook fails, investigate the root cause. - Do not invert the order (test before impl). The whole point is that every commit is independently runnable, which requires impl-first.
- Do not bundle multiple logical units into one commit even when they share a scope. One feature → one pair.
Example
Working tree:
modified: src/auth/token.ts
modified: src/auth/token.test.ts
modified: src/auth/session.ts
modified: src/auth/session.test.tsResulting history (oldest first):
feat(auth): validate token expiry against server clock
test(auth): ensure token expiry rejects skewed clocks
refactor(auth): extract session lookup into dedicated helper
test(auth): cover session lookup helper edge casesTwo logical units → four commits, each pair impl-first.
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.

