How the harness works, piece by piece
Everything here is plain Markdown, bash and one Python script that sit in my coding agent's config folder. This page explains what each part does, when it runs, and why it exists, so you can copy one piece or the whole setup.
01Overview
The harness turns one coding agent into a small team. The main session plans and decides. Specialist agents do the narrow jobs: reading big files, writing code in an isolated worktree, reviewing a diff as an opponent, testing a running app. Hooks enforce the rules the model forgets, and rules files carry the habits I want on every project.
Four kinds of parts:
- Skills are multi-step workflows the agent loads on demand, like
orchestratefor code changes ande2e-testfor testing a whole app. - Agents are subagents with one job each, their own tools and a pinned model. 32 of them, in six groups.
- Hooks are small bash scripts that run before or after a tool call and can block it or add context. 7 of them.
- Rules are short Markdown files loaded into every session, some only for matching file types. 15 of them.
02Install
Clone the repo and copy what you want into your agent's config folder. Each part works on its own, so you can start with one hook or one skill.
$ git clone https://github.com/HishamM1/harness $ cp -r harness/skills/orchestrate ~/.claude/skills/ $ cp harness/agents/*.md ~/.claude/agents/ $ cp -r harness/hooks ~/.claude/hooks $ cp harness/rules/*.md ~/.claude/rules/
Hooks need to be wired in settings.json. The wiring I use (also in settings.example.json):
{
"hooks": {
"PreToolUse": [
{ "matcher": "Read", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/check-file-size" }] },
{ "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/protect-generated" },
{ "type": "command", "command": "bash ~/.claude/hooks/secret-guard" }] },
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/block-attribution" },
{ "type": "command", "command": "bash ~/.claude/hooks/check-package-manager" },
{ "type": "command", "command": "bash ~/.claude/hooks/check-file-size" },
{ "type": "command", "command": "bash ~/.claude/hooks/secret-guard" }] }
],
"PostToolUse": [
{ "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/lint-rules" }] },
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/ci-after-push" }] }
]
}
}
The hooks need bash, jq and perl. They read the tool call as JSON on stdin and answer with a deny reason or extra context.
03What's in the folder
~/.claude/ CLAUDE.md attribution, delegate models, CI, URLs, paths, copyable text settings.json hook wiring and permissions rules/ 15 rule files, some scoped by file path skills/ orchestrate, e2e-test, design-director, ux, review, … agents/ 32 agents, one Markdown file each hooks/ 7 bash hooks plus lib.sh sync-harness.py copies all of it to Codex, OpenCode and Gemini CLI
The top-level instructions file is short. It holds only what applies everywhere: never add AI attribution to anything published, which model each delegate CLI uses, watch CI after every push, give full URLs and full file paths, and never put copyable text in a blockquote.
04 · skillorchestrate
The workflow for every code change. The main session never edits code itself under this skill. It sizes the task, researches, plans, hands the code to an implementer in its own git worktree, verifies, sends the diff to a reviewer that didn't write it, and squash-merges the result back uncommitted.
Intake
- Each task gets an ID,
T1,T2, and a size. - It asks only for decisions that are the user's to make, never for facts it can find in the code.
- Before starting, it runs the check command on a clean tree and records the known failures, so it never blames itself for a test that was already red.
- At most 3 tasks are active at once.
| Size | When | What runs |
|---|---|---|
| Direct | 1–2 files, under ~30 lines, no schema, auth, billing or queues | The main session makes the edit and verifies |
| Light | 2–3 known files | One implementer, then the verify step. The review gate only for schema, auth, billing or queues |
| Full | Everything else | All nine steps below |
The per-task loop
- Research2–4 read-only agents in parallel:
investigator,Explore,docs-lookup,web-researcher,bulk-reader,diff-summarizer,log-triager. - Verify the researchThe main session re-reads every cited
path:line. High-stakes claims get a second agent. - PlanSchema, public APIs, auth or more than ~5 files need the user's OK first. Open design questions move the task to Awaiting user.
- ImplementAn
implementerin an isolated worktree. Bugs get arepro-writerfailing test first; features get afeature-test-writerafter. Implementers on files that don't overlap run in parallel. If one hits its turn limit, the task is split. - Check the setup
vendorandnode_modulesmust be real folders in the worktree, not symlinks to the main checkout. - VerifyRerun the check command in the worktree and compare with the known failures.
- Adversarial gate
adversarial-reviewer, plusmigration-reviewerfor schema changes. Only Blocker and High findings get fixed. Round two reviews only the fix commits. After two rounds it stops and asks. - Merge back
git merge --squashinto the main checkout, rerun the check, leave it uncommitted, remove the worktree and branch. - PushOnly when asked. Then watch every CI run for that commit to completion.
Status board
Every turn ends with a board of up to 5 rows, one per task, with its stage: Queued, Research, Plan, Awaiting user, Implement, Verify, Review, Merge, Done or Blocked. It's how a long session stays readable.
Other models
When I ask, implementation can go to another CLI instead: Gemini through agy-delegate, OpenCode through opencode-delegate, or Codex. The rule stays the same: the model that wrote a change never reviews it.
05 · skille2e-test
Tests a whole running app the way a QA team would: every flow, every role, phone and desktop widths, every locale, with logs and the error tracker read after each step. It ends with issue drafts, and files them only after one OK.
It asks four questions, at most
- Local or deployed.
- Where to file issues, on the first run only. The answer is saved for next time.
- One OK before filing.
- Anything destructive.
Modes
| Say | What it does |
|---|---|
| local / deployed / a URL | Full run against that target |
| api only, ui only, android, ios | Scoped to one surface or device |
| an area or flow name | Scoped to that part of the app |
| security only, no ux | Filters the check list |
| changed, since <ref>, a PR | Only flows touched by that diff |
| retest | Rechecks filed issues: FIXED, PARTIAL, NOT FIXED or CAN'T TEST |
| resume, budget | Continue a stopped run, or cap its size |
Phases
- DiscoverFive
e2e-planneragents in parallel, one per part: UI, native apps, API, environment, access. The main session re-reads what they cite, starts the app (locally, a worktree with its own stack), gets accounts for each role and an OTP helper, and writes the coverage table. - BaselineMarks the log position, lists the error tracker's open issues, runs health checks, writes the rules file every tester gets.
- Test3–4 testers at a time:
e2e-ui-tester,e2e-api-tester,e2e-native-tester, withaccessibility-auditoralongside. Every action is confirmed against the API or database, not just the screen. - Sweep
e2e-observerreads everything the run added to the logs and the tracker and maps each error to the flow that caused it. - Triage
e2e-triagermerges and dedupes findings into drafts with severity, repro, evidence and acceptance criteria. The main session re-checks every one. - FileScreenshots go to a dedicated branch so issues can link them. No real passwords, ever.
- RetestOn request, after fixes land.
- Clean up and reportTest data removed, and anything left behind listed.
Each run keeps a folder of small helpers (api.sh, ui.mjs, adb.sh, logs.sh, otp.sh, sentry.sh) and the last 5 runs stay on disk so a run can resume.
06 · skillsdesign-director and ux
design-director acts as head of product design for the repo it's in. It keeps five documents in the tracker (brief, decisions, mobile UX, web UX, design system), builds in Penpot, generates brand assets in Recraft, and never edits app code. Design changes reach the code as issues with acceptance criteria.
Its loop: understand the problem, research the risky assumptions, plan the UX before any visuals, decide and log why, design, get an independent critique and an accessibility audit, then hand off.
ux is the rulebook the design agents read: heuristics, flows and their states, navigation, patterns, copy, platform conventions for iOS, Android and web, WCAG 2.2 AA, and Arabic and RTL. It also runs on its own to review a screen or plan a flow.
07 · skillsOther skills
| Skill | What it does |
|---|---|
| agy-delegate | Hands a task to Gemini's CLI in the background, then reviews and lands its diff |
| opencode-delegate | The same, through OpenCode |
| grilling | Stress-tests a plan by asking hard questions until it holds |
| api-design | HTTP API conventions the api-reviewer falls back on when the project has none |
I also use a few skills I didn't write: review, address-findings, recall and explain from entireio/skills, plus break-ui and animate. They aren't in the repo; install them from their sources.
08Agents
Each agent is one Markdown file: a description that says when to use it, the tools it may touch, and a pinned model. Most are read-only. Only four ever write files in the repo, and each writes one kind of thing.
Build
| implementer | Writes the code for one scoped task, in a worktree. Never pushes, merges or reviews its own work |
| repro-writer | Turns a bug report into one failing test. Never writes the fix |
| feature-test-writer | Writes scenario tests: user journeys, permissions, state changes, failure paths |
Review
| adversarial-reviewer | Reviews a diff as an opponent. Required before pushing schema, auth, billing, queues, or more than 3 files |
| migration-reviewer | Schema and migration changes and the code that depends on them |
| api-reviewer | New or changed endpoints against the project's existing API style |
| query-reviewer | N+1 queries, missing indexes, unbounded queries, read-then-write races |
| ui-reviewer | A built screen against its design, from screenshots |
| browser-tester | Drives a changed flow in a real browser and reports the step that breaks |
| accessibility-auditor | WCAG 2.2 AA and iOS and Android rules, at any stage from flow spec to built screen |
Read
| investigator | Traces how or why code works across files, with every claim cited |
| bulk-reader | Reads large files and answers one question, so they never enter the main context |
| diff-summarizer | Summarizes a big diff, branch or PR by file and intent |
| docs-lookup | Fetches current library docs, pinned to the installed version |
| web-researcher | Answers one question from the web, with source links |
| log-triager | Groups application, server or CI logs into distinct errors |
End-to-end testing
| e2e-planner | One part of the test plan from the code: UI, native, API, environment or access |
| e2e-ui-tester | Web, Electron and Tauri flows with Playwright, every width and locale |
| e2e-api-tester | Endpoints with each role's real token: auth, IDOR, validation, races, side effects |
| e2e-native-tester | One native app on one emulator, simulator or device |
| e2e-observer | Maps every new log and tracker error to the flow that caused it |
| e2e-triager | Merges and dedupes reports into issue drafts |
Design
| mobile-ux-architect | IA, navigation, flows and screen list for the mobile app |
| web-ux-architect | The same for the site, dashboard and admin |
| penpot-builder | Builds foundations, components and screens in Penpot |
| brand-illustrator | Logos, icons and illustrations in one consistent Recraft style |
| motion-designer | Interactive Rive animations with their state machines |
| design-critic | Critiques each design round as an opponent |
| product-designer | HTML mockups of every screen and state for a web product |
Plan
| product-owner | Turns designs and code into a backlog of milestones and issues |
| upgrade-planner | Reads every changelog between two versions and lists only the breaking changes this codebase hits |
| schema-diagrammer | Turns a database schema into ER diagrams with plain-language rules |
09Hooks
Rules in a Markdown file are suggestions. Hooks are enforced: they run on every matching tool call, outside the model, and a deny stops the call with a reason the model reads and acts on.
| Hook | When | What it does |
|---|---|---|
| secret-guard | Before Edit, Write, commit | Blocks live API keys, tokens and private keys, and secrets in client-bundled env vars like NEXT_PUBLIC_* |
| check-file-size | Before Read, cat | Blocks reading a file over 350 lines whole, and points to bulk-reader or a ranged read |
| check-package-manager | Before shell | Blocks npm in a pnpm, yarn or bun project, based on the lockfile |
| protect-generated | Before Edit, Write | Blocks hand edits to lockfiles and generated files |
| block-attribution | Before git, gh | Blocks commits and PRs that carry AI attribution trailers or lines |
| lint-rules | After Edit, Write | Flags new code comments, any and @ts-ignore, swallowed exceptions, env() outside config, disabled hook-deps rules, on added lines only |
| ci-after-push | After git push | Reminds the session to watch the CI run to completion and fix only its own failures |
They share lib.sh, which splits a shell command into segments, so cd app && npm i is checked from inside app.
10Rules
Each rule is a short list of habits. Seven load everywhere; the stack ones load only when a matching file is in play.
| Rule | What it says |
|---|---|
| sdlc | Reproduce bugs before fixing. Plan big changes first. Clean up after yourself. Decide what happens when two requests race |
| code-hygiene | Search every consumer before renaming. No empty catches. One logical change per commit. Thin controllers, small services. No code comments |
| verify-before-done | Run the smallest check that exercises the change before saying it works, and say which one ran |
| delegation | Which agent for which job, and when not to delegate. Covered below |
| do-it-yourself | If the agent has the access, it does the step instead of handing it to me |
| use-generators | Create files with the project's generator, add packages with the package manager |
| formatter | Run the project's formatter on exactly the edited files, never repo-wide |
| context7 | Fetch current library docs instead of answering from memory |
| arabic-voice | How to write in my voice in Egyptian Arabic and in English |
| laravel, typescript, python | Stack conventions, scoped by file type |
| prisma, drizzle, expo | Schema and package workflows for those tools |
11Delegation
Subagents cost tokens and lose detail in both directions, so the main session delegates only when the raw material is much bigger than the answer (big files, logs, CI output, docs) or when it needs an independent review.
- Anything that edits code stays in the main session, except the implementer under orchestrate and the two test writers.
- Independent read-only tasks go out 2–4 at a time, in one message, so they run in parallel.
- Subagents don't see the conversation, so every prompt carries the constraints that matter and the exact question.
- Once a search is delegated, the main session doesn't repeat it. It verifies any claim it acts on by re-reading the cited lines.
- Review loops fix only Blocker and High findings, and stop after two rounds.
12Sync to other CLIs
sync-harness.py copies the whole setup to Codex (~/.codex), OpenCode (~/.config/opencode) and Gemini CLI (~/.gemini), so every agent CLI I use follows the same rules.
- Rules and the instructions file are merged into each CLI's
AGENTS.md. - Lines that only make sense in the source CLI are rewritten. A specific wait tool becomes "the available command and wait tools", for example.
- Agents are converted to each CLI's format, and the search agent is mapped to that CLI's own explorer.
- MCP servers are converted too, except ones tied to a single project.
$ python3 ~/.claude/sync-harness.py
13FAQ
Isn't this a lot of tokens?
Less than it looks. Small tasks skip the loop entirely (the Direct size). The read agents exist to save tokens: a 2,000-line file read by bulk-reader comes back as a paragraph.
Why can't the writer review its own code?
A model reviewing its own diff tends to confirm its own reasoning. A fresh reviewer that gets only the diff, and is told to find what's wrong, catches more.
Where do I start?
The hooks. They're small, they work with any workflow, and check-file-size plus secret-guard pay off on day one. Then orchestrate.