Hitesh · StockDrifts
STOCKDRIFTSRESEARCH

How frontier agent harnesses actually work.

Claude Code, Codex CLI, Gemini CLI, Kimi CLI, Grok Build, OpenCode, Hermes, GLM — compared at the layer that matters: the harness. System prompts read directly from the repos, the techniques that repeat, and a build-your-own playbook.
PROMPTS READ FROM SOURCE 8 HARNESSES · JUL 2026 HARNESS LAB
→ to advance
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Executive summary

Every frontier agent is the same ~200-line loop — the real competition moved to context engineering.

01 — The same loop
~200 lines
Send conversation + tool schemas to the model, execute whatever comes back, append results, repeat until plain text. All eight products run this identical core. Everything else is differentiation.
modeltoolsappend
02 — Where they differ
6 layers
Prompt · tools · loop mechanics · context management · safety · memory. The spread is real: prompts span 374 → 3,917 words (10×), tool inventories run 3 → ~18. Every choice is a philosophy.
prompttoolsloop ctxsafetymem
03 — The 2026 battleground
context
Compaction prompts, KV-cache discipline, deferred tool schemas, subagent isolation — and Kimi's D-Mail, where the model edits its own context. Harness and model are now co-designed artifacts.
transcriptsummary
If you remember one line: the loop is trivial — cache discipline, context management and verification rules are the whole game.
Source: Harness Lab — 8 harnesses, prompts cloned & read from source, Jul 2026
harness lab · 02 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Foundations · anatomy

Anatomy of a harness: one loop wearing different clothes, six places to compete.

system prompt+ transcript + schemas model tool calls execute plain text= done append results → repeat
01System promptIdentity, tone, coding rules, output format. 370–4,000 words — the most legible part, and increasingly the smallest.
02ToolsFrom 3 (Codex: shell, apply_patch, update_plan) to ~18. Edit-format wars: exact-string replace vs custom diff grammars.
03The loopTurn-taking, parallel tool calls, background tasks, preserved thinking blocks carried between turns.
04Context managementThe 2026 battleground: compaction prompts, KV-cache discipline, subagent isolation, Kimi's D-Mail rollback.
05Safety & permissionsOS sandboxes (Seatbelt / Landlock) crossed with approval policies. Hooks for deterministic guardrails.
06Memory & extensibilityAGENTS.md / CLAUDE.md, skills with progressive disclosure, MCP as the universal tool bus.
Source: Harness Lab — anatomy distilled from 8 harness codebases & prompts
harness lab · 03 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
The players

Eight harnesses, eight philosophies — from three tools to feature-maximal.

Claude Code
Anthropic · the feature-maximal one
Popularized CLAUDE.md, hooks, skills, subagents, plan mode. Design center: context is the scarcest resource — progressive disclosure everywhere; rules attached to the tools they govern.
skills · hooks · subagents
Codex CLI
OpenAI · the minimalist
Three tools + OS-level sandboxing instead of per-tool prompts. Per-model prompts: codex-tuned models get ⅓ the words — behavior is trained in, not written down.
3 tools · sandbox × approval
Gemini CLI
Google · the benchmarked prompt
Teaches the model token economics of its own strategy; the repo gates prompt edits behind SWE-bench runs. Directives vs Inquiries; self-healing sandbox.
prompt = tested code
Kimi CLI
Moonshot · the context innovator
D-Mail lets the model roll its own context back to a checkpoint, replacing dead ends with a note to its past self. YAML agent specs, persistent subagents, K3: 1M context.
D-Mail rollback
Grok Build
xAI · anchored edits
Smallest general prompt (668 words) and the most novel editor: hashline anchors — content-hashed line refs, atomic batch edits, fresh anchors on staleness.
hashline · 2-level compaction
OpenCode
SST · the model-agnostic switchboard
Ships seven system prompts (anthropic.txt, codex.txt, kimi.txt…) and picks one per model family — hard evidence that prompts are written per model, not per product.
7 prompts
Hermes
Nous · harness as text
Tool schemas live inside the prompt in <tools> tags; calls come back as JSON tags — portable to any stack. Hermes Agent writes its own skills after each task.
374 words · self-writing skills
GLM / Z.ai
Zhipu · the contrarian
Builds no harness at all: Anthropic-compatible API, model trained to fit Claude Code's conventions, sold as a coding plan. The harness is a commodity; the model is the product.
borrow the harness
Source: Harness Lab — repos cloned & read Jul 2026; closed harnesses from first-hand session notes
harness lab · 04 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Measured · wc -w on source

Prompt size is a design decision: when behavior is trained in, the prompt shrinks 3×.

