Design the Environment, Not the Code: 6 Core Harness Components for AI Coding Agents
The article outlines six essential components — knowledge, tools, environment, feedback, verification, and permissions — for building a Harness engineering environment that enables AI coding agents to work effectively, and details practical implementations like AGENTS.md, prompt engineering, context engineering, CodeGraph, and repository wikis.
Six Core Components of a Harness Environment
The author frames AI coding agents as new hires; the Harness is their onboarding kit. A complete Harness must provide:
Knowledge — project facts (AGENTS.md, architecture docs, product rules, code comments, schemas, task specs) that are discoverable, consistent with code, and suitable for on-demand reading.
Tools — terminal, file editing, browser, log query, etc. Each tool needs clear purpose, input, output, and permissions. Example: fixing a web feature may require search, edit, test, serve, page interaction, console reading.
Environment — reproducible, isolated workspaces where commands like npm test run reliably. Hidden env vars, globally installed deps, local-only databases, and undocumented init steps break agents.
Feedback — observable consequences: test results, page state, structured logs, network requests, metrics, traces. OpenAI's case: each Git worktree starts independently and exposes DOM, screenshots, logs, metrics, traces.
Verification — executable acceptance criteria (tests, static checks, structure checks, user-behavior scripts). The executing agent must not be able to lower standards (e.g., delete tests, weaken assertions).
Permissions — file access scope, network access, credential use, dangerous commands, external writes. Boundaries should be enforced via sandbox, command allowlists, credential isolation, approval gates — not vague "be careful".
Control Loop and Failure Modes
The agent run follows four phases:
Understand: locate goal, rules, relevant code
↓
Act: use permitted tools in controlled environment
↓
Observe: read command output, page, logs, state
↓
Verify: judge completion/failure/need-help with independent evidenceCommon breakdowns:
Action without understanding → wrong directory or rule violation.
Source code without environment → cannot reproduce failure.
Edit without observation → unsure if page works.
Self-report without verification → "done" replaces evidence.
Tools without permission boundaries → out-of-bounds ops to pass task.
Harness quality is measured by whether the agent takes fewer detours, gathers evidence independently, knows when to stop, and how much implicit info humans must supply.
Five Key Practices for Harness Implementation
Repository as single versioned source of truth — move tribal knowledge, chat fragments, scattered docs into searchable, versioned repo.
Turn "done" into "tested" — replace vague completion with Definition of Done, functional tests, performance baselines. Objective tests say "Yes"; agent cannot self-certify.
Guardrails for autonomy — agent chooses implementation path, but edit restrictions, tool permissions, architectural invariants are enforced.
Fast feedback loops — after each step, immediately run tests, review, re-scan, or load-test. Success continues; failure rolls back with evidence.
Persist everything — Spec, Plan, ADR, Skill, tests, reports, decision logs go back into repo as context for next run.
CodingAgent Component Taxonomy
Rule — tells AI the rules.
Skill — tells AI how to perform fixed actions within rules.
Scripts — not for AI, but to verify AI's work.
MCP — connects AI to external knowledge and tools.
SubAgent — splits a large task into multiple collaborating roles.
Workflow — defines when and in what order those roles collaborate.
Prompt Engineering as Behavioral Contracts
Prompt engineering is not hunting "magic prompts" but writing executable behavioral contracts:
Define responsibilities and boundaries (what agent owns, what it doesn't, handling insufficient info).
Calibrate output and process (few-shot, task decomposition for predictable, checkable behavior).
Reuse, security, versioning (templatize, anti-injection, version control like engineering assets).
Debugging prompt failures follows four precise description dimensions:
Separate phenomenon from expectation ("expected X, got Y").
Minimal reproduction steps (actions, inputs, environment).
Already-excluded possibilities ("checked logs, no errors").
Your hypothesis (even if wrong, gives AI a starting point).
Precise problem description is an engineer's core skill; AI just makes its ROI immediately visible. Instead of fancy prompt tricks, first master "phenomenon, reproduction, excluded, hypothesis" — the highest-leverage capability upgrade.
Slash Commands for Reusable Workflows
Custom slash commands (e.g., /prompt-optimize) package structured prompt templates. Example template includes Goal, Context, Constraints, Input, Output, Acceptance Criteria, Examples, Unconfirmed Items. Stored as .github/prompts/xxx.prompt.md (GitHub Copilot) or .claude/commands/xxx.md (Claude Code) with YAML frontmatter for metadata.
Two built-in advanced commands in Claude Code: /goal — goal-driven loop: provide goal + verifiable done condition; independent judge model checks each round; stops when satisfied or max rounds reached. Example:
/goal build AI dev log project until npm run build passes and dev server serves all pages. /loop — time-driven loop: repeat at fixed intervals. Example: /loop 5m check deployment status, notify on error.
Context Engineering: Three-Layer Progressive Disclosure
Context window is limited and expensive; give the right info at the right time.
L1 Session-resident ("badge & binder"): auto-loaded each conversation — CLAUDE.md, AGENTS.md, project tree, core red lines. Ultra-minimal, high-frequency, map-only.
L2 On-demand ("specialist toolbox"): loaded only when a specific SubAgent or Skill is invoked — deep domain rules, workflow SOPs, complex prompt templates. Keeps main context clean.
L3 Persistent knowledge base ("archive/library"): not in memory unless agent actively queries (via MCP, RAG, file search) — long research docs, historical debugging records, massive API dictionaries.
AGENTS.md: Index, Not Encyclopedia
Two roles: (1) core dev constraints (red lines), (2) documentation map (where to find details). Must stay under ~100 lines. Typical "golden trio" at repo root: AGENTS.md — universal AI action guide. CLAUDE.md — tool-specific shortcuts. CHANGELOG.md — project history for context.
Andrej Karpathy's 65-line CLAUDE.md distills four rules:
Think before coding: state assumptions, ask when uncertain, present alternatives, propose simpler approaches.
Simplicity first: minimum code, no speculative abstractions, no unrequested flexibility, no error handling for impossible cases.
Surgical changes: touch only what's needed, match existing style, don't refactor working code, flag dead code but don't delete unless asked.
Goal-driven execution: define success criteria, loop until verified; for multi-step tasks, write a brief plan with verification checks.
Can be added directly to AGENTS.md or installed as a Skill:
npx skills add https://github.com/szkocot/andrej-karpathy-skills --skill karpathy-guidelines.
Project Knowledge Base: Four-Layer Docs Structure
Agent-facing knowledge base ( docs/) organized by stability and entropy:
docs/
├─ index.md # top-level map
├─ 01-项目层/ # Project Layer: biz direction, core flows, arch, ADRs
├─ 02-技术层/ # Technology Layer: middleware, DB, coding standards, libs, APIs
├─ 03-资产层/ # Assets Layer: PRDs, tech designs, test cases, bug lessons
└─ 04-原始层/ # Raw Layer: meeting notes, web pages, chat logs, transcriptsTwo flows:
Bottom-up distillation: raw → assets (PRDs, ADRs) → project layer (decisions).
Top-down routing: agent reads index.md map, fetches tech rules from 02, writes lessons back to 03.
Every directory has index.md with document table for progressive disclosure. Uses Google OKF (Open Knowledge Format) — directory-level Markdown conventions with YAML frontmatter, Git-native, portable.
Initialize with:
npx skills add https://github.com/wuchubuzai2018/expert-skills-hub --skill project-knowledge-hierarchy.
CodeGraph: Structural Code Navigation
Project: https://github.com/colbymchenry/codegraph. Parses code with tree-sitter into nodes (functions, classes, interfaces, routes) and edges (calls, inheritance, references, imports) stored in local SQLite, exposed via MCP.
Solves "Harness environment deficiency" where agents waste 70%+ tokens on lexical scanning (grep/glob/read) causing token explosion, attention dilution, and session amnesia.
Two upgrades:
Lexical scanning → topological navigation (AST + call graph).
Context gateway: assembles high-signal code slices. Benchmarks on 7 real repos (VS Code, Django, Tokio, etc.) show 70%+ fewer tool calls, 57–59% token reduction .
Install:
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh(macOS/Linux) or PowerShell equivalent; then codegraph install and codegraph init in project.
Repository Wiki: Visualization, Review, Cross-Repo Portal
Distinct from docs/ (real-time Context-as-Code). Wiki serves three Harness functions:
Visualization outlet for agent-derived knowledge (Mermaid architecture diagrams, global dictionaries).
Human-in-the-loop review panel — humans prefer web UI for auditing agent's project understanding.
Cross-repo/external agent "diplomatic card" — independent of code branches, exposed via MCP/API for other agents, QA, PM assistants.
Tools: OpenWiki, Z.ai's Zread CLI, author's skill:
npx skills add https://github.com/wuchubuzai2018/expert-skills-hub --skill haizei-project-wiki-generator.
Summary
Harness engineering shifts engineer focus from writing code to designing environments. The six components (knowledge, tools, environment, feedback, verification, permissions) form the control loop. Practical building blocks include AGENTS.md as index, prompt engineering as behavioral contracts, slash commands for reusable workflows, three-layer context disclosure, four-layer docs hierarchy with OKF, CodeGraph for structural navigation, and repo wiki for visualization and cross-team alignment. The goal: every automated execution leaves verifiable, traceable, reusable results — not just more code.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
