The agentic software factory: Why it needs a harness

The agentic software factory: Why it needs a harness

Part 3 of 5: The Agentic Software Factory


At the end of Part 2 we had a factory floor. Bootable repo, written context, a standard task shape, isolated workspaces, gates, station definitions, permissions on paper, and a register. It works. It also depends on every agent session actually reading the station definition, actually respecting the scope, and actually running the gates before announcing, with total sincerity, that it’s done.

Most of the time, they will. “Most of the time” is not how you run a line. It’s how you run a lottery. This post is about the piece that turns rules on paper into rules that hold: the agentic harness.

What a harness actually is

A model by itself does exactly one thing. You send it text, it sends text back. That’s it. Everything that makes it an agent lives in the program wrapped around it:

  • The loop. Send context, receive a response, and if the response asks for a tool, run the tool and send the result back. Repeat until done.
  • The tools. Reading files, editing files, running commands, searching, calling APIs, talking to MCP servers.
  • The permissions. Which tools are allowed, on which paths, with which arguments, and which ones need a human to approve.
  • The context management. What gets loaded at the start, what gets summarized when the conversation gets long, what gets carried into the next session.
  • The hooks. Your own code that runs at defined points: before a tool call, after a tool call, when the agent tries to stop.
  • The limits and the record. Turn and time budgets, cost tracking, and a log of everything that happened.

That wrapper is the harness. Claude Code is a harness. So is every other coding agent CLI and IDE agent you have used. When people argue about which agent is “better,” a surprising amount of what they are really comparing is the harness, not the model. (The internet will not be told this. I’m telling you anyway.)

The reason this matters for a factory fits in one line:

A prompt is a request. A harness is a guarantee.

“Do not edit files outside src/orders/” in a prompt is something the model will usually follow. The same rule in the harness is something it cannot break.

How you could do it

There are four realistic ways to get a harness for your factory, from least to most work.

1. Configure the coding agent you already use. Most serious coding agents now expose the harness through configuration: permission allow and deny lists, hooks, subagent definitions, reusable skills, and project-level instruction files. In Claude Code that is .claude/settings.json, .claude/agents/, skills, and CLAUDE.md, all checked into the repo. This gets you a long way with zero custom code, and it is where I tell everyone to start.

2. Drive the coding agent headlessly from scripts. The same agents can run non-interactively. You hand them a prompt, a set of allowed tools, and a turn limit, and get structured output back. That turns each station into a command your automation can call:

claude -p "$(cat .factory/stations/reviewer.md) Task: #482" \
  --allowedTools "Read,Grep,Glob,Bash(make test)" \
  --max-turns 40 \
  --output-format json > review-482.json

Now a station is a process with an exit code and a JSON result. Your CI system or a small orchestrator can chain them, and nobody has to babysit a chat window.

3. Build on an agent SDK. When you want your own orchestrator, with stations as functions, custom tools, and your own state, an SDK like the Claude Agent SDK gives you the same loop, tools, permissions, and hooks that power the CLI, as a library. You write the factory logic. The SDK handles the agent mechanics.

4. Write the loop yourself against the raw API. You can. The tool-use loop is not complicated. But you will end up rebuilding file editing, context compaction, permission prompts, and sandboxing, and those are full of sharp edges that someone else has already bled on. I only go here for very specialized agents that do not touch a codebase.

My honest recommendation: start at 1, add 2 as soon as you want stations to run without a human pressing go, and move to 3 when the orchestration logic outgrows shell scripts. Skip 4 unless you have a strong reason, and “it’d be fun” is not a strong reason. (It is a reason. Just not a strong one.)

What I would put in it

Here is what my harness layer does for the factory, regardless of which of those four paths is underneath.

Load the station, not just the prompt

Each station has a definition file from Part 2. The harness loads it as system-level instructions, along with the root agent guide and the ADRs linked from the task. The agent does not get to decide whether to read the conventions. They are in its context before its first turn.

Enforce scope with a hook

The task issue lists the paths a writer may change. The harness writes those into the workspace when the station starts, and a hook checks every edit against them before it happens. In Claude Code that is a PreToolUse hook:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": ".factory/hooks/enforce-scope.sh" }]
      }
    ]
  }
}
#!/usr/bin/env bash
# .factory/hooks/enforce-scope.sh: block edits outside the task's scope.
path=$(jq -r '.tool_input.file_path' | sed "s|^$PWD/||")
while IFS= read -r pattern; do
  [[ -z "$pattern" ]] && continue
  [[ $path == $pattern ]] && exit 0
