Build your own software factory on Claude Code: codeagent's design, read from the code¶
I typed a three-line idea for a weather page into Claude Code. One hour and fifty-three minutes later the product had its own GitHub repo with 14 merged pull requests, 7 ticket issues, a VERIFIED report and a release candidate passing its smoke test in QA. Production waited for me to merge one more pull request.
The factory that did this is called codeagent. This post explains the idea behind each part, why it's there and what goes wrong without it, so you can design your own version. I've left the code out, and each section links to the files if you want to read them.
What codeagent is built from¶
codeagent is public at pkhamdee/codeagent. It's a Claude Code project folder with about 6,600 lines of instructions and scripts, and no service of its own runs anywhere.
Four kinds of parts do the work:
| Part | What it is | Why it's there |
|---|---|---|
| Skill | Written instructions for one kind of work | Tells an agent how to do a stage well |
| Subagent | A separate Claude session with an empty memory | Keeps one stage's clutter out of the next |
| Script | A small program that always behaves the same way | Checks the work, so nobody relies on an agent's word |
| Hook | A check Claude Code runs before every action | Blocks actions an agent must never take |
Most skills are blended from four collections: pstack, superpowers, mattpocock/skills, and my own software-factory-agent. The skill map records what came from where.
The pipeline: twelve stages, four pull requests you merge¶
You start it with one command in Claude Code, from the codeagent folder:
Each blue box in the diagram is a separate subagent working on its own branch. Between two boxes a script decides whether the stage passed, and another script merges the branch by pull request. You show up four times, on GitHub.
The session you typed the command into becomes the conductor. It starts the subagents and runs the checks, and it writes no product code itself.
Six design rules, and why each one exists¶
Skills are written instructions, and a model can skip a line of its instructions. So every rule that matters is also enforced by a script or a hook. When you build your own, ask of each rule what happens on the day the agent ignores it.
1. A script decides whether a stage passed¶
An agent can report that its work is finished when it isn't. When a subagent hands back its work and says it passed, the conductor ignores that and runs a check called a gate. The next stage starts only if the gate agrees.
Before a ticket's code can be merged, its gate wants to see four things:
- Every acceptance criterion is ticked, or has a written reason why it isn't.
- A reviewer who didn't write the code has signed off on it.
- The code hasn't changed since that review.
- The product's own tests pass.
The third check closes a gap where a builder gets approval and then edits the code. The fourth has a risk of its own, because an agent wrote those tests too. The gate runs them without your GitHub login or cluster access, and with a time limit.
Here the ship gate refuses a release because v0.1.0 has already shipped. The deploy gate passes.
Code: gate.sh
2. Every unit of work gets a fresh context¶
A long conversation fills up with old errors, abandoned ideas and file contents, and the model has to work around all of it. codeagent starts a new subagent for every stage and every ticket1. Its only memory is the repo, the issues and a short prompt.
When it finishes, it reports back in six lines: what it did, its commits, the gate result, decisions a person should look at, facts a later stage needs, and anything blocking it. The limit came from myweather, the test product described below. Its free-form reports ran well past 15 lines and stayed in the conductor's memory until the end.
Review works the same way. The builder never reviews its own change, because it already believes the change is right. A separate reviewer gets the ticket, the spec and the change, and none of the builder's reasoning. On myweather, reviewers caught real defects in 4 of the 7 tickets, including a server crash and credentials shown in an error message.
Code: stage-runner.md, reviewer.md
3. Agents decide and write it down¶
No one is in the chat during a run, so a question would stall it. When the idea leaves something open, the agent picks an answer, records what it costs if that answer is wrong, and moves on. You read those decisions later. myweather ended up with 149 rows of them.
Four things do stop an agent: an action that can't be undone, anything security-sensitive, an effect outside its own branch, or a stage so broken that every way forward is a guess.
This only works if "done" is defined before anyone writes code. The first stage turns the idea into statements that can be tested. For myweather they included these:
- When the weather service is unreachable, the page shows a readable error message.
- The hourly table has exactly as many rows as the weather service returned.
The verify stage later checks them one by one on a fresh copy of the product. "Users can see the weather easily" would give it nothing to test.
Code: CLAUDE.md, frame-idea
4. Your approval is a merge¶
The factory stops four times and opens a pull request for you: the brief, the spec, the security review and the production release. Its own scripts refuse to merge them. I chose pull requests because you can answer from anywhere and the answer stays on record.
| What you do | What happens |
|---|---|
| Merge | Approved, and the next stage starts. At checkpoint 4 the merge is the production deploy. |
Comment /revise with notes | The stage runs again with your notes |
Comment /accept-risk with a reason, then merge | A critical security finding is accepted, with your reason on record |
Comment /reject with notes, then close | The release is refused and your notes become new tickets |
| Close | The factory stops |
Your words are stored exactly as you wrote them and given to every later stage. I learned that one on myweather. I wrote that some security suggestions were "not built", the conductor shortened it to "optional" in its notes, and a later agent built one of them.
The factory also marks what it writes on GitHub with 🤖 codeagent. It was posting under my account, and I couldn't tell its comments from my own.
Code: checkpoint.sh
5. Limits are counted by scripts¶
An agent that retries its own failures can go on for hours and burn through your usage. Scripts do the counting, because a model can lose count when its conversation gets summarized.
| Limit | Default | What it prevents |
|---|---|---|
| Attempts per stage | 3 | Retrying the same failure forever |
| Trips from verify back to build | 3 | A product that never converges |
| Total runs per product | 60 | A surprise bill |
| Time per run | 90 minutes | An agent that hangs |
| Sessions per product | 1 | Two conductors changing the same code |
From the second attempt on, the agent has to look for the cause before it tries another fix.
The other limit is on what agents may do. A guard checks each command or file edit first2. If a factory agent is asking, the guard refuses to push code, merge, deploy or touch your tokens. Your own session has far fewer restrictions.
The last refusal in that picture comes from a real mistake. An agent stopped its test server by killing every process on the machine with a matching name. Its instructions already said not to, and it skipped that line, so I moved the rule into the guard.
The guard catches mistakes by recognizing commands. An agent determined to get around it could, and the README says so.
Code: guard.py, factory.toml
6. Build once, promote the same bytes everywhere¶
If you rebuild the product for production, you ship something QA never tested. codeagent builds one image per commit and uses that same image in QA and production.
What runs where is written down in a separate Git repository, the fleet repo. Flux, a tool that keeps a cluster in line with a Git repository, reads it and applies the changes. Moving a version to the next environment is a pull request there, so the Git history shows every release and who approved it.
After each deploy the factory tests the running product. If production fails that test, it puts the previous version back (if there is one) and tests again. My test product went through this twice:
A rollback never touches data. A product with a database has to keep its schema changes compatible with the previous version.
Code: promote.sh
The same factory on a laptop or a Linux server¶
I built codeagent on a Mac. It now also runs on a Linux server, and a product needs no changes to move between them. The product doesn't know its own web address, because the platform fills it in at deploy time.
| Mac | Linux server | |
|---|---|---|
| Kubernetes | Rancher Desktop | k3s |
| Product address | http://myweather.localhost | https://myweather.apps.example.com |
| Who can open it | You, on that machine | Anyone who can reach the server |
Some skills still assumed the laptop after the move, and one of them broke. Skills now ask a script where they are running, so each machine's settings live in one place.
Merge checkpoints from your phone¶
On a machine that stays on, start Claude Code's Remote Control in the factory's folder and you can run /factory from the Claude mobile app3. The work still happens on your machine, and you merge the checkpoints in the GitHub app.
Merging a production release deploys it even if no Claude session is open. An optional watcher covers that case. It checks every five minutes and does the testing and any rollback itself.
The myweather run, from idea to production¶
The idea file asked for a web app that gets the weather from the Open-Meteo API and shows the result as a table on a page. It named the exact API request to use and nothing else.
The run took 15 stage runs: frame, spec, security, tickets, 7 builds, verify, deploy, ship and the retro. No gate failed, and verify passed on the first cycle. One caveat: myweather ran just before I moved checkpoints to pull requests, so I approved its four checkpoints in the Claude Code session. I proved the pull request path afterwards on a throwaway product, including a /revise comment, two production rollbacks and a hotfix.
Every stage and every ticket ended up as a merged pull request:
The first ticket builds no features. It sets up the tests, the CI and a secret scan, so every later ticket is checked from its first commit.
The idea was accepted at 21:45 (UTC+7), dev went live at 23:31, the release candidate passed QA at 23:39, and production went live at 05:37 the next morning, once I approved it.
It's a plain page, which is what the idea asked for.
Build your own, step by step¶
You don't need all of codeagent to get most of the benefit. If I started again I'd build it in this order, and each step works without the ones after it.
| Step | What to build | Why it comes here |
|---|---|---|
| 1 | A factory folder, with products kept outside it | An agent working on a product can't damage the factory by accident |
| 2 | One stage skill and its gate, written together | Whatever the skill promises, the gate checks |
| 3 | A fresh subagent per stage, with a short report | Long runs stay accurate |
| 4 | A conductor skill that only orders the stages | One place knows what happens next |
| 5 | The guard, with its own tests | It has to exist before you leave a run alone |
| 6 | Checkpoints as pull requests | You can approve from anywhere, on the record |
| 7 | Production | It needs the most setup |
| 8 | A retro after each product | The factory learns from its mistakes |
Four of these have a detail that's easy to miss:
- Gates (step 2) must say why they failed. That message is what the next attempt works from.
- The conductor (step 4) should pass file paths and issue numbers to its subagents. If it pastes whole documents into 15 prompts, it runs out of room halfway through a product.
- Checkpoints (step 6) should accept answers only from people you name. If the factory uses your GitHub account, also block its agents from commenting on pull requests, or one could approve its own work.
- The retro (step 8) should propose changes and leave the decision to you. myweather's retro proposed 7, I applied all 7, and most of them moved a rule out of the instructions and into a script.
What you need¶
- Claude Code
- A GitHub account, with
git,jqand theghcommand-line tool (2.94 or newer) - For production only: the
fluxtool, and a Kubernetes cluster with Docker beside it (Rancher Desktop on a Mac, or k3s on Linux)
Costs and limits¶
- Every stage is a full agent session. myweather used 15 of them for a page with two tables.
- The guard stops mistakes. It doesn't contain an agent that is trying to get out.
- Without its own GitHub account, the factory acts as you. A separate account fixes that, but I haven't tested that setup with a real second account.
- Each run lives on one machine. Sleep, network drops and usage limits all stop it, and
/factorywith the product's name picks it up again.
Summary¶
The pattern to copy is that skills say how to do the work, scripts check that it was done, and GitHub keeps the record.
| If you worry that... | Build this |
|---|---|
| an agent says "done" when it isn't | a gate script that decides |
| quality drops during a long run | a fresh subagent for every stage and ticket |
| an agent approves its own code | a separate reviewer that never sees the builder's reasoning |
| the factory builds the wrong thing | four checkpoints that wait for your merge |
| it loops forever | limits counted by scripts |
| it pushes or deploys on its own | a guard that checks every command |
| production differs from what QA tested | one image per commit, used everywhere |
- Pick one stage, and write its instructions and its gate together
- Add the guard before the first run you leave alone
- After each product, find the rule an agent skipped and move it into a script
-
Anthropic, Create custom subagents: each subagent runs in its own context window and is defined in a markdown file. ↩
-
Anthropic, Hooks reference: a
PreToolUsehook runs before a tool call and can block it, and its input says which subagent made the call. ↩ -
Anthropic, Remote Control: connects the Claude app for iOS and Android to a Claude Code session running on your machine, which has to stay on with the
claudeprocess running. ↩
Discussion
Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.








