AINave
Blog

What is an agent harness? We read the source code of 5 to find out

An agent harness is everything in a coding agent that isn't the model. I've used 10 of them, and we read the source of 5 (Codex CLI, Gemini CLI, OpenCode, pi and Hermes Agent) to see what each one tells the model, what it lets the model do, and when it cuts it off.

Ramit Koul · 14 min read
Ask AI about this post
What is an agent harness? We read the source code of 5 to find out

The short version

What it is
Everything in an agent that isn't the model: the system prompt, the tools, the approvals, the loop and what gets forgotten.
What we did
Cloned 5 open-source harnesses on Nov 24, 2026 and read how each makes the same 5 decisions. Nothing was benchmarked.
Biggest gap
Base instructions run from about 450 tokens in pi to about 5,500 in Gemini CLI.
Surprise
4 of the 5 change the prompt, and sometimes the tools, depending on the model you pick.
Risk
Approval defaults go from an OS sandbox in Codex CLI to no permission system at all in pi.
Use it
When a tool misbehaves, swap the harness and keep the model, or the reverse, before you blame either.

Tools in this post

The Codex desktop app was crashing on me constantly. I didn't cancel my ChatGPT plan. I signed in to the same plan from a different tool, pi, and the crashes stopped. Same subscription, same models, different software around them.

That software is the agent harness: everything in a coding agent that isn't the model. I've used 10 coding harnesses for real work. For this post we also cloned 5 open-source ones and read the code to see what each tells the model, what it lets the model do, and when it cuts the model off.

What an agent harness is

A model only produces text. The agent harness is the program that turns that text into work. It writes the system prompt, hands the model a set of tools, runs the tool calls, decides which ones need your approval, feeds the results back, and trims the conversation when it gets too long.

Vivek Trivedy at LangChain has the shortest definition I know: "If you're not the model, you're the harness."

The tools now use the word about themselves. Pi's README describes it as a minimal, extensible agent harness. OpenCode even tells the model. Its base system prompt opens with: "You are an AI agent running in OpenCode, a coding agent harness."

Claude Code, Codex CLI, Gemini CLI, OpenCode and pi are all harnesses. So is Hermes Agent, which isn't a coding tool at all. An MCP server is not one: it is a source of tools that a harness connects to. A framework such as LangGraph is a kit for building one, and AINave's own agents are built on a framework of that kind, Agno.

One request, 5 decisions

Take a boring request: "fix the failing test." Between your message and the fix, the harness makes 5 decisions for you. We read how 5 harnesses make each one: Codex CLI, Gemini CLI, OpenCode, pi and Hermes Agent, in their code as of November 24, 2026. I've used all 5. Claude Code, which I use every day, isn't in the table because its source is closed.

Diagram of one request passing through 5 harness decisions in a row: prompt, tools, approval, loop and memory. A line loops back from the last to the first.
The 5 sections below follow these numbers.
HarnessBase promptTools on by defaultAsks before it actsCompacts at
Codex CLI3,452 to 5,059 tokens, across 8 templates for 14 modelsNo fixed list. 13 of 14 models call tools by writing JavaScriptYes. Approval on request, plus an OS sandbox90% of the context window
Gemini CLIAbout 5,500 tokens for newer models, 3,900 for older onesAbout 17Yes. Default mode asks before shell commands and file writes. The sandbox is off until you enable it50%
OpenCode205 tokens, swapped for 563 to 1,804 on some modelsNo fixed list. It depends on the model, and some tools are only reachable through Code ModeRarely. The default agent allows everything except reading .env filesAbout 85%
piAbout 450 tokens4NoWhen 16,384 tokens are left
Hermes AgentBuilt at runtime. The default identity text is 149 tokensUp to 27, plus 14 kanban tools that are off on new installsFor commands it flags as dangerous. A second model approves the low-risk ones50%, or 75% on windows under 512K tokens

Token counts use OpenAI's o200k_base tokenizer, so read them as relative sizes. They cover the base instructions only, before tool definitions, your project files and everything else a harness adds at runtime. The tool count for Gemini CLI is our reading of the registration code for a default interactive session. Flags and the model you pick can change it. The Gemini CLI prompt sizes come from the rendered prompts in the repo's own test snapshots, and the pi figure is the default prompt rebuilt from its code with the 4 default tools. It lands between 444 and 488 tokens depending on the file paths that get filled in.

1. What the model is told before you type

Pi sends about 450 tokens of instructions. Gemini CLI sends about 5,500 to its newer models. That is a 12x gap before you have typed a word, for the same job.

Bar chart of base system prompt size in tokens for 4 harnesses. pi is about 450. OpenCode runs from 205 to 1,804. Codex CLI runs from 3,452 to 5,059. Gemini CLI runs from 3,905 to 5,492.
Base instructions only, counted from each repository on Nov 24, 2026. Hermes Agent builds its prompt at runtime, so it has no fixed size.

