Skip to content
Bernhard GötzendorferAI automation that runs on its own · Vienna
FoundationAI Deep Dives

What Is an AI Harness? Context, Rules and Checks

An AI harness guides coding agents with context, rules and checks. I show you my setup with CLAUDE.md, handovers and quality gates.

Technical blueprint: a guide rail holding one deep ink-blue block in position.

What Is an AI Harness for Coding Agents?

An AI harness is the system of context files, rules, handovers and automated checks that guides a coding agent in its work.

A session ends partway through an API change. The handover says what's done and which test still needs writing. The next session can pick up right there.

My CLAUDE.md holds the commands and architecture decisions the agent needs for the project. Rules for specific tasks live in their own files. I put information that applies to later sessions in memory. I put what's still open on a change in the handover.

What Goes Into an AI Harness?

  • Project context. Write down where the agent should start and which commands it uses to check its work.
  • Rules with examples. Show the agent what an API response should look like and where it might differ from the rule.
  • Handovers. Record what's done, what's still open and where the next session should pick up.
  • Checks. Define which type checks, builds and tests run before a deploy.

The API rule file shows how apiResponse returns an error. A response straight from NextResponse.json() would break that format.

Layer 1: CLAUDE.md as the Main Document

CLAUDE.md is the first thing the agent reads. It must be short, precise, and current. In my project, it contains:

  • Commands: bun dev, npm test, tsgo --noEmit. The agent needs to know how to verify the code.
  • Stack: Next.js 16.2.1, React 19, TypeScript 5.9, Tailwind 4. No guessing.
  • Architecture: Three Supabase client patterns (Browser, Server, Admin). Who uses what when.
  • Quality Gate: tsgo --noEmit && bun run build && npm test. Before every deploy.

A common mistake: CLAUDE.md gets too long. Stuffing everything in, 500 lines. The agent skims it and forgets half. My solution: stay under 100 lines. Everything detailed lives in the Rules.

Layer 2: Rules as Domain-Specific Standards

Files in .claude/rules/. Each covers exactly one topic:

  • error-handling-catch.md: No .catch(() => {}). Every catch must log.
  • api-response-consistency.md: All API responses via apiResponse.*(). No raw NextResponse.json().
  • test-colocation.md: Tests belong in __tests__/ directories next to the source.
  • voice-consistency.md: First-person "I" perspective, no "we" on the website.
  • content-writing-standards.md: No em-dashes. No AI buzzwords.

The key: each rule contains not just the rule, but also anti-patterns and correct examples. An agent that only reads "Use apiResponse" still makes mistakes. An agent that sees a concrete WRONG and CORRECT example makes the right decision.

Layer 3: Session Handovers as Memory Bridges

After every session, I write a handover document. Each handover contains:

  • What was done (commits, changes)
  • What's open (open issues, known bugs)
  • Next steps (prioritized)

The next session's agent reads the handover and immediately knows where to start. Without handovers, the next session could start from zero and redo completed work.

Layer 4: Automated Quality Gates

Humans forget things. So do agents. That's why I automate everything that can be checked:

  • TypeScript: tsgo --noEmit. 0 errors as baseline. Non-negotiable.
  • Build: bun run build. Missing translations, broken imports, everything surfaces here.
  • Tests: Regression tests for the relevant behavioural contracts.
  • Content checks: Automated checks for em-dashes, AI buzzwords, i18n parity, CTA repetitions.
  • ESLint: Custom rules against console.log (PII leak prevention) and error.message in responses (SEC-015).

The quality gates run before every deploy. The agent cannot deploy without all checks being green.

Common Failure Modes Without a Harness

Examples of what can happen without a harness:

Context Drift: Session 50 starts using patterns that session 30 already replaced. Without rules, there's no reference for what's "current."

Hallucination Accumulation: The agent invents a function that doesn't exist. Without quality gates, this only surfaces in production.

Architecture Erosion: Each session makes small deviations. After 20 sessions, you have five different error-handling patterns in the same project.

Repeated Mistakes: The agent makes the same mistake as 10 sessions ago. Without feedback memory, there's no learning effect.

What Worked in the Project

A few patterns that proved themselves. These lessons connect directly to the broader journey from prototype to shipped product, something I wrote about in From 250+ Prototypes to Product.

  1. SSOT files for everything that can change. Prices, biographical facts, service definitions. One file, one truth. The agent doesn't invent, it looks up.

  2. Composable middleware instead of copy-paste. withErrorHandler(), withAdminAuth(), withRateLimit(). Three wrappers that combine freely. Less repeated code across routes.

  3. Rules with "why." Not just "Use apiResponse." But: "Because raw NextResponse.json() produces inconsistent error shapes and breaks the tests." Agents that know the "why" apply rules correctly even in edge cases.

  4. Feedback memory as a learning loop. When the agent makes a mistake and I correct it, I save that as memory. Next session: same mistake doesn't occur.

The Harness Grows With the Project

A CLAUDE.md can grow into a system of rules, handovers, memory and automated quality gates.

The harness isn't a project you set up once. It grows with every problem you solve. Every mistake that occurs twice becomes a rule. Every architecture decision that needs context becomes an SSOT document.

From Agent Workflow to Business Workflow

I describe how a prototype becomes a system you can run in From 250+ Prototypes to Product. My way of working shows how I split up and check the coding agents' work. The Claude Code Capabilities course covers subagents, skills and hooks.

I wrote about how the harness helped me build an agent in my BitGN PAC Hackathon recap.

An invoice arrives by email. Who checks the amount? Where does it need your go-ahead? See how these workflows fit together under Automation for your business. The What you get page lists the outcomes and workshops.

Common questions

What is a harness in AI?

A harness gives a coding agent context, rules, handovers and automated checks for its work on the project.

What goes into the CLAUDE.md?

In my project, it holds the commands for checking the code, the stack in use and architecture decisions. Detailed rules live in separate rule files.

How does an AI harness keep track of state between sessions?

I use memory for information that applies across sessions. In the handover, I document completed work, open items and next steps.

Which checks belong to a harness?

In my project, they are type checking, build, tests and content checks. They check the work before a deploy.