Coding Agent Deep Dive

I Built a Monster CLAUDE.md

One markdown file, dropped at a repo root, turned a confidently-wrong coding agent into one that shipped a quantization method beating a peer-reviewed algorithm — over a single weekend. The secret isn't a smarter model. It's a document that redesigns the agent's constraints and environment: Karpathy's coding rules layered on top of harness engineering.

Author: Sumit Pandey (Towards Deep Learning)
Core Idea: Rules + Harness Engineering
Proof: Beat QuaRot on quantization
41% → 11%
Coding error rate after Karpathy's 4 rules
1 weekend
To ship a QuaRot-beating quantizer, few bugs
~200 lines
Where raw prompt compliance starts to decay
101K+ ★
GitHub stars on Karpathy's CLAUDE.md, in weeks
The Four Moving Parts

1. The Failure Mode

Agents don't fail loudly. They pick an interpretation, barrel ahead silently, over-engineer, and quietly “improve” code you never asked them to touch.

2. Karpathy's Rules

A short constraint document that interrupts the agent's default behaviour — think first, stay simple, cut surgically, verify explicitly.

3. Harness Engineering

The scaffolding, constraints, and feedback loops around the agent. The CLAUDE.md is one component; skills, MCP, linters, and GC are the rest.

4. The Payoff

With the environment engineered, the same model became “scary good” — shipping research-grade code fast and with remarkably few bugs.

The one insight to keep

The bottleneck in agent performance is usually not model intelligence — it's environment design. You don't get a better agent by prompting harder; you get one by engineering the constraints and feedback it operates inside.

01

Why Agents Get It Confidently Wrong

A raw coding agent produces code that looks authoritative and is subtly broken. Karpathy's diagnosis is that the model manages neither its own confusion nor yours: it makes wrong assumptions on your behalf and keeps going without checking. Left unconstrained, three failure modes dominate — and prompt compliance itself degrades as instruction files grow past roughly 200 lines, so the answer is engineering the constraints, not writing longer ones.

Silent Assumptions

Faced with ambiguity, the model quietly picks one interpretation and executes it — never surfacing the fork — so it solves the wrong problem beautifully.

Over-Engineering

It adds error handling for impossible cases, invents abstractions for single-use code, and layers in configurable options nobody requested.

Orthogonal Damage

While doing the task, it “improves” adjacent code — reformatting, renaming, refactoring unbroken components — drift that's individually harmless but collectively untraceable.

02

Karpathy's Rules: The Constraint Layer

The backbone of the monster CLAUDE.md is Karpathy's now-viral rule set — a document that reads like a code-review checklist and works by interrupting the model's defaults before it acts. Four core rules cut measured error rates from 41% to 11%; a self-verification protocol and further additions push it lower still.

Rule 1

Think Before Coding

“State assumptions. Ask when unclear. Never guess.”
Kills:

Silent, wrong interpretations executed without surfacing the ambiguity.

Why it works:

Forces the fork into the open — the model presents interpretations instead of gambling on one.

Rule 2

Simplicity First

“Write the minimum code that solves the problem — no abstractions nobody asked for.”
Kills:

Speculative features, bloated abstractions, single-use code turned into utility modules.

Why it works:

The simplest solution that works is defined as the correct one — removing the model's licence to gold-plate.

Rule 3

Surgical Changes

“Don't touch code unrelated to the request. Every changed line traces back to what was asked.”
Kills:

Scope creep, opportunistic refactors, and style drift in code that was already fine.

Why it works:

Makes the diff auditable — every line has a reason, so reviewers can trust it.

Rule 4

Goal-Driven Execution

“Turn vague instructions into verifiable success criteria before starting.”
Kills:

“Clean up this component”-style drift and endless clarification loops.

Why it works:

Give it a target (“pass these 3 tests, keep the props interface”) and let it loop toward it autonomously.

+ Evolution

Explicit Verification & Self-Check

“Run the relevant tests after changing code. Confirm success — never assume it.”
Kills:

The three-steps-perfect-then-hallucinate pattern where later work goes unchecked.

Why it works:

