Context Engineering Is a Writing Problem
TechBy Chris West••9 min read

Context Engineering Is a Writing Problem

Six weeks later, you can't tell which decisions you made and which the agent made for you. On attributing every choice in a design doc, why unreviewed agent defaults calcify into requirements, and why a rule in CLAUDE.md is a prior rather than a constraint.

Six weeks after shipping a feature I went back to change how it handled a missing measurement, and stopped, because I could not tell whether returning empty instead of throwing was a decision I had made or one the agent had made on my behalf. The code did not say. In a diff the two are indistinguishable.

That is the failure mode worth talking about, because it is the one that compounds. Everything else in this piece is downstream of it.

I keep three kinds of document for building with agents: an instruction file of standing rules, a design doc per feature, and an implementation plan. Most writing on this covers the first one, usually some version of "keep your CLAUDE.md short." The interesting one is the second, and the convention that matters most in it is not a format. It is attribution.

Defaults calcify into requirements

Building a feature through a conversation generates dozens of small decisions. Which option is default. What happens when a value is missing. Which direction a calculation runs. Which edge case returns empty instead of throwing. You made some deliberately. The agent made the rest, reasonably, and mostly without flagging them.

The two categories have genuinely different status. Yours are invariants, chosen against a goal. The agent's are plausible defaults that no one evaluated. The hazard is that the codebase records them identically, so a month later you cannot separate them, and unreviewed defaults quietly acquire the authority of requirements. You end up defending behavior in a refactor that nobody ever chose, because it is in main and the tests assert it.

So every decision in my design docs carries its source:

1# Explorer: "Getting there" travel section on Compare
2
3Status: approved in conversation 2026-11-04 (owner: Chris).
4Calls marked "(builder's call)" were made by Claude and are open
5to correction.
6
7## The drives
8- Fusion torch: constant 1 g, unlimited fuel, flip at midpoint
9 (owner: "accelerate at say 1G constantly, with unlimited fuel")
10- No antimatter option (owner: "go with fusion, not antimatter")
11- Default selection: the fusion torch (builder's call) because it is
12 the one drive where Earth clock and ship clock visibly diverge.
13
14## Out of scope
15- Explorer only (owner: "exclusive to the exoplanet app").
16- Bump `explorerVersion` only; `version` unchanged unless shared
17 website code changes behaviour.

Two things fall out of this that I did not anticipate.

Grepping for the builder's-call tags returns exactly the set of decisions nobody reviewed. That is a review queue I get for free, and it is far smaller and far more useful than re-reading the diff. It also inverts the default: an unreviewed choice is now visible rather than invisible.

And quoting my own words survives paraphrase. "Accelerate at say 1G constantly" is not how I would write it in a spec, which is the point. Six weeks on I can still distinguish what I asked for from what the agent understood me to mean, and the gap between those two is where most drift actually lives.

The scope section does the other half of the work, written as exclusions rather than goals. Which app ships it, which version field moves, what stays unchanged. An agent will helpfully generalize a feature you wanted narrow, and a list of goals gives it no reason not to.

Tests that assert whatever you built

The same problem shows up in the test suite, in a form that is easier to miss because it comes with a green check.

Ask an agent to implement something and then test it, and you frequently get assertions that encode whatever the implementation happened to produce. The suite passes. It is also a tautology: it proves the code does what the code does. Nothing in it would catch the case where the formula is subtly wrong, because the expected values were read off the formula.

The fix is to write the numbers down first, with tolerances, and confirm the suite is red before any implementation exists.

1// Written before travelPhysics.ts existed. Run, confirmed red, then implemented.
2it("fusion at 1 g to Proxima", () => {
3 const t = tripTimes(4.24, "fusion");
4 expect(t.earthYears).toBeCloseTo(5.87, 2); // coordinate time
5 expect(t.shipYears).toBeCloseTo(3.54, 2); // proper time
6 expect(t.topSpeedC).toBeCloseTo(0.9495, 3);
7});
8
9// The degenerate ends, which is where the naive closed form dies.
10it("stays finite for every drive from 1e-3 to 1e5 ly", () => { /* ... */ });
11it("is Newtonian on a tiny trip", () => {
12 const t = tripTimes(0.01, "fusion");
13 expect(t.shipYears).toBeCloseTo(t.earthYears, 3);
14});

Those figures came from working the relativistic rocket equations by hand before asking for code. That is the part you cannot delegate, because it is the only independent check on the thing you are about to generate.

Related: mark anything that must not be paraphrased. My plans list physical constants and epochs with the word "verbatim" beside them, because an agent handed a value that looks over-precise will round it in good faith, and the drift stays invisible until something downstream disagrees by a percent.

And write a review-focus list before implementation: the cases most likely to break, each pinned to the task that has to prove it. Degenerate inputs, missing measurements, two identical operands, both extremes of the valid range, numerical stability where catastrophic cancellation is plausible. For the travel-time work that meant specifying the asinh/acosh forms rather than the algebraically equivalent ones that lose precision on short trips. Producing that list is the part of this process that most resembles engineering, and the part an agent is worst at, because it requires knowing where your own system is thin.

Prose is a prior, not a constraint

Which brings me to the thing I would most want to correct about how instruction files get discussed. A line in CLAUDE.md raises a prior. It does not enforce anything. If you are shipping on the assumption that a written rule guarantees behavior, you have misunderstood what you built.

So wherever a rule is mechanizable, it should not be prose at all.

Under Capacitor my app's origin is https://localhost, which means a literal fetch("/api/...") resolves against the local bundle and 404s silently, and any share link derived from window.location is dead for whoever receives it. All of that divergence lives in one module, and the rule is enforced in CI rather than in prose:

1// nativeUrls.guard.test.ts
2const ALLOW = "native-url-ok";
3
4it("never composes /p/ or /system/ paths inline", () => {
5 const offenders = sourceFiles()
6 .flatMap(({ path, lines }) =>
7 lines
8 .map((text, i) => ({ path, line: i + 1, text }))
9 .filter(l => /["']\/(p|system)\//.test(l.text))
10 .filter(l => !l.text.includes(ALLOW)))
11 .filter(l => !l.path.endsWith("nativeUrls.ts"));
12
13 // Fails with file:line, so the fix is mechanical.
14 expect(offenders).toEqual([]);
15});

This holds regardless of what made it into context, and it holds against human contributors too. The instruction file keeps one line pointing at the module and the test does the work. The escape hatch is a comment token, so legitimate exceptions are explicit and greppable instead of silently tolerated.

The triage order: enforce in CI if you can, then in the type system, and write prose only for the residue. In practice that residue is about intent and permanence rather than code shape. You cannot write a test asserting "never reuse a versionCode," because the constraint lives in a system you do not control.

What earns a line

For the prose that remains, the budget is real and it is not a style question.

Everything in an instruction file occupies the same context as the code the model needs to read, and competes with it. Forty lines of formatting preference is not forty lines of signal; it is dilution of the three lines that would have prevented an outage. Instruction files degrade with length in a way documentation does not, because documentation is read selectively by a human with a goal, and an instruction file is read in full by a process that has no goal yet.

The selection criterion I settled on is the absence of a feedback loop. A loud failure is self-correcting: the type check fails, the agent reads stderr, the agent converges. Spending context on those is waste. A silent failure has no signal at all, so the only place to intervene is before the work starts.

The cleanest example in my repo is the Android version code:

1// Wrong, and wrong in a way that passes review.
2// Squash merges make this DECREASE: a branch counts more commits
3// than main has after its squash, and Play hard-rejects any
4// versionCode that is not strictly greater than the last upload.
5const versionCode = Number(execSync("git rev-list --count HEAD"));
6
7// Monotonic by construction, independent of history shape.
8const EPOCH = Date.UTC(2026, 0, 1);
9const versionCode = Math.floor((Date.now() - EPOCH) / 60_000);

Commit count is the obvious choice, produces working code, and is unrecoverable when it fails, because a rejected build burns its number permanently and the rejection arrives at upload time. Three build targets sharing one .next directory and route files needing a non-standard extension are the same shape: reasonable default, no error, wrong outcome.

Then, since this is a writing problem, the phrasing carries more weight than the selection:

1<!-- Weak. A constraint with no mechanism is a constraint you
2 can rationalize past, and the model will. -->
3- Don't set NEXT_PUBLIC_NATIVE_BUILD on Vercel.
4
5<!-- Strong. Rule, mechanism, blast radius, failure mode. -->
6- Never set `NEXT_PUBLIC_NATIVE_BUILD` on Vercel. It is a
7 local-native-build-only flag. `src/app/galaxy/page.tsx` checks it at
8 server runtime and skips reading the session when it is true, so on
9 Vercel /galaxy renders signed-out for every visitor, with no error
10 to signal why.

Same rule, and the second version generalizes. It explains a causal chain instead of asserting a prohibition, so it produces correct behavior in adjacent situations you never wrote down. State the consequence, name the failure mode, and point at the alternative.

Mine is about twenty lines. Growth past that is a smell.

Three artifacts, three lifetimes

The division of labor is just lifetime. Standing invariants that outlive every feature go in the instruction file. Decisions scoped to one feature go in its design doc, with provenance. Steps scoped to one branch go in the plan, and get deleted when it merges. Putting a feature decision in the instruction file is how that file grows past the point of being read.

Worth knowing that the first of the three is being standardized underneath us. In December 2025 the Linux Foundation stood up the Agentic AI Foundation (opens in a new tab) and OpenAI donated AGENTS.md (opens in a new tab) to it, alongside Anthropic's Model Context Protocol and Block's goose, with AWS, Microsoft, Google, Bloomberg and Cloudflare as platinum members. The launch coverage (opens in a new tab) framed the three projects as plumbing between agents and the systems they operate on, which is the right read: MCP standardizes how an agent reaches tools, and the instruction file standardizes how a repository hands over its accumulated judgment.

The practical argument for converging on one filename is that tools disagree about which they load, so a repo touched by more than one agent maintains the same invariants in two places, which is how they drift.

Nothing comparable is happening for design docs or plans, which is roughly why I wrote this.

What it costs and what it is worth

The direct return is easy to justify. These documents take minutes and each one retires a class of defect that used to cost a day.

The indirect return surprised me. You cannot write a rule until you understand the mechanism, and the mechanism is a much higher bar than the symptom. More than once I have started a line like "never hand-edit this generated value" and realized I did not actually know what overwrote it, or at what point in the build, or why my edit vanished without a trace. Finding out is the work. The line is the receipt.

So this is the rare documentation task that improves the system before anyone reads the output. I understand my own build pipeline materially better than I did before I had to specify it for a process that arrives knowing none of it.

Two honest limits. A prose rule is a prior, not a guarantee, and anyone treating CLAUDE.md as a safety mechanism should move the rules they care about into CI. And a stale instruction file is worse than none, because it is confidently wrong in exactly the way the file exists to prevent. Like any checklist it works only while every line is still true.

But the attribution habit is the one I would keep if I had to drop the rest. Not because it prevents defects, which it mostly does not, but because it preserves the distinction between what I decided and what was decided for me. Six weeks later that is the only thing in the repository I cannot reconstruct from the code.

Comments

Loading comments...

Leave a Comment

0/2000 characters (minimum 10)