Core system prompt length (words, excl. tool schemas)
measured 2026-07-19 from cloned repos · gray bars = estimates (runtime-assembled or not fully public)
Gemini CLI — assembled coresnippets.ts (runtime-assembled)
≈ 4,200
Codex — base GPT-5 promptprompt_with_apply_patch_instructions.md
3,917
Claude Code — core promptfirst-hand; excl. tool descriptions
≈ 3,000
Kimi CLIagents/default/system.md
2,239
Z.ai Codecaptured prompt
1,393
OpenCode — Claude variantsession/prompt/anthropic.txt
1,335
Codex — codex-tuned promptgpt-5.2-codex_prompt.md
1,221
Grok Build — main templatexai-grok-agent/templates/prompt.md
668
Hermes — function-callingprompt_assets/sys_prompt.yml
374
−69% · SAME PRODUCT OpenAI ships 3,917 words to general GPT-5 but only 1,221 to codex-tuned models — trained-in behavior needs no prose. The endgame prompt is pure constraints.
Source: Harness Lab — wc -w on repo files; estimates flagged. 10× spread across the field
harness lab · 05 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Compared · adoption matrix

Six techniques are table stakes now — the edge lives in what only one harness ships.

Converged — everyone ships it
  • ✓
    Plan / todo tool — update_plan, TodoWrite, SetTodoList: 8 of 8
  • ✓
    Auto-compaction with a dedicated summarizer prompt
  • ✓
    Memory files — AGENTS.md is a Linux Foundation standard, 60k+ repos
  • ✓
    MCP client as the universal tool bus
  • ✓
    Subagents for delegation and context isolation
  • ✓
    Skills — markdown + frontmatter, lazily loaded
Unique edges — one or two shops only
  • Model-initiated context rollback (D-Mail) — Kimi only
  • Hashline anchored edits, atomic batches — Grok only
  • Deferred tool loading — schemas fetched on demand — Claude Code + Codex
  • Intra-turn tool-result compaction — Claude Code + Grok
  • Per-model system prompts — Codex (6 files) + OpenCode (7)
  • Benchmark-gated prompt edits — SWE-bench before commit — Gemini only
Source: Harness Lab technique-adoption matrix — direct repo reads + docs/changelogs, as of Jul 2026
harness lab · 06 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Primary sources · verbatim

Read from source: the prompts say the quiet part out loud.

codex/prompt_with_apply_patch_instructions.md✓ source
"Do not waste tokens by re-reading files after calling apply_patch… The tool call will fail if it didn't work."
gemini-cli/…/snippets.ts · engineering comment✓ source
"You must run the major benchmarks, such as SWEBench, prior to committing any changes to the Context Efficiency section."
kimi-cli/…/dmail · tool prompt✓ source
"You are basically folding the recent messages in your context into a single message… Just explain to your past self."
grok-build/…/templates/prompt.md✓ source
"Weigh each action by how easily it can be undone and how far its effects reach… One approval is not a blank check."
gemini-cli/…/snippets.ts · orchestrator✓ source
"Your own context window is your most precious resource… the sub-agent's entire execution is consolidated into a single summary."
kimi-cli/agents/default/system.md · Ultimate Reminders✓ source
"ALWAYS, keep it stupidly simple. Do not overcomplicate things."
Source: Harness Lab prompts/ — verbatim files cloned Jul 19, 2026; every quote checked against repo text
harness lab · 07 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Frontier · new in 2026

2026's shift: the model now edits its own context — and the prompt became versioned, tested code.

Context frontier
  • Model-initiated rollback — D-Mail inverts compaction: the model picks a checkpoint and folds dead ends into a note to its past self.
  • Anchored editing — content-hashed line refs kill the two classic edit failures: ambiguous matches and files changed underneath you.
  • The preserved-thinking contract — K3 docs warn dropping thinking history makes generation "highly unstable." The transcript is no longer freely editable.
  • Deferred tool loading — ship names only, fetch schemas on demand. Kills the silent 10k-token schema tax; both major harnesses converged in months.
Structural shifts
  • Per-model prompts as standard — the one-prompt-for-all-models era is over; each family gets the dialect it was trained on.
  • The prompt is benchmarked code — Gemini gates prompt edits behind SWE-bench. Version your prompt; regression-test it.
  • Harness/model decoupling as business model — GLM trains to fit Claude Code and sells the plan. The moat moved from scaffold to model-fits-scaffold.
  • Self-writing extensibility — Hermes Agent reflects after tasks and writes its own SKILL.md files; skills are the cross-vendor convention now.