The bigger surprise: 4 of the 5 change the prompt depending on which model you pick.

  • Codex CLI ships a catalog of 14 models with 8 different instructions templates between them. The catalog is a JSON file bundled with the CLI and refreshed from OpenAI's servers, so the prompt is data, not code.
  • OpenCode matches on the model's name. A GPT model gets a 563-token prompt in place of the base one, or 794 tokens if it is an Astra model. Muse gets 1,613, Trinity 1,660 and Kimi 1,804. Claude keeps the 205-token base and gets 59 more tokens about code comments.
  • Gemini CLI carries 2 prompt families, a modern one and a legacy one, and picks between them by model.
  • Hermes Agent adds extra text that pushes the model to call tools instead of describing what it would do. It applies to models whose names match 9 patterns, including GPT, Gemini, Grok and Muse. Claude is not on that list. For Muse, a comment in the code explains why: on default settings Muse Spark answered in prose and made 0 tool calls.
  • Pi is the exception. It builds one base prompt for every model.

So when you switch models inside a harness, you often switch prompts too, and nothing on screen tells you. It also means a harness has to keep up with new models. Google says as much at the top of the Gemini CLI README, which now warns people not to benchmark Gemini models with it because "its harness isn't tuned for Gemini 4+ and produces unrepresentative scores."

2. What the model can touch

Pi turns on 4 tools: read, bash, edit and write. Its README says it leaves out sub-agents and plan mode on purpose. Hermes Agent's core list has 41 names, including web search, a browser, image generation, text to speech, memory, cron jobs and delegation to sub-agents. That list is why Hermes can do my non-coding work and a coding CLI can't.

The tool list also moves with the model. OpenCode gives GPT-5 and later models a patch tool and hides edit and write. Every other model gets the reverse.

Codex CLI goes furthest. For 13 of its 14 catalog models, the model doesn't call most tools directly. It writes JavaScript that calls them, and the harness runs that script in a fresh V8 isolate. "How many tools does Codex have?" stops being a useful question.

The detail we liked most is in OpenCode. If a model calls a tool named bash, which OpenCode doesn't have, OpenCode runs the call as its own shell tool and adds a note telling the model to call shell next time. The comment above that code says these are names models bring with them from other harnesses. Models pick up habits, and harnesses patch around them.

3. What needs your yes

This is where the 5 differ most.

The 5 harnesses ordered from most guarded to least by default: Codex CLI, Gemini CLI, Hermes Agent, OpenCode, pi.
The order is our reading of each harness's defaults, not a measurement.
  • Pi has no approval prompts. Its README says it "does not include a built-in permission system" and points you to a container or sandbox if you want limits.
  • Codex CLI has the strongest isolation by default. Its approval policy is on-request, and commands run inside an OS sandbox: Seatbelt on macOS, bubblewrap with seccomp on Linux. The sandbox mode defaults to read-only and becomes workspace-write once the folder has a trust decision on record.
  • Gemini CLI has 4 approval modes: default, auto-edit, YOLO and plan. Default mode asks before shell commands and file writes. It has a sandbox, but it is off until you enable it.
  • OpenCode uses allow, ask and deny rules. The default agent allows everything and only asks before reading .env files. We found no OS-level sandbox for local commands in its core package.
  • Hermes Agent checks commands against a list of dangerous patterns. In the default mode, smart, a second model approves the flagged commands it judges low-risk and you are asked about the rest. A hard block list applies even in YOLO mode. Commands run on your own machine unless you choose Docker, SSH or a cloud sandbox as the backend.

The same model will wait for approval in one tool and run any shell command without a word in another. That isn't the model being careful or careless. It is this setting.

4. When the loop stops

The basic rule is the same in all 5: by default the turn ends when the model replies without asking for a tool. The difference is the safety net.

Gemini CLI caps a single message at 100 turns and flags a loop after 5 identical tool calls. We found no turn cap in pi or Codex CLI. OpenCode has an optional step limit per agent that is unset by default. Hermes Agent sets no turn cap by default either, and the comment in its config gives the reason: "caps caused silent mid-task truncation." It relies on loop warnings instead, plus a ceiling of 50 web searches and 50 sub-agents per turn.

For "fix the failing test" this rarely matters. On a long unattended run it decides whether a stuck agent stops itself or keeps spending until you notice.

5. What gets forgotten

Every harness summarizes old conversation when the context window fills up. They disagree on when. Gemini CLI and Hermes Agent compact at 50% of the window, and Hermes raises that to 75% on windows under 512K tokens. OpenCode waits until about 85%, Codex CLI until 90%, and pi until only 16,384 tokens are left.

