Context Beats Cleverness
AI-Powered PHP Development in Practice • Part 2 of 9 • PHP • AI
Part 1 ended on a claim: a mediocre prompt against a codebase with a good context file beats a brilliant prompt against a codebase with none.
This time, the proof — because I don’t expect you to take it on faith. I ran it, in front of a room, the same way I’d want to see it myself.
Here’s the setup. A multi-tenant Laravel issue tracker, and one plan-only prompt, run twice:
Add the ability to invite a user to a tenant.
Propose a plan: which files you'd change and how.
Don't edit any files.
Same model. Same codebase. Same wording, word for word. The only difference between the two runs is one file.
Run one, no context file. The plan is reasonably competent — a route, a controller method, a form request, a test. Nothing embarrassing. Then look at how it handles seats. Either it doesn’t mention them at all, or it counts users right there in the controller and compares against the limit. It has no way to know that in this product, a seat is a billed user, a tenant at its limit cannot add one more, and there is exactly one place that rule is allowed to live. That rule lives in a Slack thread, or a product manager’s head, or — if we’re honest about most real codebases — nowhere written down at all.
Run two, one file later. The plan routes the seat check through Tenant::canAddUser(), uses the product’s vocabulary, scopes reads by tenant. Sometimes it goes one better: it reads canAddUser() itself, notices the <= inside, and asks whether a tenant at its limit should really be able to add one more user.
It should ask. That comparison is wrong — it’s a planted bug, and Part 7 is where we make tests that catch it. But notice what just happened: with no context, the model invented a seat check; with context, it engaged with the real one, bugs and all.
That’s the whole idea. Everything after this section is elaboration on what you just read.
Context Is Leverage That Compounds
A prompt helps you once. A context file helps every prompt — yours, your teammates’, every agent session against this codebase — for as long as it stays accurate.
That’s the difference between a single-use tool and leverage that compounds. And it reframes the whole discipline: context engineering isn’t prompt mysticism, it’s documentation discipline with a forcing function. Everything a good context file should contain is stuff a thoughtful senior engineer would already want written down for human onboarding. The AI angle just finally gave teams a reason to write it.
The Context Value Hierarchy
Not everything is worth the same bytes. The ladder, from wasted space to highest leverage:
Low leverage Formatting / style rules ← a linter does this better
Generic "best practices" ← the model already knows this
High leverage Architecture decisions + WHY ← not visible from reading code
Business rules & vocabulary ← lives in people's heads
Forbidden / footgun patterns ← costly, written down once
The bottom rung deserves its own warning: letting the context file do a linter’s job wastes the highest-leverage real estate you have. Pint enforces brace style better than prose ever will. Every line spent re-stating what mechanical tooling already guarantees is a line not spent on the seat rule. Reserve the file for what genuinely can’t be derived mechanically from the code.
And notice what “leverage” implies about specificity. The demo’s improvement came from specificity, not length. One well-written business rule outperforms a paragraph of generic advice:
Seat checks go through
Tenant::canAddUser(). Never reimplement the limit inline, even though a one-line count looks simpler: billing reads the same method.
There’s the rule, the why, and the footgun, in two sentences.
What Belongs: Three Blocks
If you want a starting structure for a PHP codebase, this is the one the workshop builds live:
Domain vocabulary. The words your code uses that don’t mean what they’d mean anywhere else.
- A "tenant" is a paying customer organisation.
- A "seat" is a billed user within a tenant. `seats_limit` is the most
users a tenant may have: a tenant AT its limit cannot add one more.
Architecture conventions — with the why attached:
- Tenancy is by `tenant_id` on users and issues. Every read and write is
scoped to the requesting user's tenant.
- Seat checks go through Tenant::canAddUser(). Never reimplement the
limit inline: billing reads the same method.
Forbidden patterns — things that look like reasonable patterns in general but are wrong here specifically. “Never reimplement the seat limit inline” is one. In older codebases it’s “never call the legacy SOAP client directly — go through the adapter, it handles the retry quirk.” These are the expensive lessons, paid for once, written down once.
That last block is where a 15-year-old codebase earns its keep in this conversation. My day job is a clinical-trials platform where “just read the code” is a full afternoon and namespaces are, genuinely, the new feature. The forbidden list is the part of that afternoon you can hand over permanently — to an agent, or to a new hire. The mechanism is identical. Context engineering is institutional memory that survives you leaving the room, the project, or the company.
The New-Hire Test
How long should it be?
Long enough to cover real, non-obvious decisions. Short enough that a human would actually read it cover to cover. The workshop’s working cap: roughly a page — the example file is 35 lines — and the test I use is a slight twist on the classic:
If you wouldn’t hand it to a new hire on day one, don’t hand it to the model.
More context is not always better. A bloated file that repeats what the linter enforces doesn’t just waste context window — in practice the model reads it less carefully than a tight, well-organized five hundred words. You’re optimizing for density, not volume. And pitch it at the right altitude: too granular reads as micromanagement and gets skimmed; too vague (“write clean code”) constrains nothing. The demo’s deliberate failure mode was exactly that — a first draft of “follow best practices” changed nothing. The concrete seat rule changed everything.
Mechanics: Which File, Where It Lives
- Name it for the tool. Claude Code reads
CLAUDE.md. OpenCode, Copilot, and Codex readAGENTS.md(OpenCode falls back toCLAUDE.mdonly when there’s noAGENTS.md). When in doubt, writeAGENTS.md; teams on multiple tools keep one source and sync the other. - Commit it. This is infrastructure, not personal config — checked into the repository, owned collectively, exactly like coding standards documents already are. The workshop repo deliberately ships with no context file: writing yours is the exercise.
- Scope it by directory when it grows. A root file plus per-subtree files — e.g.
tests/AGENTS.md: “known bugs are->todo()tests; remove->todo()in the same commit as the fix.” This is how context files stay under a page on large codebases. - Don’t link what the agent can’t follow. Your internal wiki is invisible mid-session unless it’s specifically wired up. The context file is what’s guaranteed to be read. Link for humans if you must, but the load-bearing facts go in the file.
Fresh Every Session — Or It Will Mislead
The most common conflation in this whole subject: “the model learned my codebase” vs. “the model reads this file at the start of every session.” It’s the latter. Nothing carries over between sessions.
Which makes staleness the quiet failure mode. A context file that’s three architecture changes out of date is arguably worse than none — no context leaves the model honestly uncertain; stale context makes it confidently wrong about your system, and confident wrongness is the exact failure this whole series is built to catch.
So treat it as a living document with an owner: updated in the same pull request that changes the architecture decision it documents, reviewed like any other documentation, occasionally pruned. A team that writes it once during a hackathon gets a liability within months. A team that reviews it gets compounding returns forever.
The Three Failure Modes
- Too long. The new-hire test fails; the model skims it anyway. Cut the formatting rules first — they were never yours to write.
- Rules without reasons. “Never do X” survives until someone clever fixes it. “Never do X — billing reads the same method” survives contact with the next agent. Reasons are what let a constraint generalize past the exact case that created it.
- The forbidden list doesn’t exist. The footgun you hit once in 2019 is still armed, and the model walks into it with total confidence because in general, the pattern is fine. That’s the class of bug the file exists to kill — cost you one afternoon to write down, saves it every month since.
Resources
- Workshop repo: github.com/gunnard/workshop-starter — ships with no context file, on purpose; a worked example sits on the
ch4-startbranch - Slides (PDF): /talks/ai-powered-php-development-in-practice.pdf
- The series: /writing/
Next: Part 3 — Three Prompt Patterns That Cover Most PHP Work.
This is Part 2 of a nine-part series adapted from “AI-Powered PHP Development in Practice,” my half-day workshop at Longhorn PHP 2026 (Austin, October 15). Start with Part 1.