When you start programming with an agent in tools like Cursor, Codex or Claude Code, the first thing you notice is that it writes code very fast and guesses a lot. It does not know your project or your rules, and it does not remember what it did yesterday. Every session starts from scratch.
What fixes that is building an environment around it. You write down what you would explain to someone joining the team, and you add tests that tell it when it gets something wrong. That environment is called a harness. This post is the guide I wish I had read when I started, and you can use it as a base for building your own.
What harness engineering is
Harness literally means the gear you put on a horse. In the world of agents it is used to name everything around the model, and harness engineering is the practice of building and improving that environment so the agent works better. Birgitta Böckeler, from Thoughtworks, explains it very well in Harness engineering for coding agent users with the formula Agent = Model + Harness.
Part of the harness already comes built into the tool you use, like its system prompt or the way it searches for code. The part that is up to you is the external harness, what you add for your project. According to Böckeler, a good external harness raises the chance that the agent gets it right the first time and gives it a way to correct itself before you review.
She divides the pieces into two types.
- Guides. They act before the agent writes. They are the context and rules files, like
AGENTS.mdor a spec. - Sensors. They act afterwards and tell the agent if something went wrong. They are the tests, the linter, the typecheck or a code review.
If it only has guides, the agent follows your rules but never knows whether what it did worked. If it only has sensors, it finds out that something failed, but since nobody told it how to do it well, it makes the same mistakes again. That is why it is worth using both together.
Your job as a programmer is to keep improving that harness. When a mistake repeats, you add a rule or a test so it does not happen again. The rest of the post covers the pieces I use.
Later I talk about Spec-Driven Development, an optional complement that goes on top of the harness, but everything starts here.
AGENTS.md, the project rules
AGENTS.md is an open format that works like a README for agents. The README.md is meant for people and explains what the project is and how to start it. The AGENTS.md holds what an agent needs to work well, like the build and test commands, the conventions and the rules that cannot be broken.
It came out of the joint work of several coding agent teams (OpenAI Codex, Amp, Google's Jules, Cursor and Factory). Today it is maintained by the Agentic AI Foundation, under the Linux Foundation, and according to its site, in October 2026 more than 60,000 open source projects used it.
It has no required fields. It is plain Markdown with whatever headings you want, and the agent reads it as text. You create it at the root of the repository and that is it.
How to structure an AGENTS.md
These are the sections that come up most often, both in the official documentation and in the projects I have seen.
- Project summary. What it is, in two or three lines.
- Stack. Language, framework, Node or Python version, external services.
- Commands. How to install, run, test, lint and build.
- Folder structure. What is in each one and what should not be mixed.
- Conventions. Code language, style, commit and PR format.
- Hard rules. What the agent must never do without permission.
- Reference documentation. Links to
docs/for what does not fit here.
Keep it short. In my case the file itself says it should stay around 150 lines, and if something grows, it gets moved to docs/ and linked.
A real example
This is the AGENTS.md of my portfolio, trimmed so the idea is clear.
# AGENTS.md
Guía operativa y reglas duras para agentes trabajando en el portafolio.
## Resumen del proyecto
Portafolio interactivo con estética pixel art: secciones dibujadas en
Canvas por un motor propio, con personajes, mapas y un arcade.
## Stack
- Node.js >=22.6.0
- Next.js (App Router, TypeScript estricto, SSG)
- Canvas 2D con motor propio en engine/
- Tailwind CSS, MDX para el blog
- Español e inglés con diccionarios propios en src/i18n/
## Comandos
npm run dev # Servidor de desarrollo
npm run build # Build de producción
npm run lint # Linter y tipos
npm test # Pruebas
## Convenciones
- Código, commits y comentarios en inglés.
- Documentación (docs/, AGENTS.md, MEMORY.md, ADRs) en español.
- Todo texto visible va en los diccionarios, nunca directo en JSX.
- Lo que falta definir de diseño se marca como TODO(design).
## Reglas duras
1. Nunca hacer deploy, push a main ni instalar dependencias sin
autorización explícita en el mensaje actual.
2. Nunca inventar colores, tipografías, tamaños ni duraciones.
3. engine/ no importa React, hooks ni nada de components/.
4. Toda animación se puede saltar y respeta prefers-reduced-motion.
5. Leer MEMORY.md al iniciar la sesión y actualizarlo al terminar.
6. Mantener este archivo corto; lo que crezca va a docs/.
## Documentación de referencia
- docs/architecture.md
- docs/engine.md
- docs/testing.md
- docs/decisions/ (ADRs)
The hard rules are what helps me the most. If I do not write that the agent must not install dependencies, sooner or later it installs one. With the rule written down, it asks me first.
Where the files go
Everything lives at the root, next to the README.md, and this is what a project looks like with the guides I talk about here. The sensors, on the other hand, are the tests (code that checks that your code does what it should) and lint (a tool that catches syntax or style errors), practices that have become normal when working with agents, so in AGENTS.md you write down the commands to run them and with that the agent can check its own work on every change you ask for before handing it to you.
mi-proyecto/
├── docs/
│ └── decisions/ # ADRs (decisiones de arquitectura)
├── src/
├── AGENTS.md # Reglas y contexto fijo para cualquier agente
├── MEMORY.md # Estado del proyecto, se actualiza cada sesión
├── BRIEF.md # Qué se va a construir ahora y cómo se valida
├── HANDOFF.md # Relevo para el siguiente agente o la siguiente sesión
├── CLAUDE.md # (opcional) Apunta a AGENTS.md para Claude Code
└── README.md # Para personas
In a monorepo, the main AGENTS.md stays at the root with the rules that apply to the whole project. If a package has its own stack or its own commands, I recommend adding an AGENTS.md inside its folder too, for example in apps/web/ or packages/api/. It is optional, but it helps a lot. When the agent edits a file, it takes into account the nearest AGENTS.md together with the one at the root, so each package adds its details without repeating the general rules.
MEMORY.md, the memory between sessions
AGENTS.md barely changes. MEMORY.md changes all the time, because it holds the state of the project. The agent reads it at the start and updates it when each task ends, so I do not have to explain again where we left off.
Mine has four parts. A log of what was done with dates, the recent decisions (ten at most, the old ones go to the ADRs), the pending items and the open questions that need my answer.
# MEMORY.md
## Estado actual
- 2026-10-24 · Navbar fijo en la home. Queda fixed arriba, con un
espaciador del mismo alto. El blog no cambia.
- 2026-10-21 · La ruta del blog es /blog. /log redirige con 308.
## Decisiones recientes (máx. 10)
1. [ADR-0004] Animación basada en tiempo real, no en cuadros.
2. [ADR-0006] Sitio bilingüe con diccionarios propios, sin librería.
## Pendientes
- Docs desactualizados: docs/testing.md todavía dice que el
framework de pruebas está por decidir (ya es Vitest).
## Preguntas abiertas
- ¿Se agrega jsdom + Testing Library para probar clics en el DOM?
Write each entry as if someone who was not there is going to read it. Put file names, commands and the reason for each change.
BRIEF.md, what you are going to build
BRIEF.md describes a concrete task or feature before starting it. It is not an official convention like AGENTS.md, so each team builds it in its own way. The useful part is that it holds the goal, the scope, what is left out and the acceptance criteria, in other words, how you will know it turned out well.
# BRIEF: Formulario de contacto
## Objetivo
Que un visitante pueda mandarme un mensaje sin salir del sitio.
## Alcance
- Campos nombre, correo y mensaje.
- Envío por un servicio de correo transaccional.
- Protección básica contra bots.
## Fuera de alcance
- Adjuntar archivos.
- Panel para ver mensajes.
## Criterios de aceptación
- El mensaje llega al correo en menos de un minuto.
- Con un correo inválido se muestra un error en el campo.
- Pasan npm test y npm run lint.
A BRIEF.md like this is already a small spec. Further down I explain how to work with specs in a structured way.
HANDOFF.md, the handoff between agents
Sessions with an agent end. The context fills up, you switch tools or you simply want to start a clean chat. HANDOFF.md is the handoff note so the next agent can continue without losing anything.
Before closing I ask the agent to write it. The next agent reads it first and continues from there. Mine has these sections.
# HANDOFF
- Rama: main
- Último commit: 285a80d
- Fecha: 2026-10-21
## 1. Objetivo
Qué es el proyecto y qué se estaba haciendo.
## 2. Qué se implementó
Cambios concretos con la ruta de cada archivo tocado.
## 3. Decisiones técnicas
Qué se decidió y por qué.
## 4. Problemas y cómo se resolvieron
Errores encontrados y la solución de cada uno.
## 5. Pendiente
Lo que falta, en orden de prioridad.
## 6. Cómo ejecutar y validar
npm run dev / npm test / npm run lint / npm run build
The difference from MEMORY.md is the scope. The memory is the history of the project and grows over time. The handoff is a snapshot of the moment, meant so someone can pick up right where things left off.
Tests and verification, the sensors
The guides help, but the agent still makes mistakes, and the sensors are what catches them. Böckeler distinguishes between computational sensors, which are deterministic and fast like the tests, the linter and the typecheck, and inferential sensors, like asking another model to review the code. The computational ones are cheap and reliable, so it is worth running them on every change.
In practice, put the commands in AGENTS.md and ask the agent to run them before saying it is done. According to the agents.md site, if you list them there the agent tries to run them and fix what fails.
## Antes de terminar una tarea
- npm test # todas las pruebas pasan
- npm run lint # sin errores de linter
- npm run typecheck
- Reporta qué archivos cambiaste y qué comandos corriste.
These commands are from a Next.js project, but the idea is the same in any stack. If you work with Java and Spring, .NET, Python or Django, you can ask the AI to suggest the equivalent sensors for your language or framework and help you write them down in your AGENTS.md.
The last sensor is you. Read the diff before accepting it, even if the tests pass. As Böckeler says, no sensor is good at catching a wrong diagnosis or a misunderstood instruction. A good result depends on you having explained clearly what you wanted.
Compatibility between tools
One advantage of AGENTS.md is that it does not depend on a vendor. The official site has the full list of tools that read it, among them Cursor, Codex, Copilot and Windsurf. Gemini CLI and Aider read it if you configure them that way (the site has the example).
Claude Code uses its own file, CLAUDE.md. To avoid duplicating rules, mine only imports the other one.
# CLAUDE.md
@AGENTS.md
> Leer MEMORY.md al iniciar cada sesión y actualizarlo al terminar.
Antigravity, Google's IDE, does not appear on that list at the time of writing this, so check its documentation to see which file it reads. In the meantime, nothing stops you from telling it in the first message to read AGENTS.md.
Spec-Driven Development, how to work on top of the harness
With the harness built, you still have to decide how you ask the agent for work. Spec-Driven Development (SDD) means working with a written specification before the code. You describe what you want to build, why, and how you will check that it works. The agent implements from that document instead of from a one-off prompt in the chat.
The harness is what I really recommend building first. It is the simplest to start with and these days many programmers use it as their normal way of working with agents, with rules, memory and tests that grow with your project. SDD is a separate step you can add on top. It helps when a feature deserves more care than throwing a prompt into the chat, because you first write what you want, why, and how you will check it. You can work well with only the harness, and when you add specs the agent has even less left to guess. Also, the acceptance criteria of the spec can be turned into tests that add to the sensors of the harness.
A prompt stays in the chat history, the agent interprets it in its own way and the next session no longer sees it. A spec lives in the repo. You review it before any code exists, the agent reads it again when it gets lost and you use it at the end to compare the result. It also forces you to think about the edge cases before the agent solves them by guessing.
How it fits with AGENTS.md and BRIEF.md
AGENTS.md holds the rules that apply to any change in the project. Tools like Spec Kit call something similar a constitution, and Kiro calls it steering. The spec describes a single feature. The BRIEF.md from the example above is the simplest version of a spec. I put it with the pieces of the harness because it lives in the repo, but what it holds is the intent of a feature, and that is enough to start with SDD.
The typical flow
- Spec. What gets built and why, from the point of view of the person who uses it. This step does not discuss frameworks yet.
- Plan. Now the technical part, with stack, architecture and constraints.
- Tasks. The plan is split into small steps that can be implemented and tested separately.
- Implementation. The agent solves the tasks one by one and you review small changes instead of a thousand-line diff.
- Verification. The result is compared against the spec and the acceptance criteria. If something is missing, it is added as a new task.
Between each step you review. The agent can write the spec, the plan and the tasks, but you are the one who decides whether they are good.
A short example
# Spec: Modo oscuro
## Qué y por qué
Quien visita el sitio de noche quiere leer sin que la pantalla
lo deslumbre.
## Requisitos
- Botón en el navbar para cambiar entre claro y oscuro.
- Si el usuario no ha elegido, se usa la preferencia del sistema.
- La elección se guarda y se respeta en la siguiente visita.
## Fuera de alcance
- Temas personalizados.
## Criterios de aceptación
- DADO un sistema en modo oscuro, CUANDO abro el sitio por primera
vez, ENTONCES se ve en oscuro.
- DADO que elegí claro, CUANDO recargo, ENTONCES sigue en claro.
- Pasan npm test y npm run lint.
## Tareas
1. Leer la preferencia del sistema.
2. Agregar el botón y guardar la elección.
3. Ajustar los colores con variables CSS.
4. Escribir las pruebas de los dos criterios.
The GIVEN / WHEN / THEN format is the one Kiro uses for its acceptance criteria. It helps because each criterion turns almost directly into a test.
Tools
- GitHub Spec Kit. It is open source and works with several agents through commands like
/speckit-specify,/speckit-plan,/speckit-tasksand/speckit-implement. Each step generates a Markdown file that feeds the next one. GitHub explains it in its blog. - Kiro. The AWS IDE. Each spec generates
requirements.md,design.mdandtasks.md, and lets you run the tasks from the editor.
You do not need any of them to start. A Markdown file with the structure of the example works with any agent.
If you want to go deeper, Birgitta Böckeler compares Kiro, Spec Kit and Tessl on martinfowler.com. It is a good counterbalance because it also points out the problems, like specs too long to review or agents that do not always follow what is written. There is also a recent academic article that presents SDD as a discipline for software engineering with agents.
How to start today
- Create
AGENTS.mdat the root with the summary, the stack and the commands. You can ask the agent itself to make a first draft and then correct it yourself. - Add three or four hard rules. Start with the ones that would hurt the most if broken, like deploying or installing packages without asking.
- Create an empty
MEMORY.mdwith the state, decisions and pending sections. Put inAGENTS.mdthat it should be read at the start and updated at the end. - Before each feature, write a short spec in
BRIEF.mdwith goal, scope and acceptance criteria. If the feature is big, ask the agent for a plan and a task list before it writes code. - When opening each session, whatever the tool, ask the agent to read
AGENTS.mdandMEMORY.mdbefore doing anything. Many load them on their own, but saying so costs nothing and makes sure it starts with your rules. - Ask the agent to work and to tell you at the end which files it changed and which commands it ran to test it.
- Make sure the tests and the linter pass, and review the diff yourself.
- When you close the session or switch tools, ask for a
HANDOFF.mdand give it to the next agent.
Over time you will notice which mistakes repeat. Each one is a candidate for a new rule in AGENTS.md or a new test, and that is how the harness grows with your project.
Resources
- agents.md, the official site with examples and the list of compatible tools
- Custom instructions with AGENTS.md, the Codex guide
- Harness engineering for coding agent users, by Birgitta Böckeler on martinfowler.com
- Spec-Driven Development for Agentic Software Engineering
- Understanding Spec-Driven-Development: Kiro, spec-kit, and Tessl, by Birgitta Böckeler
- GitHub Spec Kit and its documentation
- Specs in Kiro
Who is behind harness engineering?
Mitchell Hashimoto. Cofounder of HashiCorp and creator of Ghostty. In My AI Adoption Journey, from February 5, 2026, he says he started calling harness engineering the habit of fixing each agent mistake so it does not make it again, either with a new line in AGENTS.md or with a tool, like a script that runs only the tests that matter. He himself clarifies that he did not know whether a term for that already existed.
Ryan Lopopolo, from OpenAI. In Harness engineering: leveraging Codex in an agent-first world, published on February 11, 2026, he describes a five-month experiment in which his team shipped an internal product without writing code by hand. Codex wrote everything and the repo reached close to a million lines and about 1500 pull requests. They started with three engineers and later there were seven. What helped me the most is his conclusion that the team's work shifted to designing the environment, making the intent clear and building the feedback loops.
Birgitta Böckeler, from Thoughtworks. She published a first note on February 17, 2026 and on April 2 she replaced it with the full article, Harness engineering for coding agent users. That is where I got the idea of guides and sensors that I use in this post. She also distinguishes computational controls, like tests and linters, from inferential ones, like a review done by another model.
Anthropic. In Harness design for long-running apps, published on March 24, 2026, Prithvi Rajasekaran describes a harness with three agents, one that plans, one that builds and one that evaluates by testing the app the way a user would. In his comparison, the agent alone took 20 minutes and cost 9 dollars, but the app had broken parts, and with the full harness it took 6 hours and cost 200 dollars, with an app that actually worked.
Meta-Harness. A paper published on arXiv on March 30, 2026 by Yoonho Lee, Omar Khattab (creator of DSPy), Chelsea Finn and others, which uses an agent to automatically search for and improve the harness code.
Philipp Schmid, from Google DeepMind. In The importance of Agent Harness in 2026, from January 5, 2026, he explains it with an analogy I like a lot, where the model is the CPU, the context is the RAM and the harness is the operating system.
Tool documentation for working with agents
I work every day with Cursor and Antigravity, so those two are the ones I know best. The others also read project rules and it is worth having their documentation at hand.
- Cursor. It is the editor I use for almost everything. Its rules explain how it loads
AGENTS.mdand the files in.cursor/rules. - Antigravity. Google's environment built for working with agents, and the other one I use every day. In Rules it explains how to give it rules and workflows.
- Codex. OpenAI's agent, which you can use from the terminal, the editor or the cloud. Its AGENTS.md guide is one of the clearest.
- Claude Code. Anthropic's agent for the terminal. It uses
CLAUDE.mdinstead ofAGENTS.md, and in memory it explains how to import one from the other. - OpenCode. An open source agent for the terminal that works with several models. It reads
AGENTS.md, and its rules explain how.
Where does Spec-Driven Development come from?
GitHub Spec Kit. Den Delimarsky introduced it on the GitHub blog on September 2, 2025, in Spec-driven development with AI: Get started with a new open source toolkit. There he presents it as an answer to vibe coding, where you describe what you want, receive code that looks right and often does not work. Spec Kit splits the work into specifying, planning, breaking it into tasks and implementing, and at each step you review before moving on.
Kiro. AWS introduced it on July 14, 2025 as an IDE with agents. Its specs split each feature into requirements, design and tasks, and the acceptance criteria are written with the GIVEN / WHEN / THEN format.
Tessl. It is the third tool Böckeler reviews in the article below, and the one that takes the idea the furthest, because it aims for the spec to be the main file and for the code to be generated from it. When she tried it, it was still in private beta.
Birgitta Böckeler. In Understanding Spec-Driven-Development: Kiro, spec-kit, and Tessl, from October 15, 2025, she tries all three and proposes three levels. In spec-first you write the spec before the task. In spec-anchored you keep it around so you can keep maintaining the feature. In spec-as-source you only edit the spec and never touch the code. She also says that for a small bug Kiro generated four user stories with 16 acceptance criteria, something worth keeping in mind before using SDD for everything.
The paper. Spec-Driven Development for Agentic Software Engineering, published on arXiv on August 31, 2026 by Jessica Díaz and her team at the Universidad Politécnica de Madrid, presents SDD as the discipline for working with agents as a team and connects it with the harness. It distinguishes the system rules, which live in files like AGENTS.md, from the specs of each feature, which is exactly the separation I use in this post between AGENTS.md and BRIEF.md.