Guideclaude-codeharnessagents-ia

Claude Code Harness: 98.4% Infrastructure, 1.6% AI

The Claude Code harness explained: agent loop, CLAUDE.md, permissions, hooks, MCP, mistakes to avoid, three configuration levels and what it really costs.

21 min readPublished June 22, 2026Updated November 11, 2026

Geoffrey Harrazi

Chief Product Officer · Co-founder, Idun Group

Without changing the model, a new harness takes an agent from 52.8% to 66.5% on Terminal Bench 2.0, as measured by LangChain.

The Claude Code harness is everything in the agent that is not the model: the loop that sends the request to Claude and runs the actions it proposes, the tools it can call, the project memory, the permission rules, the automated checks and the logs. The model supplies the power; the harness channels it. The term applies to any AI agent, hence the formula agent = model + harness; designing and tuning this layer, for Claude Code as for Codex or Cursor, is called harness engineering. It is what separates a Claude agent that impresses in a demo from one you can trust on a production repository.

This guide is written first for the teams who configure Claude Code. The question that comes next, what the Claude Code seats produce against what they cost, is covered on our Claude for enterprise page. For how the agent itself works, see agentic coding with Claude Code. Outside code, Anthropic offers an office agent, Claude Cowork. And to have a second model review the code without leaving the session, see our Antigravity plugin for Claude Code.

Claude Code harness architecture and components

Claude Code runs on an agent loop and six building blocks: project memory (CLAUDE.md), tools (Read, Edit, Write, Bash, Grep, WebFetch…), permissions (settings.json), hooks (PreToolUse, PostToolUse), MCP servers and observability (logs, context compaction). CLAUDE.md steers the model without enforcing anything. Permissions, hooks and the scope of MCP servers decide what runs, and the logs keep a record of it.

Why is 98.4% of Claude Code estimated to be harness?

Because most of a coding agent's work is not producing text but deciding what to run, with which rights, and keeping a record of it. A community analysis of the Claude Code v2.1.88 source (about 1,884 files and 512,000 lines of TypeScript) estimates that only 1.6% of the code is AI decision logic; the remaining 98.4% is infrastructure: permission gates, tool routing, context management, error recovery. MBZUAI researchers cite this estimate in their study of Claude Code (Jiacheng Liu, Xiaohan Zhao, Xinyi Shang and Zhiqiang Shen, arXiv, April 2026). It is an order of magnitude, not an official count, but it shows where the work lies.

With the same model, it is the configuration that separates two teams: verification loops, quality gates and error handling matter more than a more powerful model. LangChain put a number on it, as shown below: 13.7 more points on Terminal Bench 2.0 by changing only the layer around the model.

How does the Claude Code agent loop work?

Claude Code, like Cursor, Codex or an agent built with LangGraph, runs on a four-step agent loop:

  1. Send: pass the model the message and the list of available tools.
  2. Check: read the stop_reason field of the response.
  3. Run: if the response is a tool_use, run the requested tool and add the result to the context.
  4. Repeat: until the model gives its final answer.

The harness governs every pass through this loop. Without it, the agent acts with no constraints and no record. Configured well, it sends every action through a permission check, quality checks and logging.

Harness vs prompt engineering: what is the difference?

Prompt engineering shapes what the model says; the harness shapes what the agent does. The two work together.

Prompt engineeringHarness
What it controlsWhat the model answersWhat the agent runs
CoverageInstructions, examples, contextTool calls, permissions, hooks, memory
EffectQuality of answersReliability in production
StrengthAdvisory: the model can drift from itBlocking: a forbidden action does not run
LifespanOne sessionThe project's configuration

LangChain measured it. By changing only its harness (system prompts, tools, middleware), without touching the model, its coding agent went from 52.8% to 66.5% on Terminal Bench 2.0, a gain of 13.7 points (LangChain, 2026).

What did the 31 March 2026 source code leak reveal?