Scale from 0 to 100 percent of the context window showing when automatic compaction triggers. Gemini CLI and Hermes Agent at 50 percent, OpenCode at about 85, Codex CLI at 90, pi at about 92 on a 200K window.
pi's trigger is a fixed 16,384 tokens before the limit, so its share depends on the window size.

Tool output gets cut too. Codex CLI caps a tool result at 10,000 tokens. Pi and OpenCode cap at 2,000 lines or 50 KB. Gemini CLI truncates shell output at 40,000 characters and Hermes Agent at 50,000. Gemini CLI, OpenCode, pi and Hermes Agent save the full output to a file so the model can go back for it.

If an agent "forgets" an instruction you gave an hour ago, check this before you blame the model. A harness that compacts at 50% starts summarizing your early messages long before one that waits for 90%.

One thing they nearly agree on is where your project rules live. Codex CLI, OpenCode, pi and Hermes Agent all load AGENTS.md, though Hermes Agent prefers its own .hermes.md if the project has one. OpenCode, pi and Hermes Agent fall back to CLAUDE.md when there is no AGENTS.md. Gemini CLI looks for GEMINI.md unless you configure another name.

Model problem or harness problem?

When I talk about these tools I try to keep 2 kinds of opinion apart.

About the models. When I let Codex plan and build, it over-engineers and drifts away from the goal, and it is hard to get it to see the intent behind a task. The GPT models, including the newer GPT-6.2 Astra and Sol, don't have the taste of Opus 5.5 or Fable 5.2. They are good at finding bugs though, sometimes better than Claude. So in my workflow Claude Code plans and executes, and Codex reviews.

About the harnesses. 2 or 3 months ago I liked the Codex app more than Claude's. Since then the Codex desktop app has become bloated. It uses a lot of RAM and CPU and isn't as smooth as it was. The Claude app went the other way. It used to be sluggish and short on features, and now it is fast, light and easy to use. None of that is about a model.

Screenshot of Claude Code in the Claude desktop app. It lists the steps of a backend migration plan with check marks and says what is left before switching over.
Claude Code in the Claude desktop app, checking a backend migration of mine against the plan.

The Claude app also has Claude Design, which I use for 100% of my UI work because it keeps my designs consistent. I haven't found anything like it in Codex, and I almost never use Codex for UI. That one is both problems at once: a model that is weak at UI inside a harness with no design surface.

That is what happened with the crashes. Pi can sign in with a ChatGPT subscription instead of an API key, so I kept my plan and changed only the software around it. It ran smoothly.

Not everything I run is for code. Hermes reads my email, works as the support desk for my products, handles low-priority things on my behalf and does whatever market research I throw at it. It is a harness too, with a very different tool list, which is the point of decision 2.

For the record, the 10 coding harnesses I've used are Codex, Claude Code, Grok Build, Muse Code, Gemini CLI, Antigravity CLI (agy), pi, OpenCode, Oh My Pi (omp) and Kilo Code. These days I run Claude Code with Orca next to it. Orca isn't a harness. It is an ADE that runs harnesses side by side, each in its own git worktree.

Screenshot of Orca. A sidebar lists dozens of worktrees for the AINave frontend, and the main pane shows one session coordinating 3 worker agents that take turns using a server port.
Orca on the AINave frontend. One session is coordinating 3 workers and handing a shared server port from one to the next.

If you are choosing a tool rather than studying the layer, our Claude Code alternatives comparison goes product by product.

Claude Code
Claude CodeDeveloper tools
Anthropic's agentic coding tool for terminal, IDE, desktop and web
View on AINave
OpenAI Codex
OpenAI CodexDeveloper tools
OpenAI's coding agent for the terminal, IDE, desktop and cloud
View on AINave
OpenCode
OpenCodeDeveloper tools
Open-source coding agent for the terminal, desktop and mobile
View on AINave

Does the harness show up in results?

Reading code tells you the harnesses differ. It doesn't tell you whether the differences change outcomes. For that we only have other people's measurements, so here they are with their owners attached.

What was comparedResultWho measured it
One model across different harnesses, Terminal-Bench 2.0Claude Opus 4.6 scored 58.0% in Claude Code and 76.4% in Meta-HarnessThird-party survey of leaderboard data
Harness changes only, model fixed, Terminal-Bench 2.052.8% to 66.5%LangChain, on its own agent
Planner, generator and evaluator harness against a solo run6 hours and $200 against 20 minutes and $9Anthropic, on its own experiment

2 cautions. Most of these are vendors measuring their own products, and even the leaderboard entries in the first row are submitted by the teams themselves. And the effect is not uniform. A comment in Hermes Agent's code records a test on Nemotron 3.5 Super VL, 5 runs with its extra guidance blocks on and 5 with them off. The pass rate moved by under 1 point on 3 benchmarks and by 3.7 points on a fourth, which the authors call not significant.

