# How I Build Mieru with Claude Code Agents
Mieru is my side project: privacy-first web analytics for small sites, with a 1 KB tracking script, no cookies and one page of numbers. Under the hood it’s a FastAPI ingest service, a Redis stream, a writer that moves events into ClickHouse, and the ops to run it all on one server. The code and docs are public at github.com/AntonBurduzha/mieru.
Most of the code is written by Claude Code. Every task goes through one command, /task, which takes it from a spec to a single commit. Separate agents write the tests, review the diff and verify the result. I keep two gates: I approve the spec before anything is built, and I test the result before anything is committed.
The whole setup is checked in under .claude/: the /task skill with its spec template, three agent definitions (test-writer, reviewer, verifier), two hooks and settings.json. The process is written up for people in docs/workflow.md, and nothing in it depends on Claude Code. The spec is the contract, and its commands are ordinary shell commands.
Run 1: the spec and gate 1
I start with /task T07. Claude reads the task’s roadmap row, the feature entries, the architecture docs the task touches, the conventions and the code it will change. Then it writes docs/tasks/T07-<slug>.md from a template:
- a goal in one or two sentences;
- scope, with an “Out” list that names the task that does the rest;
- the exact files it may change, docs included;
- interfaces with their real names;
- acceptance criteria, each ending in an
auto:command that fails when the criterion is broken, orhuman:steps I can follow.
That last rule does most of the work. A vague criterion has no command to attach, so it shows up at gate 1, before any code exists.
The run then asks me to approve, and I can edit the spec file while the question waits. My checklist: clear scope, specific allowed files, observable criteria, a proof of done that proves each criterion, and a size of about 300 changed lines for an agent task. Bigger tasks get split. On approval, Claude creates the branch, sets the status to build, and commits the spec on its own.
Tests first, from a separate agent
The test-writer agent writes at least one test per auto: criterion. It may only write in the test folders, and only files the spec allows. Its instructions also say the tests must fail for the right reason: a failed assertion, or an import of a name the spec says will be created. A typo or a broken fixture is its own bug to fix.
The main session then checks that git status shows only test files besides the spec, and that every criterion has a test. Keeping this agent separate means the implementer can’t quietly fit the tests to its own code. Tasks with nothing to test in Python, like shell or CI work, skip the step and the spec says why.
The build, then review in a fresh context
The main session writes the code inside the allowed files, runs lint, types and tests until they’re green, and updates the docs the spec lists. If it needs a file outside the list, it stops and asks.
Then the reviewer reads the change. It starts with a fresh context, so it has none of the reasoning that produced the code, and its tools are Read, Grep, Glob and Bash, so it can’t edit anything. It reviews git diff main against the spec and the conventions in a fixed order: correctness, privacy, tenant isolation, security, reliability, conventions, tests, docs, scope.
Some checks are specific to Mieru. No IP address, user agent or request body may reach logs, Redis or the databases, and every query on tenant data has to be scoped by org_id or site_id. A generic bug-finding review wouldn’t know those rules, so I run Claude Code’s /code-review only as a second opinion.
Each finding gets a severity, a file:line, a concrete scenario and the smallest fix:
Must-fix: <n> · Should-fix: <n> · Nit: <n>
1. [must-fix] path/to/file.py:42: <what breaks, the scenario>. Fix: <smallest change>.2. [should-fix] .../task applies every must-fix and should-fix finding, runs the checks again, and leaves the nits to me (/task T07 apply nit 2).
The verifier can’t make a check pass
The verifier is the second read-only agent. It runs the standard checks, every auto: command, the proof of done and the feature checks from docs/features.json. It also checks scope (every changed file is on the allowed list) and test integrity (no test removed, skipped or loosened without a written reason). It only counts a criterion as proven if it ran the command in that session and saw it pass.
VERDICT: DONE | FAIL | NEED_HUMAN
| # | Criterion | How | Result | Evidence ||---|-----------|-----|--------|----------|| 1 | <short> | auto | pass | `<command>` exit 0: "12 passed in 0.8s" || 2 | <short> | human | unconfirmed | needs the developer: <steps> |On FAIL, the main session fixes the cause and verifies again. After three FAILs in a row it stops and shows me the report’s “To reach DONE” list.
NEED_HUMAN means nothing failed, but something needs a person: a server check, a GitHub setting, or a criterion too vague to run. In T04, the automated deploy, the agents ran shellcheck, actionlint and the scope check, and the verifier returned NEED_HUMAN for the criteria that needed the real server and the GitHub settings. I ran those and pasted the output into /task. The last criterion was proven by the merge’s own CI deploy.
The debug map and gate 2
Before handing over, Claude adds a “Where to debug” table to the spec: three to five places where the task’s behaviour is decided, each with a file:line, how to reach it and what to look at. The line numbers are checked against the code on disk. In T06, the ClickHouse schema task, one row points at ch_migrate.py:72, where the migration runner decides which files are pending, and names the test to run under the debugger to get there.
The status becomes test. I read the whole diff in Cursor, run the “Test it yourself” steps, and step through the parts I want to understand. If something is wrong, /task T07 <what's wrong> sends it back: Claude reproduces it in a test, fixes it, and runs the reviewer and verifier again.
Run 2: one commit, and I push
When it works, I run /task T07 again, which means “I tested it and it works”. It confirms the DONE verdict, flips passes to true in features.json only for features whose check the verifier saw exit 0, sets the status to done, makes the task’s one commit and writes the PR description to .git/pr-T07.md.
Claude never pushes. The project settings deny it:
"deny": [ "Read(./.env)", "Read(./**/.env)", "Read(./**/*.pem)", "Bash(git push)", "Bash(git push *)", "Bash(ssh *)", "Bash(rm -rf *)"]I push, CI runs lint, types and tests against real databases, and I merge.
On top of the deny list, protect.sh runs before every Bash, Edit, Write, Read, Grep and Glob call. It blocks .env files, private keys, DROP TABLE, deleting Docker volumes and git reset --hard, whatever a prompt says. format.sh formats every file Claude writes.
State lives in the spec
Each task’s status (todo, spec, build, test, done) is kept in the spec’s frontmatter and its roadmap row. /task reads it and continues from there, so a run can stop mid-build and pick up the next day.
Every task also leaves a record. The spec’s Review section holds every verdict and finding, and what was done about each. T01 had 15 acceptance criteria, each ending in a command, and finished with 61 tests at 97% coverage, merged as PR #6.
Between the two gates the loop runs without me, and my time goes into the spec and my own test. I haven’t measured tokens per task yet. Some tasks also run in human mode: the pipeline, the data model, auth and infrastructure, the parts I need to explain and defend myself. There /task writes me a tutorial instead of the code, then reviews and verifies what I wrote.
The full workflow and the agent definitions are in docs/workflow.md.