AI engineering in production · Lesson 3

My AI coding harness: 220 memories, 10 agents, 15 hooks

I stopped writing better prompts. I started maintaining a harness: 220 one-fact memories, 10 specialist agents, 15 hooks and a rule for every scar. Here is the whole setup, and how to build your own in a week.

Moeid Saleem Khan

I don't write better prompts anymore. I maintain a harness.

Every morning an AI coding agent opens my workspace and already knows that one product must never be pushed without my approval, that a migration which has been applied is never edited again, and that a voice server must not be restarted while a call is live. Nobody typed any of that into a chat. It loaded with the session.

That's the difference I care about. A prompt lasts one conversation. A harness lasts as long as the work does.

This is the exact setup I run, what each layer is for, and the incidents that wrote most of it.

TL;DR → A harness is everything around the model that makes its output safe to ship: instructions, memory, skills, specialist agents, hooks and tools. → Mine has about 220 memory files, each holding one fact, with an index the agent reads at the start of every session. → 10 specialist subagents and 11 skills turn repeated work into playbooks instead of fresh prompts. → Hooks fire on 15 lifecycle events, so some rules run as code and can't be forgotten. → Almost every rule came from something that broke. Write the rule the same day.

Why a prompt is the wrong unit

When people say they "use AI for coding", they usually mean a chat window. You explain the project, the agent does good work, the session ends, and tomorrow you explain the project again.

Repeating yourself is the small cost. The big cost is everything you forget to repeat. The agent has no idea that your billing service has a quirk, that a teammate's branch is mid-merge, or that last Tuesday a "harmless" change took down sign-in. It will happily walk into the same hole twice.

The model is the same for everyone. The harness is the part you own.

I think of it like onboarding an engineer. You wouldn't hire someone senior and then refuse to give them the runbook, the architecture notes and the list of things that hurt last time. A harness is that onboarding, written once and loaded every time.

The six layers

The six layers of my harness, from the rules the agent reads to the tools it can touch

The six layers of my harness, from the rules the agent reads to the tools it can touch

1. Instructions: the constitution

At the top sits one global instructions file that every session reads. It's short and opinionated. TypeScript strict mode. ES modules only. Zod at system boundaries. Don't add comments unless the logic is non-obvious. Prefer editing a file over creating a new one. When unsure about architecture, ask instead of guessing.

Next to it sits a tool-discipline rule: a decision table that says which tool to use for which job. Search code with the search tool, not a shell command. Explore an unfamiliar codebase with an explorer agent instead of reading twenty files one by one. Anything touching three or more files gets a plan first.

Each project then adds its own file with the commands, ports and traps that only matter there. One of mine says, in capitals, that migrations go to the database before the code that depends on them. That line exists because the opposite happened.

Keep this layer small. If it grows past a page, the agent starts treating it like background noise, the same way a person does.

2. Memory: one fact per file

This is the layer that changed the most for me.

My agents have a persistent memory of about 220 small files. Each file holds exactly one fact: a decision, a correction, a standing rule, a gotcha or a pointer. An index file, one line per memory, loads into every session. The agent reads the index, then opens only the memories that matter for the task in front of it.

There are four kinds:

→ User: who I am and how I like to work. → Feedback: corrections I gave, with the reason. "Never use product-count bragging in anything you write for me." → Project: state that isn't in the code. What's live, what's on hold, what's waiting on whom. → Reference: where things live. Dashboards, folders, the right account to use.

Two rules keep it healthy. First, never save what the code or git history already says. Memory is for the things you can't derive. Second, when a memory turns out to be wrong, delete it. A stale memory is worse than no memory, because the agent trusts it.

The "why" line matters more than the rule. "Don't restart the server during a call" is a rule. "Because the file watcher restarts the process and kills every live call" is understanding. With the why, the agent can handle the case the rule didn't name.

3. Skills: playbooks for repeated work

Some jobs come back every week. Publishing a blog post. Shipping a mobile app to the App Store. Automating App Store Connect through its API instead of clicking through the dashboard.

Each of those is a skill: a written playbook with the steps, the commands, the checks and the mistakes we already made. I have 11 of them. When a task matches, the agent loads the playbook and follows it instead of improvising.

The App Store one is my favourite example. It carries every rejection reason we've hit, so the next app doesn't collect the same rejection. A skill is a lesson that can't be forgotten, because it's loaded before the work starts.

4. Subagents: specialists with narrow jobs

