How we built a software factory that builds itself
Principal Engineer
Coding agents are changing how engineering teams work. Developers can now delegate substantial implementation tasks, often with several agents working in parallel. But producing more code is only useful if teams can keep up with the work required to get it into production: planning, testing, reviewing, fixing problems, and merging changes. A software factory coordinates this process, automating much of the work between an initial request and a finished change.
At CircleCI, we’ve been building our own software factory to help our engineers get more code into production without getting bogged down in the work between implementation and merge. We call it Chunk factory, and it’s become the main way our team ships code, including the code for the factory itself. Across the factory’s repositories, we’re now merging nearly eight times as many pull requests a week as we were over the summer, and the time it takes to get a change merged has dropped from around a day to under an hour.
Building Chunk factory has pushed us to solve some difficult engineering problems, from coordinating agents around an approved plan to helping them respond to feedback and recover from failures without constant human intervention. In this post, we’ll share how we built the system and what we’ve learned from running it. Our goal is to provide a useful reference architecture for building your own software factory, as well as some practical building blocks you can start using today to make agent-driven development more effective.
The results so far
Chunk factory is already making a substantial difference in how much work our engineers can ship. As we’ve expanded the system from automated review to coordinating more of the development process, we’ve seen improvements in both throughput and the time it takes to get changes merged.
-
40x more automated pull request reviews. Our review agent now handles hundreds of PRs a week across CircleCI, not just for the team building Chunk factory. So far, it’s reviewed more than 5,000 pull requests and approved nearly 3,900.
-
Nearly 8x more merged pull requests. Across the three repositories used to develop Chunk factory, weekly merges have increased dramatically. The factory is now responsible for opening roughly 80% of the pull requests merged in those repositories.
-
Median time to merge fell from nearly a day to under an hour. Changes are getting through review and into main much faster.
The reduction in merge time is particularly meaningful. Our agents were already capable of producing useful code, but getting changes reviewed, addressing feedback, and recovering from failures still required engineers to keep the process moving. Chunk factory is reducing the manual coordination between writing code and getting it merged, allowing more development work to reach completion without constant human intervention.
The building blocks behind Chunk factory
We didn’t begin by designing a complete software factory. Our engineers were already using coding agents to write substantial amounts of code, and like many teams, our pull requests were accumulating faster than people could review them.
To help clear the backlog, we built an automated review agent that could evaluate changes against repository rules and post approvals or actionable feedback directly to GitHub.
Getting through review faster helped, but engineers still had to manage the work surrounding each pull request. They needed to respond to feedback, rerun tests, resolve conflicts, and get changes back through review. As more agent-written code moved through the system, we wanted agents to handle those steps without requiring someone to coordinate every handoff.
Fortunately, we already had several of the capabilities we needed, each of which could be used independently of the factory:
-
Chunk sidecars give agents isolated development environments where they can build, test, and fix changes without interfering with other work.
-
Chunk CLI gives developers and agents access to those environments and tools for validating changes against a repository’s existing checks.
-
CircleCI Smarter Testing uses test impact analysis and parallel execution to help teams validate changes efficiently as development activity increases.
Along with our internal review agent, these gave us much of the foundation we needed. The missing piece was a consistent way to bring them together, rather than having every engineer build and manage their own agent workflows. We wanted a process that could keep moving even when tests failed or reviewers requested changes.
We built Chunk factory to manage that process. It takes an initial request, develops a plan for an engineer to approve, and coordinates agents through implementation, testing, and review. When something goes wrong, the factory routes the feedback back to the agents so they can address it and continue working toward a pull request that’s passed its checks and is ready to merge.
For more of the story of how our engineering teams rolled out coding agents and ended up building Chunk factory, read Senior Staff Engineer Dan Mullineux’s account over on the Confident Commit Substack.
How a change moves through Chunk factory
Chunk factory takes a change from an initial request to a pull request ready to merge. The engineer approves the proposed plan before implementation begins, while agents and automated checks handle much of the work that follows.
Every plan moves through five stages: Plan, Build, Validate, Integrate, and Merge. The factory keeps track of progress across those stages, controls which tasks agents can perform, and records what happens along the way. Each plan breaks the change into units, smaller pieces of work that a builder agent can implement, test, and commit on its own.
Engineers can follow the work without having to coordinate every step. The plan and its history remain available throughout the process, including what the agents have done, which checks have passed, and anything that needs attention.
Getting started with the Chunk CLI
Developers work with the factory through the Chunk CLI or the CircleCI web app. The CLI handles repository setup, plan creation, validation, and the local components that execute factory tasks. Most of the day-to-day interaction happens in chunk ui, where engineers review plans, leave comments, approve work, and follow agent activity.
Setting up a repository and starting a first plan takes four commands:
chunk init
chunk factory bootstrap
chunk factory plan "<describe the change you want to make>"
chunk ui
chunk init detects the repository’s test, lint, and formatting commands and installs agent skills and hooks for automatic validation. chunk factory bootstrap creates the configuration in .chunk/config.json and prepares a sidecar image containing the project’s development environment.
With the repository configured, chunk factory plan accepts a natural-language description of the change you want to make. For the examples in this walkthrough, we’ll use a simple request: create a vanilla html with hello world in it. Running chunk ui opens the terminal interface where an engineer can review the resulting plan and follow its progress.
Other commands, including chunk validate and chunk sidecar, provide direct access to capabilities that work independently of Chunk factory. Developers can use the Chunk CLI to validate changes or give coding agents isolated environments without running the complete factory workflow.
Plans can also start from the CircleCI web app, which provides a page for each plan with its current stage, design, comments, blockers, and approval controls.
Engineers can start a plan from the CLI, review or approve it in the CircleCI web app, and resume the associated Claude Code session when they want to work with the agent directly. The plan, decisions, and activity history stay with the work across these interfaces.
Plan: Agree on what to build
When someone submits a request, an architect agent turns it into a written plan before any code gets written. Every plan follows the same structure: the intended outcome, the design and relevant context, open questions, a worked example, and the individual units of work.
For our Hello World example, the architect specifies a single index.html file at the repository root, without separate CSS or JavaScript files. It also records why it chose that structure instead of placing the file in a subdirectory. There’s not much to debate in such a small example, but the same structure becomes much more useful when a change involves existing services, APIs, or architectural decisions.
The plan goes through an automated review before an engineer sees it. The engineer can then comment, ask questions, or request revisions. Approval happens in two steps: first the design, then the units of work.
Here, the reviewer has asked for the heading to appear in red. The architect revises the plan, automated review runs again, and the engineer can approve once the comment has been addressed. The discussion stays attached to the relevant part of the plan, rather than getting buried in an agent’s conversation history.
We didn’t always work this way. Early versions of Chunk factory could build directly from a prompt and open a pull request without requiring an engineer to approve the design. We removed those commands because too many important decisions were being reviewed only after the code had already been written.
A prompt can leave quite a lot open to interpretation, especially when it refers to an existing codebase. By the time the agent has turned its assumptions into a few hundred lines of code, correcting them can mean rebuilding the change and going through another round of review. Working through the design beforehand gives reviewers a chance to catch problems while they’re still easy to fix. The approach also reflects a broader principle of intent-driven development: agents should have a clear, reviewable understanding of what they’re trying to achieve before they start implementing it.
Build: Keep the work moving across agents and environments
Once a plan has been approved, the factory starts working through its individual units. Depending on the task, this can involve hours of agent work, with commits, tests, retries, and occasional rebases along the way.
One of the problems we had to solve was keeping track of all that activity. Agents might be running on an engineer’s laptop or inside a cloud environment, and we wanted plans to survive an interrupted connection, a laptop going to sleep, or a service restarting without somebody having to reconstruct what the agent was doing.
We built a cloud service we call the conductor to coordinate the process. It keeps track of each plan and decides what work should happen next, using a durable execution engine to preserve progress through restarts and interruptions. The conductor also controls which tasks agents can perform at each stage. During planning, for example, agents can read the repository but can’t modify code.
On the developer’s machine, a factory daemon requests tasks from the conductor and assigns them to the appropriate workers. Each plan gets its own Git worktree and branch, keeping the agent’s changes separate from the engineer’s checkout.
Each plan also gets a Chunk sidecar, a short-lived Linux microVM containing the development environment. Sidecars start from a snapshot image defined by the team, so agents can build and test against a consistent environment without interfering with other plans. The environment is deleted when the plan finishes. We can also run coding agents and the factory daemon inside the sidecar itself, allowing work to continue without relying on the developer’s laptop.
Sidecars are one of the reusable building blocks in this architecture. The factory handles creating and managing them as plans progress, but developers can also use Chunk sidecars directly to give agents isolated development environments. Teams can create reusable sidecar snapshots with their dependencies preinstalled, reducing setup work each time an agent starts a new task.
We use different agents for different parts of the work, with models chosen for their responsibilities:
| Agent | Responsibility | Model |
|---|---|---|
| Architect and planner | Design the change and break it into units without editing code | Claude Opus |
| Scout | Investigate the repository, CI results, and observability data | Claude Haiku |
| Builder | Implement one unit, commit the code, and run its tests | Claude Sonnet |
| QA | Review completed work before the plan moves forward | Claude Opus |
We’ve kept the responsibilities fairly narrow. The scout gathers information and reports what it finds rather than drawing conclusions on behalf of the builder. The builder works on one unit at a time and reports when it’s blocked rather than improvising around a problem it doesn’t understand. The factory can also use different scout and builder agents.
As the build progresses, chunk ui shows the active unit and a running log of the work being done, including when an agent claims a task, what it changes, and whether the unit completes successfully.
Keeping the workflow state outside the agents has made the system easier to operate as we’ve increased the amount of work running through it. We can restart workers, recover from interruptions, and investigate failures without losing the record of what’s already happened.
Validate: Catch problems while the agent is still working
Each unit goes through validation inside its sidecar before the factory opens a pull request. We want agents to discover and correct routine problems while they’re still working, rather than waiting for CI to tell them they forgot to run the formatter or introduced a lint error.
The first set of checks comes from the repository’s own validation commands, configured in .chunk/config.json. For example, the factory’s repository includes these linting and formatting checks:
{
"commands": [
{
"name": "lint",
"run": "task lint",
"role": "gate",
"timeout": 60,
"remote": true
},
{
"name": "format",
"run": "task fmt",
"role": "autofix",
"timeout": 30
}
]
}
A gate command must pass before the unit can move forward. An autofix command can modify files, which is useful for formatting and other mechanical changes that don’t require a language model to figure out how to fix them. The remote setting tells the factory to execute the command in the sidecar.
The same validation configuration can also be used outside the factory. Chunk factory runs checks inside sidecars, while developers and agents can use chunk validate to run their repository’s configured checks in their existing workflows. Teams can use that capability without adopting Chunk factory’s planning or orchestration system.
Our factory also runs reviews against prompts that the team defines in .chunk/reviews/. Each markdown file addresses a particular area of concern, such as API design or database migrations, and provides project-specific guidance for the reviewers.
The builder and reviewers work through any feedback until the unit has no outstanding comments. Once all units have passed their checks, the factory opens a pull request with a description linking back to the original plan.
Integrate: Run CI and work through failures
The pull request now enters the same CircleCI pipeline as every other change to the repository. Sidecar validation catches many routine problems, but integration still needs to be checked against the team’s established CI process, regardless of who or what wrote the code.
We’re using Smarter Testing to keep those runs manageable as PR volume increases. Test impact analysis identifies tests affected by a change, and dynamic test splitting distributes them across parallel containers. In the factory’s own repository, agent prompt files count as code dependencies, so changing an agent’s instructions triggers the tests that exercise them.
Smarter Testing works with ordinary CI pipelines as well as those used by software factories. As agents produce more changes, teams can use it to reduce unnecessary test execution while maintaining the validation needed before merging.
Automated review runs alongside CI. Our internal review agent posts its verdict to GitHub through the factory-bot account, using a combination of deterministic checks and model-based evaluation. These examine things like whether the change follows AGENTS.md, whether the implementation matches its stated intent, and whether it introduces unnecessary risk.
We spent time refining the approval logic because an individual check can’t always tell us that a change is good. Each check can pass, fail, warn, or skip. The agent approves only when at least one check passes and none fail. Checks that can confirm the absence of a particular problem, without establishing that the change is acceptable overall, return skip rather than pass.
The review agent also needs access to the same repository conventions that inform the agents writing the code. We’ve encoded much of that knowledge in shared instructions and plugins, making it available across engineering teams rather than leaving each agent to rediscover how a project works. For teams establishing similar conventions, we’ve also written about using AGENTS.md and agent skills together.
When CI fails or the review agent requests changes, Chunk factory sends the problem back to the plan as another task. The scout can investigate the failure, the builder can make a correction, and the relevant checks run again. Merge conflicts become rebase tasks handled through the same process.
We call these interruptions deviations, since they represent places where the implementation differs from what the plan expects. Engineers can see the deviations and how the factory is responding to them in chunk ui, the CircleCI web app, or in their Claude Code session without having to coordinate each retry manually.
When a problem is resolved, the factory picks up where it left off. The engineer can follow the work and see how the issue was handled, rather than having to restart the process or manage another agent session.
Throughout the process, agents use short-lived credentials associated with the person who started the plan, and the system records approvals. We also alert on attempts to manipulate the review agent into ignoring its checks. When CI passes and the review agent approves, the pull request is ready to merge. An engineer makes the final call and merges it. The factory watches the pull request, and once it merges, the factory closes the plan.
What we’ve learned from building and running Chunk factory
Most of Chunk factory’s current design came from fixing problems we encountered in earlier versions. Some involved agent behavior and the quality of the work they produced, while others were familiar software engineering problems that became more noticeable once agents were doing so much of the work.
Passing tests doesn’t always mean a change is safe
One of the incidents that changed our approach to validation involved an agent-written security update for a Go dependency. The update passed every test but still broke a release.
We had automated much of the mechanical validation, but the incident exposed a gap in how we evaluated the impact of a change. Tests can tell us whether the behavior they cover still works. They don’t necessarily tell us whether an agent made the right design decision or introduced a risk the tests weren’t written to catch.
We expanded our review checks to examine intent and risk, and moved more of that review into the sidecar before a pull request exists. An early demo of Chunk factory showed a change moving through the entire process without any problems, but a later demo where the first implementation failed and the reviewers caught it turned out to be more useful. It showed how the factory worked through a problem, which is where we’ve spent a considerable amount of our development effort.
Ordinary code is better at ordinary tasks
We initially gave agents responsibility for some tasks that didn’t really need a language model. Checking out branches, rebasing onto main, and updating pull requests all have well-defined implementations, and giving them to a model introduces unnecessary variability.
The factory daemon now separates tasks that require judgment from the ones we can handle with ordinary code. Local workers take care of Git operations and other mechanical steps, while agents focus on planning, implementation, investigating failures, and responding to feedback.
| Task | Needs judgment? | Who handles it |
|---|---|---|
| Check out a branch, rebase, update a PR | No | Local worker |
| Write or revise a plan | Yes | Architect and planner agents |
| Build a unit and address review comments | Yes | Builder agent |
| Investigate a CI failure | Yes | Scout, then builder |
For a CI failure, the scout gathers relevant information from the logs and repository, and the builder works out how to address it. Once the change is ready, a local worker takes care of the Git operations needed to update the pull request. The arrangement is faster and easier to debug, and it means we’re spending model time on work where reasoning is genuinely useful.
Running a factory means dealing with distributed-systems problems
One of the more frustrating problems we’ve encountered had very little to do with AI. Chunk factory is changing quickly, and because part of the system runs on each engineer’s machine, keeping those local clients in sync with the cloud service has become a challenge. We ran into trouble when a server update removed an API route that older clients still relied on. Engineers who were only a day or two behind on updates found that their plans had stopped receiving work, but nothing failed visibly enough to explain why. It looked like the agents had simply stopped making progress.
Once we figured out what was happening, the fix was straightforward: reinstall the client. Getting there took longer than it should have, partly because we hadn’t documented the upgrade process well enough. We now announce required upgrades to everyone running the factory, and we’re moving more of the execution into sidecars where we can control the environment and keep components in sync.
Interestingly, the clearest account of the problem came from the agent that encountered it. It produced a summary with trace IDs, a timeline, and a suspected cause that gave the team something concrete to investigate. As we’ve come to rely more heavily on Chunk factory for our own development, we’ve had to give its operational reliability the same attention we give the rest of our engineering infrastructure.
Making room for human judgment
One of the biggest improvements we’ve seen is how much less time engineers spend waiting for work to move forward. With coding agents alone, it’s surprisingly easy to spend the day supervising multiple sessions, responding to requests for feedback, and approving the next action. The agents may be working in parallel, but the engineer still has to keep each one moving.
Chunk factory gives engineers more room to focus by handling the work between decisions. They can approve a plan and let the agents work through implementation and validation without constant supervision. When it’s time to get involved again, the relevant context and results are available for review.
We’re also conscious of what happens as more work moves through the system. Our research on work in progress as a growing software delivery bottleneck shows how quickly work can accumulate when development activity outpaces delivery. Even with less time spent waiting, a growing number of plans and pull requests can create more decisions than engineers can comfortably manage. We’re building toward better visibility and coordination between plans, including ways to identify overlapping work before multiple agents spend time implementing it. We want engineers to have more control over the work reaching them, rather than simply inheriting a larger queue of decisions.
If you’re building your own software factory
You don’t need Chunk factory to apply what we’ve learned, and you don’t need to build every piece yourself. Most teams using coding agents already have some of the essentials in place. The question is how to connect those capabilities into a process that can keep work moving without requiring engineers to supervise every step.
We’ve learned that the individual components need to work well on their own before orchestration can add much value. A factory won’t compensate for unreliable environments or incomplete validation, and automating handoffs won’t help if nobody can see what’s already in progress. Based on our experience, there are a few areas we’d prioritize.
-
Make the plan the unit of approval. Ask agents to produce a structured plan before writing code, including the intended outcome, design decisions, open questions, and a worked example. Review the plan with the engineer responsible for the change, then use it as the basis for evaluating the implementation. Our factory uses an architect agent and separate design and unit approvals, but the principle can be applied to any agent workflow.
-
Give each plan an isolated environment. Multiple agents sharing a checkout, database, or test server can interfere with one another in ways that are difficult to diagnose. Separate branches and worktrees help keep source changes isolated, while a sandbox with a known development environment gives each plan somewhere consistent to build and test. Chunk sidecars provide that environment, started from a snapshot of the team’s setup, and can be used independently of the factory.
-
Validate continuously and keep CI as the integration standard. Agents should run the team’s established checks while they’re working and respond to feedback before opening a pull request.
chunk validateruns the repository’s configured validation commands, giving agents a consistent way to check their work before CI. The resulting PR should still pass the team’s normal pipeline, with CircleCI Smarter Testing helping validation keep pace as PR volume grows. -
Measure the waiting and the interventions. Time to merge is useful, but we’re also interested in how often an approved plan reaches a mergeable PR without somebody stepping in. When plans repeatedly get stuck, the problem may be unclear instructions, incomplete validation, or missing context rather than the coding agent itself. Tracking where engineers have to intervene helps identify which parts of the process are worth improving next.
We’d also recommend being deliberate about how much work is in progress and where people need to make decisions. Our engineers approve plans before implementation begins, and we’re building better visibility into the work already underway. As more plans run in parallel, coordination becomes just as important as automating individual tasks.
What’s next for Chunk factory
We’re bringing Chunk factory to AWS re:Invent, where we’ll be demonstrating the workflow from request through to a merged pull request at booth #1866 in the Venetian Expo.
Our goal is to make it easier for teams to assemble software factories that fit the way they work. We’ve already addressed some of the underlying problems with capabilities like Chunk sidecars and Smarter Testing, and we’re working to make more of the orchestration and workflow capabilities behind Chunk factory available for teams to build on.
We’re continuing to develop the system in three areas:
-
Multiplayer planning. We want plans to work more like pull requests that exist before the code does. Other engineers will be able to see what’s being planned, discuss the approach, and coordinate their work. If someone starts a plan similar to one already in progress, the factory could flag the overlap and suggest working together. Agents need to coordinate with other agents, but the people directing them need that visibility too.
-
Configurable workflows. Starting with an approved plan is the approach we’ve chosen for our own factory, but it doesn’t have to be the only way to use the system. We want teams to be able to assemble their own workflows using the underlying orchestration, workflow engine, and managed sidecars. A sidecar provides more than compute capacity: it’s a repeatable, isolated development environment that a workflow can create, use, and discard as needed.
-
Skipping redundant CI work. We’re working on a tighter handoff between the factory and CircleCI, so checks that have already passed in the factory can be recorded and reused rather than run again in CI. Smarter Testing reduces the amount of testing a pipeline needs to perform; this approach could avoid repeating validated work altogether, with the potential for even greater savings in CI time.
We’re learning a lot from using Chunk factory to develop itself, and we’re looking forward to seeing how other teams put these capabilities to work in their own development processes.
Join the Chunk factory waitlist to get access as we begin opening it up to more teams. In the meantime, you can sign up for a free CircleCI account and start using Chunk sidecars and Smarter Testing in your existing workflows to get agent-generated code into production faster.