Today I Learned: notes on working with AI coding agents

Ask the agent for a "Knowledge used" table

A plan can look fine in every step and still be wrong, because the assumption underneath it is wrong. You don't see that by reading the steps.

So I ask the agent to show me what it assumed before it shows me what it wants to do:

Before the plan, give me a table "Knowledge used".
One row for each rule, decision, or existing pattern the plan relies on.
Columns: Entry | What it says | Why it applies here.
Then add a list "Assumptions (no entry behind them)".

Read the table first and mark each row: confirm, wrong, or outdated. Ten rows take about a minute. The same mistake costs an hour once it's buried in a diff.

Don't skip the second list. Every line in it is a guess the agent would otherwise have made without telling you.

Split every task into /plan and /build

A prompt that says "add CSV export" gives the agent two jobs at once. It has to decide what to do, and then do it. It will happily do both in one go, and the only place you get to see its decisions is in the code. By then it's a bit late to argue.

So we split the two.

/plan add CSV export to the reports screen

The plan comes back and the agent stops there. You approve it, change it, or throw it away.

/build

Our rule is that nothing gets built from a plan nobody approved. Throwing away a plan costs nothing. Throwing away a branch with 40 changed files hurts, and that's exactly why people end up accepting a bad one.

One more thing. A good plan has three sections that are easy to forget: Out of scope, Considered, not applied, and Assumptions. If they're missing, ask for them.

One gate question: does this change something already approved?

Agents love to improve things. For new code that's fine. For a rule your team argued about for a week and settled last year, it's a problem.

We put one question in the rules file, and the agent has to answer it before each change:

Ask yourself: does this change something already approved?

- No  -> it is additive. Do it, then report.
- Yes -> stop. Write a PROPOSAL and wait.

The proposal has a fixed shape, so I can read it in ten seconds:

PROPOSAL: change
Existing:    <the rule today, with its ID>
Proposed:    <the new rule>
Why now:     <what changed>
Impact:      <files and behaviour affected>
If approved: <the exact steps>

On safe work the agent stays fast, because it does the thing and tells me afterwards. On the decisions that are mine, it has to stop and ask. I'm a bit annoyed we didn't think of it sooner.

Give the agent a vocabulary, with banned synonyms

You might laugh, but naming is still the hardest part. I said it about CSS years ago and I'll say it again about agents.

In one of our repositories, apply means "push configuration to the server" and deploy means "ship code". An agent that swaps the two writes a wrong commit message, a wrong doc and a wrong function name, all in the same session.

What fixed it for us is a CONTEXT.md file with somewhere between 5 and 20 terms. Each one has a definition and an Avoid line:

**apply** (verb)
Push the generated configuration to the server.
_Avoid_: deploy (for config), sync, push

**marker** (noun)
A file that a script writes to show that a step is complete.
_Avoid_: lockfile, stamp, flag file

And one rule in the file the agent always loads:

Use each term exactly as defined, in the part of speech given.
Never swap in a synonym.

The Avoid line matters more than the definition. The definition tells the agent what the word means. Without the banned list it will still come up with three other words for the same thing, and it will use all of them.

Tell the agent: history is not a template

An agent reads your git log and your old files far more carefully than you do. That sounds great until it finds a workaround from two years ago and copies it, because to the agent it looks like house style.

We all have that code. The "what on earth were we thinking?" code. The agent has no idea you're embarrassed by it.

Two lines take care of most of the damage:

History is not a template.
When you cite past work, label it: "replicate" or "for awareness only".

And one more, for the search it does before planning:

Find the nearest existing example before you plan.
Reuse beats writing. Say which example you follow and why.

Now it has to tell you which old code it wants to copy. If it names the workaround, you can say no before the thing spreads to five more files.

We have a related rule in our own setup. Something the agent saw once in the code is only a candidate pattern. It gets approved when a person says so.

Unknown means out of scope, not "best guess"

The most expensive mistake an agent makes is the confident default. You never said what the timeout should be, so it picked 30 seconds. And it didn't tell you.

I'd take a hundred questions over one silent guess. So unknowns get a place to live:

Never fill a gap with a guess.
If a value, a requirement, or a behaviour is unknown:
1. Record it as an open question (Q-) with what depends on it.
2. Treat the dependent work as out of scope.
3. Continue with the work that does not depend on it.
Ask all blocking questions in one message.

Step 3 is easy to overlook. The agent doesn't stop the whole task because of one unknown. It parks that part and finishes everything else.

The "one message" bit matters more than it looks. Five questions in one message cost me two minutes. Five separate interruptions cost me the afternoon.

New tests must fail first, for the right reason

Ask an agent for a feature with tests and it often writes both at the same time. The tests pass on the first run, everything is green, and you feel great.

You shouldn't. A test that has never failed hasn't proved anything yet.

Write the tests first. Run them.
Each new test must fail, and fail for the right reason:
the behaviour is missing, not a typo or a bad import.
Show me the failure output. Then write the code.

There's a second rule, for the opposite direction:

Never change what an existing test asserts to make code pass.
An assertion you think is wrong goes to me.

You need that second one. The fastest way to a green build is to edit the test, and an agent that wants to finish will find it. To be fair, so will a developer on a Friday afternoon.

Make sub-agents return a fixed handoff

"Done! Everything works."

I don't trust that sentence from a person, and I trust it even less from an agent. When one agent hands work to another, the report that comes back is all the first one gets. If the report is a cheerful summary, the one thing you needed to know is not in it.

So every sub-agent gets the same form to fill in:

Return exactly this:

Branch:      <name>
Behaviour:   <what works now, in one or two sentences>
Files:       <changed files>
Checks:      <commands you ran, and their results>
Deviations from the plan: <each one, with the reason, or "none">
Unresolved:  <what you could not do, or "none">

The last two fields are why the form exists. An agent will never tell you on its own that it skipped step 4. Give it a field called Deviations and it writes it down.

Also, keep parallel agents away from the same files. Two agents editing one file create a merge problem that neither of them can see. You're the one who gets to find it.

Write the "never" list before the agent writes code

We let AI agents work on the repository that manages every laptop in the company. That only works because we wrote the "never" list before they wrote any code.

Before an agent goes near infrastructure, decide what it may never do. Write it down, together with what it should do instead.

Never push, tag, release, or deploy without my go for that action.
Never run commands on a real device or server. Give me the command.
Never edit a generated file. Put the change in the generator.

A "never" rule works when it names the action exactly. "Be careful with production" doesn't count. The agent can't do anything with that.

It also has to say what to do instead. "Give me the command" keeps the work moving, where a plain "don't" just leaves the agent stuck.

And look at the words "for that action" in the first line. A yes for one push is not a yes for the next one.

So the agent writes and a person pulls the trigger. Whatever the agent wrote is in Git, where you can review it and revert it.

When docs and code disagree, the code wins. Then fix the doc.

Be honest, when did you last update your README?

Give an agent a README that's out of date and it follows the README. It can't know which of the two you trust. So tell it:

The code wins over any document.
When they disagree, say so and fix the document.

"Say so" is the half I care about. I want to hear about the disagreement, because every now and then the document is right and the code is the bug.

For that case, add this:

If the answer is "the code is wrong", give me a suggested fix.
Never change the behaviour silently.

We ran this over one of our existing repositories. The agents fixed the outdated documents themselves and only showed us the real clashes: 15 of them, out of 72 findings. We decided all 15 the same day.

0%