An agent is a model plus a harness: what it knows, what it can touch, what it may not do, how it checks itself and what it leaves for the next session. The model is the same for everyone. The harness is where your results come from, and in Claude Code it is a handful of files you can review like code.
Build each piece from a failure you have seen
The term took off in February 2026, when OpenAI's Codex team wrote up harness engineering: building the environment, constraints and feedback loops that let agents write the code. Anthropic's long-running agents write-up makes the same point with failure modes. Every useful harness part answers one:
| Failure | Harness fix |
|---|---|
| Declares victory early | a feature list that starts all failing; tests decide "done" — features.json, a Stop hook |
| Leaves a mess | commit and write a progress note every session — git, progress.md |
| Forgets the conventions | standing instructions loaded every session — CLAUDE.md |
| Runs something dangerous | deny rules, a sandbox, approvals — permissions, /sandbox |
| Breaks style or types | fast checks on every edit — PostToolUse hooks |
| Drowns in context | side work in a fresh context — subagents |
Read the table right to left and you have a checklist. Read it left to right and you have the discipline: add a part when you have seen the failure, not before. The same idea for agents you deploy with the SDK is who owns the loop.
Know which settings file wins
Five settings levels: the higher one wins a single value, lists merge.
- Managed
managed-settings.jsonor MDM — org policy; nothing overrides it - Command line
--settingsfile or JSON — this session only - Local project
settings.inlocal.json .claude/— you, this repo, gitignored - Shared project
settings.jsonin.claude/— the team, committed - User
settings.jsonin~/.claude/— you, every project
Highest precedence first. permissions.allow, deny and hooks add up across all five; a deny anywhere still wins.
Claude Code reads settings from five levels. For a single value such as the model, the highest level that sets it wins. List keys such as permissions.allow and hooks merge instead, so a project rule adds to your user rules and never erases them. Two consequences matter in practice: a deny rule at any level cannot be undone by an allow rule at another, and a managed policy is the only place an organisation can make a rule stick.
Scope permissions to a prefix, never to everything
{
"permissions": {
"defaultMode": "acceptEdits",
"allow": [
"Bash(npm run test *)",
"Bash(npm run lint *)",
"Bash(git status)",
"Bash(git diff *)"
],
"ask": ["Bash(git push *)"],
"deny": [
"Read(.env*)",
"Edit(.env*)",
"Bash(git push --force *)"
]
}
}
Bash(*) in allow- every command runs unprompted,
rm -rfincluded - one approval click made permanent
- you stop reading what runs
Bash(npm run test *)- a family of known-safe commands
- anything new still prompts, so you notice it
- dangerous ones denied outright
Rules are checked deny first, then ask, then allow, and the first match decides. Put the * after the subcommand: Bash(git diff *) allows only git diff, while Bash(git *) allows every git command, including push. Compound commands are split, so npm test && curl … needs both parts allowed. A long, specific allow list is a sign the harness is working. The rule syntax is in the permissions docs; the same model in code is permissions and hooks.
Pick the right primitive for each job
| You want | Use | Because |
|---|---|---|
| a convention Claude should always follow | CLAUDE.md | loaded every session |
| a procedure you keep pasting | skill | loaded only when needed |
| side work that would flood the context | subagent | own context, returns a summary |
| data or actions in another system | MCP server | new tools, not new instructions |
| something that must happen every time | hook | runs without the model choosing |
| the same setup in a second repo | plugin | packages the rest, versioned |
Each one fails the same way when it is used for the wrong job: a hook cannot reason, a skill cannot enforce (the model decides whether to load it), a subagent cannot react to events, and an MCP server only adds tools. The longer comparison is skills vs subagents vs MCP.
Give it a way to check its own work
- EditClaude changes a file
- PostToolUselint and type-check that file
- Claude fixeserrors arrive while the file is fresh
- Stoptests must pass before "done"
Fast, deterministic feedback is the highest-leverage part of a harness. A model that can run the tests fixes its own mistakes; a model that cannot hands them to you. Anthropic's write-up found the same: agents marked features done until they were told to verify them end to end, there with a browser-automation MCP server. Wire the checks as hooks so they run every time, keep each one fast, and make failures readable. The three hooks worth copying are in Claude Code hooks.
Leave state for the next session
A context window ends; the work does not. Anthropic's harness had a first session write a feature list, an init.sh and a progress file, and every later session start like this:
I'll start by getting my bearings.
pwd, then read claude-progress.txt and feature_list.jsongit log --oneline -20
what the last session committedRuns init.sh, starts the dev server, tests one basic feature end to end.
The basics work. The next failing feature is "New chat button creates a fresh conversation". Starting on that one.
one feature per session, then commit and update the progress fileNothing in it is clever, and that is the point: it is what a good engineer does on the first morning of a handover. Compaction keeps one long session going; files and git carry work across sessions. More on surviving restarts in agent durability.
Start from a small project harness
repo/
├── CLAUDE.md # build, test, conventions; under ~200 lines
├── .claude/
│ ├── settings.json # permissions + hooks, committed
│ ├── settings.local.json # your overrides, gitignored
│ ├── hooks/
│ │ ├── block-env.sh # PreToolUse: keep out of secrets
│ │ ├── lint-file.sh # PostToolUse: lint what was edited
│ │ └── tests-before-stop.sh
│ ├── skills/release/SKILL.md # a procedure you'd otherwise paste
│ └── agents/security-reviewer.md # a second opinion in a fresh context
└── .mcp.json # the issue tracker, the staging database (read-only)
That is enough to remove most recurring friction in a real repo. Keep CLAUDE.md short and specific (build and test commands, conventions, the things Claude got wrong twice), because it is read in full every session; the memory docs suggest under 200 lines per file. Put team gates in the committed settings.json and personal ones in your user file. Give MCP servers the narrowest credentials that work: a read-only database role, a scoped token.
A consultant working across five client repos keeps one user-level file (the .env block, a desktop ping, read-only commands) and a project layer per client (that stack's linter, test runner and deploy target). Nothing from one client leaks into another, because the project layer loads only inside that repo, and a context switch stops being a morning of rediscovery.
Grow it from triggers, and prune it
| When this happens | Add |
|---|---|
| Claude gets a convention or command wrong twice | a line in CLAUDE.md |
| you paste the same procedure a third time | a skill |
| a side task floods the conversation | a subagent |
| you copy data from a tab Claude can't see | an MCP server |
| you want something every time, without asking | a hook |
| a second repo needs the same setup | a plugin |
Adapted from the triggers table in the Claude Code feature overview.
Every part you add is a part someone has to remember exists. Run /context, /hooks and /mcp to see what actually loaded, delete instructions the model now follows without being told, and re-test the harness when you change models: a workaround for one model's habit can get in the way of the next.
Bash(*) or bypassPermissions outside a throwaway container. A 1,000-line CLAUDE.md that buries the five rules that matter. A skill used as an enforcement mechanism. MCP servers with admin credentials "for now". Settings that differ between laptops because nobody committed the project file.
“The model is the same for every team. Why do some get far better results?” Answer with the harness: what context it loads, which tools and credentials it has, which commands are denied, what checks run on every edit, and what state it leaves for the next session. Then name the failure each piece prevents. Compare framework vs own loop.
Your user settings allow Bash(git push *); the project settings deny Bash(git push --force *). What happens on git push --force origin main?
It is denied. Permission lists merge across levels, and deny rules are checked before allow rules regardless of which file they came from, so the more specific deny wins over the broader allow.
Claude keeps ignoring "run the formatter after editing" in CLAUDE.md. Which primitive should it be?
A PostToolUse hook on Edit|Write. Instructions are followed by choice; a hook runs on every matching event. Then delete the line from CLAUDE.md.
A long refactor runs over several sessions and each new session redoes work or breaks what was finished. What two harness parts are missing?
State and verification: a progress file plus a git commit at the end of each session, and a feature or test list the agent checks (and runs) at the start of the next one before it builds anything new.
- Agent = model + harness; the harness (context, tools, guardrails, feedback, state) is what you engineer.
- Add each part in answer to a failure you have seen.
- Settings: the highest level wins a single value; permission and hook lists merge; deny beats allow everywhere.
- Scope permissions to command prefixes; keep
Bash(*)out of your allow list. - Fast checks as hooks, and progress files plus git, are what let an agent run longer without you.