On 31 March 2026, version 2.1.88 of the npm package @anthropic-ai/claude-code was published with a source map file meant for internal debugging, which made it possible to rebuild the tool's source code. Anthropic described it as a release packaging issue caused by human error, with no customer data or credentials exposed (VentureBeat, March 2026).

Beyond the incident, the leak opened Claude Code's architecture to public and academic analysis: the MBZUAI study quoted above is based on this code. For a team designing its own configuration, these analyses have become a reference.

Memory: what does CLAUDE.md do, and what does it not do?

CLAUDE.md is the project's memory. Claude Code loads it every time a session opens: coding conventions, useful commands, business constraints. It steers the model's reasoning, but it blocks nothing. An instruction written in CLAUDE.md can be ignored if the context pushes the model elsewhere. Every critical instruction, such as "never modify production files", must therefore be backed by a rule in permissions.deny.

Tools: what actions can the agent take?

The harness exposes four families of tools to the model:

  • Files: read, write, edit, search;
  • Shell: bash commands, scripts, builds (deletions also go through here);
  • Network: HTTP calls, external APIs, third-party services;
  • Browser: navigation, interface interactions, tests.

In Claude Code, these include Read, Write, Edit, Glob, Grep, Bash, WebFetch and WebSearch. The MBZUAI inventory counts 19 built-in tools that are always present, and up to 54 depending on feature flags and user type, plus the tools of MCP servers (April 2026). Tools are how the agent acts, so they carry most of the risk. Each one deserves to be documented in the team's shared configuration, along with the scope of every MCP server.

Permissions: how does settings.json decide?

settings.json holds the agent's permissions in three lists: what it does on its own (allow), what needs confirmation (ask), what is forbidden (deny). Rules are evaluated in the order deny, then ask, then allow. The first match wins, and an allow rule cannot carve an exception out of a deny rule (Claude Code documentation, November 2026). Without explicit permissions.deny rules, the decision falls to the model or to whoever approves.

Claude Code also offers several permission modes, from the default mode, which asks before every sensitive action, to bypassPermissions, which asks nothing at all; the MBZUAI study counts seven in the code of the version it studied, five of them visible to users. Settings have three scopes: the project (.claude/settings.json, versioned and shared by the team), the developer (~/.claude/settings.json and .claude/settings.local.json, not versioned), and settings managed by the organisation, which nobody can override.

Hooks: how do you block an action before it runs?

Hooks are the automated quality gates. A PreToolUse hook runs before every tool call, a PostToolUse hook after it. A PreToolUse hook that returns exit code 2 blocks the action: that is what separates it from a plain log. A PostToolUse hook comes too late to prevent the action; it checks the result (running the tests, a linter) and sends the error back to the model, which can fix it. A hook does not override the rules either: a deny rule blocks the call even if the hook accepted it.

MCP: how do you add tools without exposing secrets?

MCP (Model Context Protocol) is the standard for adding tools to Claude Code: a database, an internal API, a business tool. Each MCP server brings its own tools and keeps its own credentials, so the agent never holds every secret at once. The scope of each server is a critical setting: an MCP server with overly broad write rights becomes a direct way in. Cursor and Codex rely on the same standard.

Observability: what do the logs keep, and what does context cost?

Observability does two jobs. Session logs record every action the agent takes: they are used to review an incident and to evaluate outputs after the fact. Context compaction summarises the early part of a long session as it goes, so it fits in the model's working memory: it is what lets an agent work for hours at a stretch (Anthropic Labs, March 2026, details below). Claude Code can also export its metrics and events in OpenTelemetry format.

Internal or external harness?

The internal harness lives inside the agent's process: settings.json, hooks, MCP servers. It acts before the tool call. The external harness acts at system level: container, sandbox, network filters. It also blocks what internal rules cannot see, such as a Python script that opens a file on its own. Claude Code and Cursor provide the internal layer, and Claude Code ships a built-in sandbox to isolate commands; the rest of the isolation usually falls to the platform team.