I run 10 specialist subagents: tech lead, backend, mobile, DevOps, QA, security, performance, debugger, code reviewer and a fast read-only explorer.

Two reasons this beats one big agent.

Context stays clean. Exploration is noisy. An explorer agent can read forty files and hand back three paragraphs, and the main session keeps its context for the actual change.

Independence buys honesty. A reviewer that didn't write the code, and only gets the diff, catches things the author agent explains away. I give it the code, not my conclusion, so it isn't anchored on my opinion.

The trap is spawning agents for jobs that take three tool calls. Every handoff loses detail. I delegate when the work is independent, parallel or noisy. Everything else stays in the main session.

5. Hooks: rules that run as code

Instructions are requests. Hooks are enforcement.

My setup fires hooks on 15 lifecycle events: session start, every prompt, before and after each tool call, when a subagent starts or stops, after the context gets compacted, at session end. Some are tiny. One stamps the local time on every prompt, so the agent never guesses what "today" means. Another captures what happened during the session so the next one can pick it up.

The principle: if forgetting a rule once would hurt you, it belongs in a hook, not in a sentence. An agent can skim past a paragraph. It can't skip a script that runs before the tool call.

6. Tools: what the agent can reach

The last layer is reach. Through MCP, the same agents can read and change my own workspace (projects, CRM, docs), check calendar and email, and drive a browser when a task truly needs one.

Reach is where the guardrails live. Read access is granted freely. Anything that sends a message, publishes, pays or deletes needs my explicit yes for that specific action. Scopes narrow and never widen. That's the same permission model I built into the Atrix MCP server, and it applies to my own agents first.

Every rule has a scar

Here's the part nobody shows in their setup screenshots. Most of my harness was written the day after something went wrong.

Incidents on the left, the standing rule they produced on the right

Incidents on the left, the standing rule they produced on the right

→ Four agents branched off a stale local master. The merge nearly reverted a sign-in fix that was already live. Rule: fetch and fast-forward before spawning agents, and give each agent the exact base commit.

→ A comment changed inside an already-applied migration. The checksum changed and the new image would have crash-looped production. Rule: applied migrations are immutable, comments included, and every release dry-runs its migrations against a restored copy of production.

→ Unit tests were green while every new profile failed. The tests used a fake extractor, and the real provider rejected the schema. Rule: every deploy sends one real request per schema.

→ Another session committed into a shared repository. A push would have shipped someone else's half-finished work. Rule: check for commits you didn't make before every push.

None of these were model failures. The model did what it was told. The harness didn't yet know what I knew. Writing the rule the same day closes that gap permanently.

How the harness changes my day

The visible change is speed. The real change is where my attention goes.

I spend almost no time explaining context. I spend most of it on three things: writing the brief, reviewing the diff, and deciding what's safe to ship. That's the job now. When agents write the code, your judgment becomes the product.

Long sessions end with a handoff note in a shared knowledge folder, and the next session starts by reading it. There are 23 of those notes today. Nothing important lives only in a chat window that's about to scroll away.

Build your own in a week

A one-week plan to go from chat window to harness

A one-week plan to go from chat window to harness

You don't need my 220 memories. You need the habit. Here's the order I'd do it in.

  1. Day 1: write the constitution. One page. Your stack, your style, your non-negotiables, and "ask when unsure about architecture".
  2. Day 2: add a project file for your main repo. Commands, ports, and the three traps every new engineer falls into.
  3. Day 3: start the memory. One fact per file, with an index. Every time you correct the agent, save the correction and the reason.
  4. Day 4: turn one repeated task into a skill. Pick the one you explained most this month.
  5. Day 5: add one hook for the rule that would hurt most if forgotten once.
  6. Day 6: create two subagents: a read-only explorer and an independent reviewer.
  7. Day 7: review. Delete stale memories. Merge duplicates. Move any rule you keep repeating into code.

What to do this week

→ Count how many times you re-explain the same context to your agent. That number is your harness backlog. → Write down the last three things an agent broke, and turn each into a standing rule with a "why" line. → Move your single most important rule into a hook. → Give your reviewer agent the diff, not your opinion of it.

Less prompting. More engineering.

I write about agentic engineering every week. Follow @moeidsaleem for the next one.

What's the one rule your agents keep forgetting?


Prefer video? Watch it here. Also published on X, where you can reply and discuss.

Run your team with AI, not another tab

Projects, CRM, calendar, hiring and an AI agent in one workspace. Start a 7-day trial; cancel any time before it ends and pay nothing.