done < .factory/task/scope.txt
echo "$path is outside this task's scope. Stop and report what you need changed." >&2
exit 2

Exit code 2 blocks the tool call and hands the message back to the agent, which then either finds a way to stay in scope or stops and asks. That one hook prevents most of the “while I was in there I also refactored the auth module” diffs that eat review time. You know the ones. Forty files changed, two of them related to the ticket.

Refuse to stop on a red gate

The other hook I lean on runs when the agent tries to finish. It runs the fast gate, and if anything fails, it blocks the stop and feeds the failures back. The agent cannot report “done” with a failing test. No more “All tests pass! ✅” sitting directly above a wall of red. This is the single most effective quality control I have added, and it is about ten lines of shell.

Hold the permissions per station

The permissions from Part 2 become configuration. The planner and reviewer get read-only tools plus the test command. The implementer gets write access inside its workspace and the gate commands. Nothing in the line gets deploy credentials or production database access. Network access is limited to the package registry and whatever internal services the tests need. If an agent asks for something outside that, it is a human decision. I made the longer version of this argument in security was already a mess, and nothing since has made me less paranoid.

Budget every run

Turn limits, wall-clock timeouts, and a cost ceiling per task. When a run hits a limit, the harness stops it and records a checkpoint instead of letting it spiral. In the long-running agents post these were tripwires a human watched. In the harness they trip themselves. It’s the same leash I put on the research agent on a budget, just applied to every station.

Demand structured handoffs

Every station ends with a structured result: what changed, which gates passed, what is unresolved, and what the next station needs. JSON for the machine, a short summary for the human. The next station gets the handoff and the source files, not the previous agent’s whole transcript. That keeps each session’s context small, focused, and free of the last agent’s abandoned guesses and half-remembered theories.

Record everything

Every tool call, every hook decision, every gate result, every handoff, tied to the task ID. When something goes wrong, the Learn station needs evidence, and “the agent did something weird yesterday” is not evidence. It’s a campfire story.

The harness wraps the model: station definition and context go in, tools pass through permission and scope hooks, the stop hook runs the gate, and a structured handoff comes out

The benefits, concretely

You can run a factory without a harness layer. You will be relying on prompts and attention, and attention is the thing you were trying to free up in the first place. Here is what the harness buys you.

Rules become guarantees. Scope, permissions, and gates go from “usually followed” to “enforced.” That is the difference between hoping for consistency and having it.

Repeatability. Every implementer starts with the same context, the same tools, the same limits, and the same hooks. Two tasks of the same shape get handled the same way, whichever developer kicked them off and whichever day of the week it is. That is where consistency across a team actually comes from. Not from a wiki page titled “Best Practices (DRAFT) (v3) (FINAL).”

Humans review less noise. When the line has already blocked out-of-scope edits and refused to stop on red gates, the human at the integrate station sees changes that are on-plan and green. Their attention goes to design and behavior, which is where it is worth the most.

Safety you can explain. When a security reviewer or a compliance person asks “what can the agents actually do,” you can show them the configuration and the logs. “We told it not to” does not survive that conversation. “It cannot, here is the policy, and here is the audit trail” does.

Swappable parts. Because station definitions, hooks, and gates live outside any single model, you can change the model behind a station, or run two side by side and compare, without rewriting the factory. When a new model ships (so, Tuesday), you test it against the same line and the same evidence instead of against vibes.

Cost control. Budgets and smaller per-station contexts keep token spend predictable. Runaway sessions get stopped by the harness instead of discovered on the invoice. I went deep on the cost side in making LLM features cheap enough to actually ship, and the same math applies here.

A place to put lessons. When the Learn station finds a defect pattern, the fix is often a new hook or a new gate check. The harness is where the factory’s memory of its own mistakes accumulates.

A word on overbuilding

It is very easy to get excited here and build an elaborate orchestration platform, with a dashboard, a plugin system, and a logo, before the line has run a hundred tasks. Do not. The harness should grow in response to real leaks. Start with the scope hook, the stop gate, per-station permissions, and turn limits. Add the rest when a real failure tells you to.

On Monday in Part 4 we take the stations, now wrapped in a harness, and make the whole factory boot itself: environments, workspaces, agents, and queues, the same way every time, without someone typing the startup sequence from memory and a sticky note.