What are the most common harness engineering mistakes?

Five configuration mistakes keep coming back, and two vulnerabilities published in 2025-2026 show where the risk lies. All of them concern the configuration around the model, none the model itself.

Mistake 1: instructions in CLAUDE.md without permissions.deny

The most common one. CLAUDE.md instructions are advisory: the model follows the context it has, not a conventions file that nothing enforces. An instruction such as "never modify production files" with no matching deny rule ends up being broken. CLAUDE.md documents the intent; settings.json enforces it.

Mistake 2: plaintext API keys in the agent's folder

A .env file reachable from the working folder is a file the agent can read, and that a network tool can send out. Credentials belong out of its reach: files in mode 600 in a path it cannot see, or a secret manager. A deny rule on Read(./.env) protects against Claude Code's own tools, not against a script that opens the file itself: that case calls for the sandbox.

Mistake 3: hooks that log but never block

A hook that records everything but never returns exit code 2 gives an illusion of control. Unwanted actions go through, and the post-incident review shows perfect logs next to real damage. A hook that cannot block does not protect. The same goes for a hook that crashes or whose script cannot be found: by default, Claude Code lets the action through, unless the hook is set with "onFailure": "block".

Mistake 4: MCP write rights combined with an open shell

Broad write rights on an MCP server, added to a permissive list of bash commands, give the agent two paths to write where nobody planned it. It is a classic route to files changed outside the intended scope. The rule is least privilege: writes limited to the paths that need them, bash commands limited to identified tasks.

Mistake 5: bypass mode on a production repository

bypassPermissions mode (or the --dangerously-skip-permissions flag) switches the checks off. Anthropic's documentation reserves it for isolated environments, containers or virtual machines. On a production repository, it is an open door. An organisation can forbid it by setting permissions.disableBypassPermissionsMode to "disable" in its managed settings; failing that, the same setting goes in the project's versioned .claude/settings.json.

CVE-2025-59536 and CVE-2026-21852: two vulnerabilities in the configuration layer

These two vulnerabilities, published by Check Point Research in February 2026, do not touch the model. Both went through a project's configuration files: opening a booby-trapped repository could run commands before the user accepted the trust dialog (CVE-2025-59536), or redirect API traffic to a third-party server to capture the key (CVE-2026-21852). Both are fixed. Two habits follow: update Claude Code as soon as a fix ships, and review the .claude/ folder and .mcp.json file of an unknown repository before opening it.

