Building a TDD Coding Agent
The Idea
Can we teach a coding agent to follow Test-Driven Development and would it be effective? This was the question that kicked off what became a fascinating weekend experiment in AI workflow automation. I was lucky enought to get to know some prominent TDD figures throughout my career. Before diving into the project, I reached out to Kent Beck and Steve Freeman for some valuable tips. The success criteria were clear: build an agent that could execute a proper Red-Green-Refactor loop on any given feature prompt.
Before writing a single line of code, we had to solve a fundamental question: how do you actually build an AI coding agent? Three main approaches emerged:
Option 1: Code everything by hand and invoke LLM API directly This would give us complete control over code generation and editing. We could fine-tune every aspect of how the AI modifies files and structures code. The downside? We’d need to solve the “editing problem” which is less trivial than it might seem.
Option 2: Use a CLI coding agent for individual steps Leverage existing tools like Claude Code that already understand project context and file relationships. The trade-off is less granular control, but the implementation becomes dramatically simpler. Perfect for rapid prototyping and validation.
Option 3: Modify an existing coding agent Finally, we could fork something like an open-source coding agent and adapt it specifically for TDD workflows. This would give us both control and solved problems, but at the cost of understanding complex existing architectures and maintaining compatibility.
For a weekend project with livestream time pressure, Option 2 was the clear winner.
I’ve chosen bash as the implementation language. Why Bash? Simple: invoking claude code with it is as simple as:
claude_output=$(claude -p "$step-instructions") Clean separation between workflow logic (our Bash script) and AI execution (Claude Code). The orchestrator manages the TDD cycle, Claude handles the actual coding.
Rather than building a generic solution that could handle any language or testing framework, we locked in on JavaScript with Vitest. This constraint eliminated complexity of setting up the development environment for the agent and let us focus entirely on the TDD workflow. Each development session gets an auto-generated workspace with predefined configuration.
How It Went
The development unfolded live on YouTube across two intensive 2-hour sessions. Having Raul Rodriguez join the collaboration brought invaluable real-time feedback and problem-solving partnership that solo development simply can’t match.
The first challenge appeared almost immediately: the agent would sometimes get trapped in loops, generating long sequences of if-then-else statements that satisfied tests technically but missed the software design aspect. Interestingly, this is similar to how some human developers approach TDD when the problem is complex.
After several rounds of prompt refinement, we hit our breakthrough moment. The agent successfully completed the classic Roman numerals parser exercise, following proper TDD discipline throughout. Watching it write a failing test, implement just enough code to pass, then refactor for clarity—it was genuinely exciting to see the methodology come alive through AI.
We started tackling a chess move validator next, but our API credits ran out mid-development. A prosaic ending to what had become a surprisingly elegant demonstration, but the proof of concept was complete.
The Surprising Discovery
The most unexpected insight wasn’t about TDD at all—it was about CLI coding agents as building blocks for custom workflows.
We’d stumbled onto something bigger than a TDD agent. The pattern we’d created: Bash orchestration + AI CLI execution, revealed how accessible it is to build specialized development workflows. You don’t need to understand complex AI architectures or build sophisticated integrations. You just need to think clearly about your process and translate it into a series of focused AI interactions.
This matters because it democratizes AI-assisted development patterns. Instead of being limited to whatever workflows existing tools provide, developers can now create precisely the automation they need. The barrier between “using AI tools” and “building AI workflows” has essentially disappeared.
The orchestration pattern scales beyond TDD too. Code reviews, documentation generation, architectural analysis—any disciplined development practice can potentially be automated using this same approach.
Resources
- The complete code is available on https://github.com/jaksa76/tdd-coding-agent
- Here are the youtube sessions: Part 1 and Part 2
Special thanks to:
- Raul Rodriguez for transforming this from a solo experiment into genuine collaboration
- Kent Beck and Steve Freeman for the tips.
- The YouTube audience for moral support and real-time feedback