Skip to content
~/series/ai-native-software-engineering/repo-harnesses-and-agent-instructions
EST: 28mSECTIONS: 11SKILLS: 5

Lesson 1 · AI-native software engineering

28 min readIntermediate

Repository harnesses and agent instructions

Configure AGENT.md, CLAUDE.md, repo indexing, skills, and deterministic operating instructions for autonomous coding agents.

What is a repository harness?

A repository harness turns a passive codebase into an agent-executable workspace. Autonomous coding agents do not possess innate institutional memory or contextual intuition about your architecture. Left unguided, they invent conventions, edit forbidden files, break build scripts, and wander across package boundaries.

A repository harness provides four foundational contracts:

1. Root instruction files (AGENT.md, CLAUDE.md, .cursorrules) that establish role, architecture boundaries, and operating laws.

2. Deterministic command interfaces: exact, single-command recipes for building, testing, linting, and running migrations.

3. Invariant boundaries: explicit lists of immutable files (e.g. database migrations, core auth tokens) that agents must not touch without manual approval.

4. Modular agent skills: task-specific instruction bundles and custom CLI tools discovered and loaded on demand.

Why harnesses matter

An agent without a harness requires continuous human steering on every turn, burning engineer time and token budgets on trivial corrections. A well-constructed harness establishes high-autonomy execution: the agent independently inspects project conventions, verifies changes with local linters and tests, and adheres to architectural boundaries before submitting a pull request.

Repository harness anatomy

Production harness structure:

Repository root:

├── AGENT.md / CLAUDE.md (System instructions: architecture, test recipes, semantic style rules)

├── .agents/skills/ (Modular task-specific skill folders with SKILL.md and tools)

├── scripts/ (Deterministic validation gates: check-types, lint, test-fast)

├── repo-index.json (AST symbols, file routing, and dependency maps)

└── Application code (Bounded packages with explicit interfaces and test fixtures)

Repository instruction harness

AGENT.md
# Repository Operating Contract for AI Agents

## Operating Boundaries
- Modifying files in `src/core/auth/` or `db/migrations/` is strictly prohibited without explicit human approval.
- Use semantic design tokens from `src/app/globals.css` (e.g. `bg-background`, `text-muted-foreground`). Never inject raw hex values.

## Deterministic Verification Commands
Before submitting any code change, execute these commands in order:
1. Lint check: `bun run lint`
2. Type check: `bun x tsc --noEmit`
3. Unit test suite: `bun test`

## Commit and PR Format
- PR titles must follow conventional commits: `feat:`, `fix:`, `refactor:`.
- Link affected issue number in the PR description.

Experiment: harness guidance

Observe how repository harness configuration affects agent task completion rate and boundary violations.

Select harness configuration and task type. See success rate.

What to observe

The most effective harness instructions are operational and deterministic rather than conversational. Exact command invocations, concrete file glob boundaries, and explicit verification criteria yield far higher compliance than abstract stylistic guidelines.

Production harness engineering

Keep root instruction files concise (under 2,000 words to conserve context window tokens and protect prompt cache hit rates). Delegate deep, domain-specific workflows to modular skill files loaded on demand. Pin deterministic test and lint commands in package scripts, and version harness instructions in git alongside application code.

Challenge

An autonomous agent tasked with updating an API handler rewrites a shared database migration file, breaking staging. Design an AGENT.md operating contract that establishes an immutable file boundary around migrations while providing a deterministic sandbox test command.

Production checklist

Production checklist

0 of 6 checked

Key takeaway

Repository instructions are included in the agent's prompt context on every invocation. Overly verbose instructions increase token bills, crowd out task context, and cause the model to miss critical instructions. Keep root instructions under 2,000 words and modularize skills to maintain high attention and cost efficiency.

Complete

You can now build production repository harnesses for autonomous agents. Next: spec-driven agentic development.

Mark this chapter as complete

Track your progress and unlock the next chapter.

Email updates

Get the next chapter and new guides by email.

One email per substantial release. Unsubscribe in one click.

We will email you a confirmation link first, then send an occasional email when a substantial guide is published. Unsubscribe in one click. Stored with our email provider (Resend), never sold or shared. See the privacy policy.

Continue learning