Source: Harness Lab §06 — techniques first shipped or standardized in 2026, per repo history & docs
harness lab · 08 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Playbook · the core

Build your own: the irreducible loop is ~15 lines — ship v0 in a day.

msgs = [system_prompt(cwd, os, date, agents_md)]  # stable prefix — never edit
msgs.append(user_msg)
while True:
    resp = model(msgs, tools=[shell, read, edit, write, todo])
    msgs.append(resp)
    if not resp.tool_calls:
        break                                  # plain text = final answer
    for call in resp.tool_calls:               # parallel if independent
        gate(call)                             # permission check / sandbox
        msgs.append(tool_result(call, run(call), cap=25_000))
    if tokens(msgs) > 0.8 * window:
        msgs = [msgs[0], compact(msgs), *msgs[-K:]]  # dedicated summarizer
Rule 1
Append-only, stable prefix. No timestamps in the system prompt, no editing history — this is what keeps the KV cache hot.
Rule 2
Cap every tool result (~25k tokens, keep head + tail). One verbose build log otherwise eats the window.
Rule 3
Compact at 80% with a structured summarizer: current task, errors + solutions, decisions, file paths. Keep last K turns verbatim.
Source: Harness Lab §07 — the loop every harness runs, distilled to pseudocode
harness lab · 09 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Playbook · decisions

Ten decisions define your harness — and KV-cache discipline is #1 (it's a 10× cost lever).

01
KV-cache disciplineStable prefix, append-only, mask tools instead of removing. Cache hit rate is the #1 cost metric.
02
Few tools, one great shellCodex proves 3 suffice. Every schema is a permanent tax on every request.
03
Exact-string editsUniqueness-checked old/new beats diff grammars. Fail loudly on ambiguity.
04
Prompt = constraints1–2k words, per-model variants. Version it, benchmark it — not lectures.
05
Filesystem as contextNotes and plans on disk; drop bodies, keep restorable pointers; recite the todo near the tail.
06
Compaction is a featureStructured summarizer schema; preserve thinking blocks if the model expects them.
07
Memory = markdownAdopt AGENTS.md + an auto-memory dir with index. No vector DB until markdown fails.
08
Can-do ≠ must-askSandbox (what's possible) × approval (when to ask). Hooks make policy deterministic.
09
Subagents for contextFan out read-only explorers returning 1–2k-token reports; keep one writer. Cheapest 10× on context.
10
Tag channel authorityDistinct tags for harness vs tool vs external content — injection defense as architecture.
Source: Harness Lab §07 — decisions synthesized from all 8 harnesses + Manus context-engineering notes
harness lab · 10 / 12
STOCKDRIFTSRESEARCH
Hitesh · StockDrifts
Playbook · build order

v0 → v5, each with a pass/fail gate — and the seven pitfalls observed in the wild.

v0
The loop. 5 tools, one prompt, no persistence.✓ fixes a real bug in one of your repos end-to-end
v1
Memory + todo. AGENTS.md loading, todo recited in context.✓ follows a written repo convention without being told
v2
Compaction. 80% threshold, structured summarizer, keep last K turns.✓ survives a 3-hour session, still knows the task
v3
Permissions. Allow/deny rules + approvals + OS sandbox for the shell.✓ rm -rf and git push require approval; reads don't
v4
Subagents. One read-only explore agent returning reports.✓ main context under 30% on a whole-codebase question
v5
Extensibility. Skills as markdown, loaded on demand; MCP if needed.✓ add a capability without touching harness code
✗
Cache-busting dynamics — a timestamp in the system prompt silently 10×es your bill.
✗
Tool bloat — wrapping every API endpoint as a tool; more tools ≠ better outcomes.
✗
Editing history — breaks the KV cache and preserved-thinking models alike.
✗
Trusting the model with policy — a prompt rule is a wish; a hook or sandbox is a guarantee.
✗
One prompt for all models — each family has a trained dialect; OpenCode ships seven for a reason.
✗
Unbounded tool output — one verbose log eats the window; cap ~25k, keep head + tail.
✗
No verification rules — without "validation is the only path to finality," agents declare victory on unbuilt code.
Source: Harness Lab §07 — build order + pitfalls, each observed across the 8 harnesses
harness lab · 11 / 12

Steal the discipline,
not the scaffold.

Stable prefix. Few tools. Append-only transcript. Structured compaction.
Markdown memory. Sandboxes over promises. Validation before victory.
Hitesh · StockDrifts
Harness Lab · Stockdrifts Research — prompts cloned & read from source, Jul 2026
harness lab · 12 / 12
01 / 12
→ / scroll · F fullscreen · P print