The rule set grew from 4 to a ten-rule self-check protocol precisely so the agent closes its own loop; added rules target silent assumptions, over-engineering, and orthogonal damage to cut the residual error further.

The Anatomy of the File

Every part earns its place. Stripped to its skeleton, the constraint layer of the CLAUDE.md looks like this — short, imperative, and structured so the model can't miss it:

# CLAUDE.md — behavioural contract (read every session) # 1 — Think before coding State assumptions explicitly. If ambiguous, present options and ASK. Never guess an interpretation and run with it silently. # 2 — Simplicity first Write the minimum code that solves the problem. No abstractions, options, or error-handling nobody asked for. # 3 — Surgical changes Touch only what the request requires. Match existing style. Every changed line must trace back to the ask. # 4 — Goal-driven execution Turn vague asks into verifiable success criteria first, then loop until they pass. # 5 — Verify Run the tests. Confirm. Do not assume success.

Representative structure synthesised from the rule set — the point is the shape: terse, numbered, enforceable, and readable in one pass.

03

Harness Engineering: The Environment Layer

Rules alone aren't the whole story. The monster CLAUDE.md is one piece of a larger discipline — harness engineering: the full environment of scaffolding, constraints, and feedback loops that surrounds an agent so it can work autonomously and stay on the rails. Your job shifts from writing code to designing the environment, specifying intent, and building the feedback loops.

Three Nested Layers

LayerThe question it answersWhat you actually design
Prompt“What should be asked?”The instruction text sent to the model for a single turn.
Context“What should be shown?”Every token visible while the model reasons — files, history, tool output.
Harness“How should the whole environment be designed?”Constraints, feedback loops, and operational systems the agent runs inside.
The analogy: a prompt is the command “turn right.” Context is the map and road signs that make the command make sense. The harness is the reins, saddle, fence, and road — the infrastructure that lets many agents work safely at once.

Components of a Real Harness

Context Files (CLAUDE.md / AGENTS.md)

The system of record for rules and architectural decisions. A navigational map, not an encyclopedia — organised by directory proximity so it doesn't waste the context window.

MCP Servers

Selective access to external tools and data — issue trackers, browsers, docs — connected only where they earn their token cost.

Skill Files (SKILL.md)

Task-triggered playbooks for recurring work — reviews, deployments, framework patterns — that load only when their description matches. Complementary to CLAUDE.md, which is always on.

Mechanical Enforcement

Custom linters and structural tests that enforce the rules at system level. Their error messages inject the correction straight back into the agent's context — the rule bites even if the model forgot it.

Automated Code Garbage Collection

Background agents that continuously scan for divergence and open refactoring PRs on their own — countering technical debt as the codebase scales.

04

The Payoff: When the Harness Beats the Model

The headline result: with this environment in place, the agent shipped a quantization method that beats QuaRot — a published, peer-reviewed algorithm — at the bit-widths that actually matter. It took a weekend, not a month, and shipped with remarkably few bugs. And it's not a one-off: across 2026 the same lesson — environment design outperforms raw model swaps — shows up again and again.

ExperimentWhat changedResult
The monster CLAUDE.mdRules + harness around an unchanged modelBeat QuaRot  in a weekend, few bugs
OpenAI CodexHarness-driven autonomous generation1M lines with zero manual code, ~10× faster
HashlineChanged the edit format alonePerformance jumped from 6.7% → 68.3% across models
LangChainHarness improvements, same modelsBenchmark rank moved from 30th → 5th

What to Actually Take Away

Engineer constraints, don't just prompt

A constraint document that interrupts defaults beats a longer, more polite prompt — especially past ~200 lines where compliance decays.

Keep CLAUDE.md a map, not a manual

Terse, numbered, enforceable rules organised by directory proximity. Push deep task knowledge into on-demand SKILL.md files.

Close the loop mechanically

Linters, tests, and self-check rules that feed failures back into context enforce behaviour the prose can only request.

The model is rarely the ceiling

Before reaching for a bigger model, redesign the environment. That's where most of the gain — and the “scary good” feeling — actually lives.