Our read: the harness can move results a lot at the extremes and barely at all for some model and harness pairs. We didn't find an independent head-to-head of the 5 harnesses above, and we haven't run one. Nothing in this post was benchmarked by us.

When to care, and when not to

  • Before you point an agent at a repo that matters, check decision 3. Know whether your harness asks, sandboxes, or does neither.
  • Before a long session, check decision 5. Put the instructions that must survive in your project file, not in message 3 of the chat.
  • When you switch models inside one harness, remember decisions 1 and 2. You may have switched prompts and tools as well, so judge the result on your own tasks.
  • When a tool starts to annoy you, run the swap test before you cancel anything.
  • Keep your project rules in AGENTS.md. 4 of the 5 harnesses we read load it, which makes it the most portable piece of harness config you own.

You can ignore most of this if you stay on one vendor's defaults with that vendor's models. Tuning the prompt, the tools and the compaction point for each model is what those per-model Codex templates are for.

How we did the source reading

We cloned each repository on November 24, 2026: Codex CLI at commit 4430861, Gemini CLI at 03862c4, OpenCode at 22d022c, pi at d476013 and Hermes Agent at 2506f5b0. One AI reading agent went through each repo with the same list of questions, and every number in this post was then checked against the file it came from. The links in the sections above go to the exact lines at those commits.

Nothing was run. This is a reading of the defaults in the code, and config files, feature flags and server-side settings can change what you get on your machine. Where we say we found no cap or no sandbox, it means our search found none, not that none can exist. One more caveat on Gemini CLI: since June 18, 2026 Google has moved individual users to Antigravity CLI, and it maintains Gemini CLI for enterprise Gemini Code Assist customers.

Sources

Facts last checked: Nov 24, 2026. Versions, defaults and limits in this space change quickly.

Frequently asked questions

Is Claude Code an agent harness?

Yes. Claude Code is a harness around Claude models: it runs the loop, the tools, the permission checks and the session. Anthropic also ships that harness as a library, the Claude Agent SDK, so you can build your own agents on it.

What is the difference between an agent harness and an MCP server?

A harness runs the agent. An MCP server gives the agent tools. The harness connects to MCP servers, decides which of their tools the model can see, and applies its own permission and sandbox rules to the calls.

What is the difference between an agent harness and a framework like LangGraph?

A framework is a toolkit for building a harness. A harness is the finished runtime that works as soon as you install it, such as Claude Code, Codex CLI or OpenCode.

What is the difference between an agent harness and an evaluation harness?

They share a word and little else. An agent harness runs an agent session. An evaluation harness runs test cases against a model or an agent and scores the results. Benchmarks such as Terminal-Bench use an evaluation harness to compare agent harnesses.

Does the harness matter more than the model?

It can matter as much. On Terminal-Bench 2.0, Claude Opus 4.6 scored from 58.0% to 76.4% depending on the harness, according to a June 2026 survey of the leaderboard data. But the effect is not uniform, and most published numbers come from vendors measuring their own products, so test on your own tasks.

Show 5 more questions

Which agent harness has the smallest system prompt?

Of the 5 we read, pi: about 450 tokens of base instructions and 4 tools. Gemini CLI's base prompt is about 5,500 tokens for newer models, and Codex CLI's templates run from 3,452 to 5,059. These are counts from each repository on Nov 24, 2026, using OpenAI's o200k_base tokenizer.

Can I use my ChatGPT subscription in a different harness?

Some harnesses support it. Pi's code includes a sign-in for ChatGPT subscriptions, so it can use OpenAI's models without an API key. Check your plan's terms before you rely on it.

Which file do agent harnesses read for project instructions?

Codex CLI, OpenCode, pi and Hermes Agent load AGENTS.md. OpenCode, pi and Hermes Agent fall back to CLAUDE.md when there is no AGENTS.md, and Hermes Agent prefers its own .hermes.md if one exists. Gemini CLI reads GEMINI.md by default, and Claude Code uses CLAUDE.md.

Is Orca an agent harness?

No. Orca is a desktop app that runs harnesses such as Claude Code, Codex, OpenCode and pi side by side, each in its own git worktree. The harness is still the tool running inside each worktree.

Can I build my own agent harness?

Yes, and open-source harnesses such as Codex CLI, OpenCode and pi give you a starting point. It is worth doing only if you need to change the loop, the model routing or the sandbox. If you need a different prompt, tool or rule, configure an existing harness instead.

Keep reading

All posts

Find your next AI tool.

Browse 21,000+ AI tools, sorted by what they actually do.