A step-by-step setup guide for Harness², Google Research's open-source framework that tests harness edits on your task, keeps what works, and saves the lessons for later runs.
This guide is reviewed for clarity, service accuracy, and AI-search readability. The next quarterly content review is tracked internally before unsupported metrics or client proof are added.
Most AI agents repeat the same mistakes. They don't remember what worked last time, so you end up fixing the same problems by hand.
Harness² is an open-source research framework that goes after this problem. It runs your task with a few different agent setups and compares the results. It keeps the edits that hold up and saves what it learned for later tasks.
This guide takes you from a fresh clone to your first run on OpenCode or Codex. It then shows you how to check what Harness² changed, reuse its lessons, and keep your cloud bill under control.
How this guide handles exact commands: Harness² is new research code, and it is still changing. Some steps depend on details only the official docs can confirm: the runtime version, install commands, run command, config keys, and output folders. For those, this guide gives you a copy-paste prompt that pulls the exact lines from docs/SETUP.md. It does not retype them. Everything else is written out in full: cloning, Google Cloud setup, sandboxing, reviewing edits, and troubleshooting.
What Harness² is, in plain English
A harness is everything wrapped around an AI model: its instructions, tools, memory, skills and helpers. The model is the engine. The harness is the rest of the car.
Harness² improves the harness and leaves the model alone. It edits the instructions, memory, tools and skills around the model and keeps the edits that work better on your task.
- Name: Harness², read as "Harness squared." The paper writes it as Harness^2.
- Who built it: Google Cloud AI Research with Northwestern University. Eight of the nine paper authors are at Google Cloud AI Research.
- Paper: Harness^2: Recursive Agent Harnessing for an Open World, arXiv 2610.14224, submitted 9 October 2026.
- Code: github.com/google-research/harness2, under the Apache-2.0 license. As of early December 2026 it has more than 25,000 GitHub stars.
- Status: The README states: "This is not an officially supported Google product." Treat it as research code, not a supported product.
What the paper reports: a single improvement step raised scores on three professional benchmarks. The largest gains were up to 11.5 points on WorkBuddy-Bench, 4.5 points on JobBench and 11.8 percentage points on LAB. These are the best results in each table, not typical ones. Expect smaller and less predictable gains on your own tasks.
Scope and cost: read this before you install
| Question | Answer |
|---|---|
| Is the code free? | Yes. It is Apache-2.0 licensed. |
| Are runs free? | No. Model-backed runs need a Vertex AI project on Google Cloud, or a Responses API endpoint if you use Codex. The README says these runs incur API costs. |
| Which agents can it drive? | OpenCode and Codex. Those are the only supported executors. |
| Does it work with Claude Code? | No. Claude Code is not a supported executor. Claude appears only as an optional improver model on Vertex AI. |
| Why can it cost more than a normal run? | Each improvement step runs your task several times: a base run, then a probe run for each candidate edit. It also makes model calls to propose and compose the edits. |
Hypd tip: Before your first run, set a budget alert on the Google Cloud project you'll use. It takes two minutes and prevents a nasty surprise.
How the loop works, step by step
Every task goes through the same cycle.
- Start at H0. Each new task begins from the base harness, called H0. This is the agent's normal, unmodified setup.
- Run the task. The executor (OpenCode or Codex) does the task with H0. Harness² records what the agent did, step by step. This record is called a trajectory.
- Propose. An improver model reads the trajectory and suggests candidate harness edits. The paper calls this model the "editor." It drafts two kinds of edit: a general one and one specific to the task's domain.
- Probe. Each candidate edit is run on the same task. Now you have several runs of one task under different setups.
- Compose. A composer compares how the agent behaved across those runs. It then builds one refined harness from what made the difference.
- Repeat if budgeted. This cycle can run again, either sequentially or in parallel. The
--kbudget sets how much.k=1means one single step. - Save the experience. Harness² takes what it learned from these edits and stores it in an improvement library. That library guides refinement on future tasks.
Why this matters: most self-improving setups need an answer key to know whether an edit helped. Harness² compares runs against each other instead, so it works on new, real-world tasks that don't come with a correct answer.
The 8 harness components it can edit
| Component | What it controls |
|---|---|
| System prompt | The core instructions the agent reads at the start of every task. |
| Guardrails | Rules about what the agent must always do or must never do. |
| Memory | Notes and context the agent keeps and checks while it works. |
| Tool guidance | How and when the agent should use each of its tools. |
| Subagents | Helper agents the main agent can hand smaller jobs to. |
| Skills | Packaged know-how that loads only when the agent calls it. |
| Scripts | Ready-made code the agent can run instead of redoing steps by hand. |
| Plugins | Add-ons that extend what the executor itself can do. |
Cost note from the paper: four of these components are always loaded, so every token in them is paid on every turn. Skills and similar parts load only when the agent uses them. An edit that adds a skill costs nothing until it's used. An edit that makes an always-on part longer costs you on every turn.
The improvement library: what "learning" means here
This is the part people misunderstand most.
- What gets stored: adopted harnesses (the refined setups that won) and lessons backed by evidence from the probe runs.
- What it's for: when a new task arrives, the library guides how Harness² refines that task's harness.
- What it is not: new tasks do not start already improved. Every task still starts at H0. The library makes the next round of refinement better informed. It does not skip it.
- Where it lives: use the extraction prompt in Step 1 to find the exact folder from the docs. Put that folder under version control so you can roll back a bad lesson.
The paper calls this second layer "harnessing-level recursion." Task-level recursion improves one task. Harnessing-level recursion improves how the system improves.
Prerequisites checklist
Research repos often pin exact versions. Fill in each blank from docs/SETUP.md before you install anything, and don't guess. Copy this into your notes:
promptHARNESS² PREREQUISITES — fill every blank from docs/SETUP.md [ ] Operating system: ____________________ [ ] Language runtime + exact version: ____________________ [ ] Package manager: ____________________ [ ] git installed [ ] Executor CLI installed and signed in: OpenCode [ ] Codex [ ] [ ] Model backend: Vertex AI project [ ] or Responses API endpoint (Codex only) [ ] [ ] gcloud CLI installed and authenticated (Vertex AI path) [ ] .env created from .env.example — required variable names: ____________________ ____________________ ____________________ [ ] Budget alert set on the Google Cloud project [ ] Throwaway sandbox folder ready for the first run
Step 1: Clone the repo and pull the exact setup steps
Clone the repository:
promptgit clone https://github.com/google-research/harness2.git cd harness2
Confirm you have the docs and the environment template:
promptgit log -1 --oneline ls docs/SETUP.md .env.example
Next, let your agent read the docs and pull out every exact line you need. Open OpenCode or Codex inside the harness2 folder. Use a read-only or ask-before-running mode, then paste this prompt:
promptYou are inside a fresh clone of the Harness² repo. Do not install, run, or edit anything. Read README.md, docs/SETUP.md and .env.example, then give me: 1. The prerequisites exactly as written in docs/SETUP.md: operating system, language runtime and version, package manager, required executor CLIs, and cloud authentication. 2. Every install and verify command from README.md and docs/SETUP.md, quoted exactly, in the order the docs give them. 3. Every environment variable in .env.example, what the docs say it does, and whether it is required. 4. The exact flag or config value that selects OpenCode vs Codex, and the one that selects the improver model. 5. The Vertex AI settings (project, region, model) and the Responses API endpoint settings for Codex. 6. The exact command for a first run, what it prints, and where it writes outputs, logs, adopted harnesses and the improvement library. 7. Every setting that limits iterations, probes or spend, including --k. Give the file path and line number for every item. If the docs don't cover something, write "NOT IN DOCS". Never guess or fill gaps from general knowledge.
Check every answer against the file and line it cites before you run anything.
Next, run the environment and dependency install commands exactly as docs/SETUP.md gives them. Then run its verify step.
Create your environment file from the template. If SETUP.md tells you to export variables instead, do that.
promptcp .env.example .env git check-ignore .env && echo "OK: .env is ignored by git"
If the second line prints nothing, .env is not ignored. Do not commit it. It will hold credentials.
Then check that your tools are on your PATH:
promptcommand -v opencode || echo "OpenCode CLI not found" command -v codex || echo "Codex CLI not found" command -v gcloud || echo "gcloud CLI not found"
You need at least one executor, plus gcloud if you're using Vertex AI.
Step 2: Connect a model backend
Option A: Vertex AI (works with either executor)
Sign in, select your project, and turn on the Vertex AI API:
promptgcloud auth login gcloud config set project YOUR_PROJECT_ID gcloud services enable aiplatform.googleapis.com gcloud auth application-default login
The last command creates Application Default Credentials. That is the login most Vertex AI client code looks for.
Confirm you're on the right project before you spend anything:
promptgcloud config get-value project
Next, set the project, region and model values in .env. Use the exact variable names from .env.example. Vertex AI models are regional, so pick a region where your chosen model is actually available. You can check this in Vertex AI Model Garden in the Google Cloud console.
Option B: a Responses API endpoint (Codex only)
If you don't use Vertex AI, Codex can run against a Responses API endpoint.
- Put the endpoint URL and its key in
.env, using the variable names from.env.example. - Keep the key out of git. The
git check-ignorecheck in Step 1 covers this. - This option is for Codex. OpenCode runs go through Vertex AI.
Optional: Claude on Vertex AI as the improver model
The improver model proposes and composes the edits. You can set Claude on Vertex AI as the improver. The paper's experiments used Claude Opus 4.8 as the default editor.
- In the Google Cloud console, open Vertex AI Model Garden. Enable the Claude model you want for your project.
- Make sure your
.envregion supports that model. Claude models on Vertex AI are only offered in some regions. - Set the improver model value from the extraction prompt (item 4).
Claude usage through Vertex AI is billed to your Google Cloud project like any other Vertex model.
Step 3: Choose your executor, OpenCode or Codex
| OpenCode | Codex | |
|---|---|---|
| Model backend | Vertex AI | Vertex AI or a Responses API endpoint |
| Pick it if… | You already work in OpenCode, or you want everything on Vertex AI | You already work in Codex, or you have a Responses API endpoint and no Vertex AI project |
| How to select it | Exact flag or config value from SETUP.md (extraction prompt, item 4) | Same |
How to decide:
- Pick the executor you already use every day. Harness² improves the harness of whichever executor ran the task. Improving a setup you don't use won't help you.
- Let your backend decide if you're unsure. If you only have a Responses API endpoint, use Codex. If you have Vertex AI, either one works.
- The paper tested both. Its largest reported gains came under OpenCode, but both executors improved. That doesn't mean OpenCode will do better on your tasks.
Step 4: Your first run
Keep your first run small, cheap and easy to judge.
1. Make a throwaway sandbox. Never point a first run at a real project.
promptmkdir -p ~/h2-sandbox && cd ~/h2-sandbox && git init
2. Pick a task whose result you can check yourself in a minute. Here's one you can paste:
promptIn this folder, create sample_sales.csv with 20 rows of made-up data (columns: date, product, amount). Then write a Python script, monthly_totals.py, that reads the CSV, totals the amount by month, and writes the result to summary.csv. Finally, add a short README.md explaining how to run it.
3. Set the smallest budget. Use k=1, which is one Propose-Probe-Compose step.
4. Run the first-run command from SETUP.md (extraction prompt, item 6). Select your executor and backend as described in Steps 2 and 3.
What to expect:
- The run takes noticeably longer than a normal agent session. It runs your task once with H0, then again for each candidate edit.
- The output folders, logs and adopted harness are written where the docs say (item 6 of the extraction prompt). Write those paths down. You'll need them in Step 5.
- If it fails early, it's almost always authentication, a missing executor CLI, or a region problem. Jump to the troubleshooting table.
Step 5: Check which edits it adopted, and why
When the run finishes, work through this checklist:
promptPOST-RUN REVIEW [ ] Which harness won: base (H0) or the composed one? [ ] Which of the 8 components changed? [ ] What does each edit say, word for word? [ ] What evidence from the probe runs supports each edit? [ ] Which lessons were saved to the improvement library? [ ] Did any guardrail get weaker, or any script/plugin get added? [ ] Is the actual deliverable (summary.csv, README.md) better than the H0 run's?
To see exactly what changed, compare the base harness and the adopted harness. Use the folder paths from your run output:
promptdiff -ru PATH_TO_BASE_HARNESS PATH_TO_ADOPTED_HARNESS
To review the changes with your agent, paste this prompt and attach or point to both harnesses:
promptCompare the base harness and the adopted harness from this Harness² run. For every change, tell me: 1. Which component it touches (system prompt, guardrails, memory, tool guidance, subagents, skills, scripts, plugins). 2. What behaviour it is meant to fix. 3. What evidence from the probe runs supports it. 4. Whether it is specific to this task or safe to reuse on others. 5. Any risk: loosened guardrails, wider tool permissions, new executable scripts or plugins, or anything touching credentials. Flag every change that removes or weakens a guardrail at the top of your answer.
How to tell whether a change really helped:
- Look at the output, not the log. Is the deliverable more correct, more complete, or faster to produce?
- Rerun before you trust it. A single run is noisy. The paper averaged three runs for each score. Run the same task three times with H0 and three times with the adopted harness, then compare.
- Check token cost. An edit that makes an always-on component longer can raise your cost on every future turn. Make sure the gain is worth it.
Step 6: Reuse the improvement library on later tasks
- Keep using the same library location. Later runs read the stored harnesses and lessons to guide their refinement.
- Remember that tasks still start at H0. The library makes each new round of refinement smarter. It does not replace that round.
- Version-control the library. Commit it after each reviewed run:
promptcd PATH_TO_IMPROVEMENT_LIBRARY git init # first time only git add -A && git commit -m "Reviewed Harness² run: <task name>"
- Prune bad lessons. If a lesson doesn't hold up in Step 5's reruns, remove it and commit. One bad lesson can steer future refinement the wrong way.
- Start with similar tasks. Lessons from one kind of work are most likely to help on the same kind of work. Branch out once you've seen it help.
Cost and safety controls
Spend controls
--kbudget. This sets how much task-level recursion runs.k=1is a single step. Start there and only raise it when a task clearly benefits.- Other caps. If SETUP.md lists limits on probes or iterations (extraction prompt, item 7), set them. This guide only names
--kbecause it's the one confirmed in the project's materials. - Google Cloud budget alert. In the console, go to Billing → Budgets & alerts and set a monthly budget with email alerts.
- Vertex AI quotas. Leave default quotas in place at first. They act as a natural ceiling.
Safety controls
- Sandbox every run. Use a throwaway repo or a disposable VM or container. Never run it next to production credentials or customer data.
- Keep secrets out. Your
.envshould be the only place keys live, and git should ignore it. - Review before reuse. Never carry an adopted harness into real work without the Step 5 review. Watch closely for weakened guardrails and new scripts or plugins, since those are executable code.
- Watch harness bloat. Always-on components grow costs on every turn. Trim them if they keep getting longer.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Credentials error ("default credentials not found" or similar) | Application Default Credentials not set | Run gcloud auth application-default login |
| Permission denied, or "API not enabled" | Vertex AI API is off, or your account lacks access | Run gcloud services enable aiplatform.googleapis.com. Ask the project owner to grant the Vertex AI User role (roles/aiplatform.user). |
| Charges or errors on the wrong project | gcloud is pointed at a different project | Check with gcloud config get-value project, then fix it with gcloud config set project YOUR_PROJECT_ID |
command not found: opencode or codex | Executor CLI not installed or not on your PATH | Install it, open a new terminal, and recheck with command -v opencode or command -v codex |
| Model not found, or 404 from Vertex AI | Model not available in your region, or not enabled in Model Garden | Pick a region that offers the model, or enable the model in Model Garden. Update .env. |
| Claude improver fails to load | Claude model not enabled for your project, or wrong region | Enable it in Model Garden and use a region where Claude is offered |
429 errors, "quota exceeded", or RESOURCE_EXHAUSTED | You hit a Vertex AI quota | Lower --k, wait and retry, or request a quota increase in the console (IAM & Admin → Quotas) |
| 401 from a Responses API endpoint | Wrong or expired key | Replace the key in .env |
| 404 from a Responses API endpoint | Wrong endpoint URL or path | Check the URL against your provider's docs, then update .env |
| Settings seem ignored | Variable name doesn't match the template | Compare .env against .env.example character for character |
Still stuck? Search the repo's Issues tab on GitHub for the exact error text before opening a new issue.
Quick-reference cheatsheet
prompt# ── Get the code ───────────────────────────────────────── git clone https://github.com/google-research/harness2.git cd harness2 ls docs/SETUP.md .env.example cp .env.example .env # fill in using names from .env.example git check-ignore .env # must print ".env" # ── Install ────────────────────────────────────────────── # Run the environment + dependency + verify commands exactly as docs/SETUP.md gives them # ── Check tools ────────────────────────────────────────── command -v opencode command -v codex command -v gcloud # ── Vertex AI backend ──────────────────────────────────── gcloud auth login gcloud config set project YOUR_PROJECT_ID gcloud services enable aiplatform.googleapis.com gcloud auth application-default login gcloud config get-value project # confirm before every session # ── Budget ─────────────────────────────────────────────── # --k = task-level recursion budget; k=1 = one Propose-Probe-Compose step (start here) # ── Sandbox ────────────────────────────────────────────── mkdir -p ~/h2-sandbox && cd ~/h2-sandbox && git init # ── Review ─────────────────────────────────────────────── diff -ru PATH_TO_BASE_HARNESS PATH_TO_ADOPTED_HARNESS # ── Version the improvement library ───────────────────── git add -A && git commit -m "Reviewed Harness² run: <task name>"
Key concepts at a glance
- Executors: OpenCode, Codex. Claude Code is not supported.
- Backends: Vertex AI, or a Responses API endpoint (Codex only).
- Improver: optional Claude on Vertex AI.
- Loop: H0 → Propose → Probe → Compose → refined harness.
- Library: adopted harnesses plus evidence-backed lessons. These guide future refinement, and new tasks still start at H0.
- Editable components: system prompt, guardrails, memory, tool guidance, subagents, skills, scripts, plugins.
Primary sources
- GitHub repo: https://github.com/google-research/harness2
- README: https://github.com/google-research/harness2/blob/main/README.md
- Setup docs: https://github.com/google-research/harness2/blob/main/docs/SETUP.md
- Environment template: https://github.com/google-research/harness2/blob/main/.env.example
- Project site: https://harness2.github.io
- Paper (arXiv 2610.14224): https://arxiv.org/abs/2610.14224
At Hypd, we treat tools like this the same way every time: sandbox first, smallest budget first, and nothing reused until it's been reviewed. Harness² rewards that discipline.
FAQ
Can I use Harness² with Claude Code? No. The supported executors are OpenCode and Codex. Claude only appears as an optional improver model on Vertex AI, where it proposes and composes edits. It does not do the task itself.
Is Harness² free?
The code is free under Apache-2.0. Running it is not. Model-backed runs need a Vertex AI project, or a Responses API endpoint for Codex, and they incur API costs. Each improvement step also runs your task several times. Start with k=1 and set a budget alert.
Will my agent start every new task already improved? No. Every task starts from the base harness, H0. The improvement library of adopted harnesses and evidence-backed lessons guides how that harness gets refined for the new task. The agent gets better at improving itself; it does not skip the improving.