MistakeLikelihoodSeverityFix
1. CLAUDE.md without a deny ruleVery highHighEvery critical CLAUDE.md instruction has its permissions.deny rule in settings.json
2. Plaintext API keys (.env in the agent's folder)Very highCriticalCredentials in mode 600 outside the agent's folder, or a secret manager (Vault, AWS Secrets Manager)
3. Hooks that never block (no exit code 2)HighHighEvery protection hook returns exit code 2 to block, not just to log
4. Open MCP writes and bashHighCriticalLeast privilege: MCP writes limited to the paths needed, restricted bash list
5. Bypass mode in productionModerateCriticalBypass only in isolated environments; forbidden in managed settings
6. Published vulnerabilities (CVE-2025-59536, CVE-2026-21852)Low if Claude Code is up to dateCriticalUpdate as soon as the fix ships; review the configuration of unknown repositories

Sources: Check Point Research (February 2026) for the vulnerabilities, Claude Code documentation (November 2026) for the fixes. Likelihood and severity: Idun Group estimates.

Configure your Claude Code harness in 3 levels

Configuring Claude Code comes down to four files: CLAUDE.md for instructions, .claude/settings.json for permissions (allow, ask, deny) and hooks, .mcp.json for MCP servers, and the organisation's managed settings. The level of autonomy depends on the repository and the task: approve every action in production, a curated allow-list in staging, full autonomy in a sandbox.

LevelWhat needs confirmationWhich repositoriesSetting in Claude Code
A. Approve every actionEvery sensitive tool callProduction, regulated contexts, code shared across teamsDefault mode, broad ask rules, deny rules on anything critical
B. Curated allow-listAnything outside the list, starting with destructive actionsProofs of concept, stagingChosen allow list (reads, tests, read-only APIs)
C. Sandboxed autonomyAlmost nothingLong batch tasks in an isolated environmentContainer or sandbox, restricted network, no reachable secrets

Level A: every action needs confirmation

The recommended entry point for sensitive repositories and regulated contexts. Every sensitive tool call triggers a human confirmation: the approval load is at its highest and the risk at its lowest. This setting suits projects in production and codebases shared by several teams. Because a person approves each action, it also works as a continuous review. The repository's CLAUDE.md or README states which tasks the agent may carry out on its own and which need approval.

Level B: a curated allow-list, everything else needs confirmation

An allow-list defines what the agent does on its own: reading files, running tests, calling read-only APIs. Everything else, starting with anything that deletes or overwrites, needs confirmation. This setting suits proofs of concept and staging: the agent moves fast on routine tasks without constant supervision. The list is versioned in .claude/settings.json and documented in the README. A starting example, to adapt to the repository:

json
{ "permissions": { "allow": ["Read", "Grep", "Glob", "Bash(npm run test *)"], "ask": ["Edit", "Write", "Bash(git push *)"], "deny": ["Read(./.env)", "Read(./secrets/**)", "Bash(rm -rf *)"], "disableBypassPermissionsMode": "disable" }, "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"${CLAUDE_PROJECT_DIR}\"/.claude/hooks/check-bash.sh", "onFailure": "block" } ] } ] } }

The check-bash.sh script must exist in the repository and be executable: it reads the proposed command and returns exit code 2 to block it. Its path starts from the project root (${CLAUDE_PROJECT_DIR}), so it is found even after a change of directory. Without "onFailure": "block" (Claude Code v2.1.295 or later), a missing or failing script would let the action through.

These rules add to those of the other settings files; they do not replace them. Claude Code merges the allow, ask and deny lists from the user, project and local files. An allow rule a developer has set in their own settings therefore still applies, and the project file does not guarantee that everything outside its list will need confirmation. A repository's allow rules also apply only once the folder is trusted; deny and ask rules apply right away. For a shared, closed scope, you need settings managed by the organisation with allowManagedPermissionRulesOnly: Claude Code then applies only the rules from those managed settings.

Level C: full autonomy in a sandbox

The agent works in a container, with restricted network access and a filesystem limited to the working folder. The approval load is close to zero. This setting is for long batch tasks, often run overnight: migrating a codebase, generating test suites, large-scale refactoring. Isolation guarantees the agent cannot reach secrets or systems outside its scope; it is the only setting where bypass mode belongs.

What does a harness cost? Anthropic Labs figures (March 2026)

On 24 March 2026, Prithvi Rajasekaran of Anthropic Labs published the cost of several runs in which Claude had to build a complete application on its own. On the same prompt, a 2D retro game maker, a single agent worked for 20 minutes for 9 USD; the full harness worked for 6 hours for 200 USD, more than 20 times as much, but the resulting application was far richer and actually playable.

ConfigurationWhat it includesApplication builtDurationCost
Single agentOne agent, no planner, no evaluator2D retro game maker20 min9 USD
Full harnessPlanner, generator and evaluator, Playwright MCP, several test rounds, automatic context compactionThe same6 h200 USD
Simplified harnessA lighter version, on a newer modelA different one: a music studio in the browser3 h 50 min124.70 USD

Source: Anthropic Labs, Prithvi Rajasekaran, "Harness design for long-running application development" (24 March 2026). The first two rows cover the same prompt; the third covers a different application and cannot be compared directly with the other two.

