Saltar al contenido

AI harness: how we cut the cost of our coding agents by 24%

A coding agent like Claude Code in a five-minute demo looks like a brilliant intern. In a real repository, with hundreds of thousands of lines, it looks more like a brilliant intern with amnesia. It remembers what happens in the current session well, but forgets the project's rules when the context fills up, rereads the whole history on every turn and, every so often, tries to push unreviewed code or touch a file with credentials.

The outcome is familiar: sessions that drag on, a context that degrades, an API bill that climbs and technical debt that grows unseen until the release review.

AI harness: an AI model surrounded by four controls (guardrails, context, model routing and verification)

The problem isn’t the model. Frontier models are within reach of any team, so everyone starts with the same capabilities. What separates the teams that deliver reliable code from those that pile up bills and technical debt is the AI harness they build around the model (commonly referred to as AI harness engineering). We sum it up in an equation:

Agent = Model + Harness

The model is a probabilistic reasoning engine: very good at proposing code, but it guarantees nothing. The harness is the deterministic software chassis that gives it hands (tools), memory (project state), routes (which model to use for each task) and brakes (controls that block what must not happen). A simple comparison: the CPU does the computing, but without an operating system nobody can use it safely. The model is the CPU; the harness is the operating system.

The golden rule of an AI harness: polite suggestions vs. hard blocks

The most common way to control an agent is to write rules in CLAUDE.md or AGENTS.md: «don't commit secrets», «run the tests before closing», «don't commit to main». They work in the demo. In a long session, with the context loaded with logs and files, the model tends to rationalise: it decides this exception doesn't apply or that it has already tested enough. A written rule is a suggestion. It is not a guarantee.

That is why we propose a simple design principle:

Whatever can be checked is checked by a deterministic script. The AI decides only what requires judgement. And every time a written rule is broken, it becomes an automated control.

A pre-commit hook (a script that Git runs automatically before each commit) that scans the diff, i.e., the changes, for API keys is a rule that the model cannot skip. A pre-push that requires green tests also does not depend on the agent remembering to run them.

The four pillars of a production harness

Diagram: Agent = Model + Harness. The 4 pillars of an AI harness: deterministic guardrails, context hygiene, model routing and independent verification

1. Deterministic guardrails (fail-closed by default)

A guardrail fails closed: if it cannot verify something, it blocks the action. A typical setup includes:

  • A pre-commit hook that looks for secrets and private data in the diff and blocks the commit if it finds any.
  • A commit-msg hook that requires traceability: every change must point to a task or ticket.
  • A pre-push hook that runs the tests and blocks the push if they fail.
  • Tool-use hooks that stop the agent from reading sensitive files or running destructive commands.
  • A merge blocked until an independent review mark exists that the agent itself cannot write.

2. Context and memory hygiene

There is a hidden cost in any long session: the agent rereads the entire conversation history on every turn. In published measurements of real Claude Code sessions, 96.8% of tokens went to rereading the history (32 sessions analyzed). Caching makes those rereads cheaper, but they still add to the bill and fill the context with information that is no longer relevant.

The answer is not to ban long sessions, but to reset them with judgement. We use /clear often, combined with a lightweight state-recovery script that injects only what is essential: active branch, task in progress, latest test result and next step. The rest is discarded. The agent picks up the work without dragging the whole session along.

Subscribe to our newsletter.

Get the latest insights on digital solutions, industry trends, expert articles, and upcoming events.

3. Model routing and isolated subagents

Not every task deserves the same model. Planning an architecture or reviewing a design decision requires high-level reasoning; writing a repetitive test or changing a template does not. That is why the harness separates roles:

  • A high-reasoning model in the main thread, which plans and reviews.
  • Faster, cheaper subagents to run bounded tasks, each on its own work branch.

Each subagent works in isolation, with a closed scope, and returns a result that the main thread validates. This way an error in one task does not contaminate the others.

4. Independent verification

An agent cannot mark its own homework. A reviewer who inherits the conversation where the code was written inherits its assumptions too. That is why review always happens in a clean context window, without the history of the session that produced the change. The reviewer receives the diff, the acceptance criteria and the project rules, and nothing else. Many of the errors the author misses show up there.

AGENTS.md and the harness, version-controlled in the repository

For all of this to scale, the harness lives in the repository itself, under version control. The rules are defined in AGENTS.md, an open standard that most coding agents understand (Claude Code, Codex, OpenCode and Cursor, among others), so they aren’t tied to any one tool. Skills, scripts, hooks and templates live alongside it: all in one place, with the same history as the code.

The advantage is that an improvement made once reaches every project. Each project only declares its own requirements in a small configuration file.

In short: AGENTS.md defines the rules, and the hooks and scripts make sure they are followed.

Results: 24.4% savings that pay for quality

Analyzing our internal engineering sessions (both local and in the cloud) against a baseline without harness controls, we recorded total savings of 24.4% in API costs, broken down as follows:

  • 17.6% from model routing: Sonnet for execution instead of Opus for everything.
  • 4.5% from context resets and state recovery.
  • 2.3% from deterministic scripts (Python and Bash) that read logs, roadmaps and the continuous integration (CI) status, instead of letting the model read huge files.

The most relevant figure is not just the savings, but what we reinvest them in. In fact, 19.5% of total spend was deliberately allocated to clean-context code reviews, bug fixes and automated retrospectives. The 24.4% savings comfortably exceed that quality spend: the harness pays for itself.

Why move from prompts to an AI harness

Tuning prompts has diminishing returns. A harness works the other way round: every control you add protects all future sessions across the whole team. If your team uses coding agents and still governs them with a rules file, the question is not whether you will have an incident, but when.

Stop fine-tuning prompts and start designing the harness. Rules that get broken become controls; tasks that can be checked become scripts; and decisions that need judgment become independent reviews.

If you want to understand how to connect agents to your systems, also read our article on Model Context Protocol (MCP) and how we apply AI in software development.

Want an AI harness for your team?

At Orienteed, we help organizations audit their AI workflows and deploy ready-to-use deterministic harnesses directly in their Git repositories. No external servers and no vendor lock-in. It’s how we build software ourselves: AI speeds up the work, and every change goes through deterministic controls and human review. Book a 30-minute session with our team and we’ll review your setup together.

Do you need to develop a digital solution for your business?

Contact us today here to start an incredible project together.