The key point of the article is the separate evaluator. An agent grading its own work judges it too kindly; a separate agent, tuned to be demanding, spots what does not work and sends it back to the generator. A full harness therefore costs more than a bare session, but it delivers an application that works. For leadership, the right measure is not the cost of a session but the cost of a usable result.

Can you use the Claude Code harness with other models?

Not officially. Claude Code is built for Claude models, available through the Anthropic API, Amazon Bedrock, Google Cloud or Microsoft Foundry. The ANTHROPIC_BASE_URL variable lets you send traffic through a corporate LLM gateway, which centralises credentials, costs and logs. Some gateways can route to other models, but Anthropic states that it does not support routing Claude Code to non-Claude models (Claude Code documentation, November 2026). The system prompts and tools are tuned for Claude: with another model, results vary.

What carries over is the principles. The LangChain gain quoted above was measured on a model that was not Claude, in a different harness. Codex, Cursor and open-source agents have equivalent layers: project memory, permissions, hooks, MCP. In a meeting, a technical director told us he keeps his teams' skills in an open-source tool precisely so he can switch models. To keep that freedom:

  • write the project conventions in files other agents can read (AGENTS.md, recognised by Codex and several other agents, can be imported from CLAUDE.md);
  • keep checks in scripts called by the hooks, which can be reused elsewhere;
  • expose business tools as MCP servers rather than as integrations tied to one agent.

From the individual harness to enterprise-wide governance

Why does an individual setup not hold at team scale?

Because a settings.json on one machine syncs with nobody. Each developer keeps their own rules, and configurations multiply with no overall view: agents set up differently, missing READMEs, prohibitions that differ from one repository to the next. As soon as several agents work in parallel on business applications, a shared level of rules is needed.

Claude Code provides the means. The project's .claude/settings.json is versioned with the code and gives the whole team a common base, which adds to each person's own settings. Managed settings, deployed by IT on every machine, apply to everyone and cannot be overridden: shared deny rules, bypass mode disabled, a list of allowed MCP servers, a mandatory LLM gateway and, with allowManagedPermissionRulesOnly, permissions that come from them alone.

The four maturity stages

  1. Individual setup. The developer configures their agent (Claude Code, Cursor or Codex) in a local settings.json. CLAUDE.md sets the project rules; hooks and MCP servers are switched on case by case.
  2. Team setup. The team shares a configuration repository: versioned CLAUDE.md files, rule files, standardised hooks, an up-to-date README.
  3. Platform. Agents run as services, with shared observability (OpenTelemetry, for example), persistent memory and centralised guardrails.
  4. Enterprise. The same rules apply to every AI tool in the company, Claude Code included: what is forbidden everywhere, who can change a rule (roles from owner to reader), how to stop an agent in an emergency, which records to keep for the AI Act and OWASP.

The fourth stage is less about tooling than about organisation: who sets the rules, who changes them, who can stop an agent. We describe an AI agent governance framework built on real usage in a dedicated article.

What do the AI Act and OWASP require?

Records and human oversight. A coding agent is not usually a high-risk AI system under the AI Act. But if it is part of one, the text requires automatic event logging (Article 12), effective human oversight (Article 14) and, on the deploying company's side, logs kept for at least six months (Article 26). These rules apply from 2 December 2027 for Annex III systems, a date set by the AI omnibus of July 2026; our guide covers what the AI Act requires of companies that use AI. OWASP published its reference framework for agentic applications in December 2025, which also expects verifiable controls and a documented ability to review. The agent's configuration layer is the natural place to produce that evidence: every instruction given to the agent and every action it takes must be traceable.

Do other agents work the same way?

In principle, yes; in the detail, no. Claude Code, OpenAI's Codex CLI and Aider share the same base: an agent loop, tools the harness checks before running them, a project memory. The differences lie in where the security boundary sits, and the MBZUAI study documents them (April 2026):

  • Claude Code evaluates every action before running it: deny rules first, hooks, an optional automated classifier and seven permission modes. The boundary sits between the model and the execution environment.
  • SWE-Agent and OpenHands rely on container isolation rather than action-by-action rules.
  • Aider relies first on Git: you roll back if the agent got it wrong.
  • OpenClaw, an open-source assistant connected to messaging apps, puts the boundary at the entrance of its gateway: a single trusted operator, allowlists of senders, and a sandbox that is off by default.

For a team, the lesson is practical: before adopting an agent, find out where it puts that boundary, and what you need to add around it (container, rules, backups) to cover the rest.

What leadership should know before adding Claude Code seats

A well-configured harness makes Claude Code safe and reliable. It does not tell you whether the seats serve the company's objectives. Before expanding, leadership needs four answers, and they are the ones that come up when we talk with CIOs.

  • Which objective are we funding? A head of developer tools told us that as soon as they open Claude Code to a team, they are asked what budget to plan. Their answer: for which objectives? Without an objective, the budget follows the number of seats, and the renewal is decided with nothing to go on. A member of an executive committee voiced the same worry differently: the fear of losing control, and a simple question, will these seats be used well?
  • What do the sessions produce? The available traces count sessions and minutes. At one large company, the tracing system could not reconstruct what a session had produced. A duration is not a result. And since agents moved to consumption-based billing, a head of generative AI told us their concern was no longer driving adoption but containing the spend. On the estates we analyse, 20 to 40% of paid AI licences go unused.
  • Did this code already exist? A group CIO discovered modules built with Claude Code when a standard function of his information system already did the job: it only needed switching on. A fast agent quickly produces code the company did not need.
  • Who owns security? Writing code is something AI can do; security is where the problem lies, as one CIO put it. The answer lies in the settings described above: managed settings, deny rules, updates, sandbox.

These answers are measured by team and by task, from the logs and exports the platforms already produce, and cross-checked with interviews. We analyse usage, not individuals. The method to work out what AI returns from real usage is set out in a dedicated article. Idun Group does this work on Claude Code: we measure real usage from what your platforms record, cross-check it with interviews, and tell you what to industrialise, consolidate or cut. The detail is on our page about real Claude Code usage, team by team.

In short: six settings to check this week

  • Every critical CLAUDE.md instruction has its permissions.deny rule.
  • Protective PreToolUse hooks return exit code 2.
  • No API key is readable from the agent's folder.
  • MCP servers have only the write rights they need.
  • Bypass mode is disabled in managed settings, outside the sandbox.
  • Claude Code is up to date, and unknown repositories are reviewed before they are opened.

Was this article helpful?

Frequently asked questions

The Claude Code harness is everything around the Claude model inside the agent: the loop that sends it requests and runs its actions, the tools, the project memory (CLAUDE.md), the permissions (settings.json), the hooks, the MCP servers and the logs. The model proposes an action; the harness decides whether it runs, with which rights, and keeps a record of it.

About the author

Geoffrey Harrazi« geoffrey »

Chief Product Officer · Co-founder, Idun Group

Chief Product Officer and co-founder of Idun Group. Product, business and sales. Ex-LVMH. Leads Idun Cockpit, which measures the real usage of the AI companies have already deployed: licences, assistants and agents.

LinkedInSite26 articles published
Revision history (4)
  • November 11, 2026Rewrite: clearer English, repetition removed, a section for leadership, internal links.
  • November 10, 2026Internal links added at the top of the article to the Claude for enterprise page and related articles; related articles refocused on Claude.
  • October 30, 2026Passages about Idun Group's offer updated; call to action refreshed.
  • June 10, 2026Initial publication

Get our guides on the value of AI every month

Field notes on real AI usage in companies: adoption, costs, what it returns and what to do about it. No spam, ever.

1 email per month. No more.

Unsubscribe at any time from the link in every email. How we handle your data: privacy policy