Skip to content
OTFotf
All posts

Why Owning Your AI Agent's Context Is Crucial for Production

D
DaveAuthor
8 min read
Why Owning Your AI Agent's Context Is Crucial for Production

Cold open

The single biggest enable of 2026 is that AI coding agents actually ship code now. Claude Code, Cursor, the new agentic loops — they don't just autocomplete, they read your repo, plan, and write multi-file diffs across dozens of files. That used to be a recorded demo. Now it's Tuesday. A junior dev with a good agent is producing what a senior dev with a good editor produced in 2023, in roughly half the keystrokes.

Then they hit Cmd+Z on the session and the context dies.

The "demo to prod" gap is the actual blocker

Every agent session builds up two layers of state. The first is the work product — the files it changed, the diff it shipped. That persists. The second is the understanding — which file holds the auth flow, why the billing webhook signs payloads the way it does, why Card is wrapped in forwardRef but Button is not. That second layer is what makes the agent effective inside the session. It is also what evaporates the second the session closes.

So the next session — or the next dev, or the CI bot, or your teammate who clones the repo — starts cold. The agent re-derives every convention from scratch. It invents a new folder layout. It picks a different button variant. It writes a Stripe webhook handler that almost matches the one already in the codebase but doesn't, and you spend 40 minutes diffing them.

I've watched a 30-file change ship in 8 minutes and then watched a teammate's agent spend 25 minutes reverse-engineering what the first agent did so it could extend it without breaking it. That reverse-engineering time is pure tax. It scales with every handoff: dev-to-dev, agent-to-agent, sandbox-to-CI, sandbox-to-prod.

The thesis is one sentence: the agent is a consumer of your context, not the source of truth. Anything you want the agent to do reliably across sessions has to live in the repo, not in the conversation.

11 production screens. Login, database, payments — all wired.

The SaaS Dashboard Kit ships everything already connected. Nothing to set up. Live demo at saas.otf-kit.dev.

See the live demo

What "context" actually means in a repo

When the agent opens your codebase it needs four things, in order:

  1. Stack and entry points. Language, framework, where the app boots, what runs in tests.
  2. Convention. How files are named, where routes live, where DB schemas live, the import order.
  3. Component contracts. Which UI primitives are blessed, what their props are, what variants exist, what to never use.
  4. Tried-and-tested recipes. For recurring tasks — adding a Stripe webhook, writing a migration, scaffolding a screen — what does the team-agreed version look like.

Most agents get (1) from package.json and a glance at the entry file. (2) they infer from neighboring files, badly. (3) they guess, or they pick whatever library they were trained on most loudly. (4) they invent from scratch every single time.

That last one is where the hour disappears. The agent doesn't know your team agreed webhook handlers go in app/api/webhooks/<provider>/route.ts, with signature verification as the first line, with idempotency keys keyed on the provider's event id. So it writes the webhook somewhere else, in a different shape, and now the codebase has two of them.

ephemeral agent session vs persistent repo context

Sandboxes are great until the session ends

The sandboxed agents — the chat interfaces, the IDE sidebars, the web playgrounds — are brilliant for one-shot generation. They prove the model works. They demo well. They are not where production code lives.

Production code lives in a repo, on a branch, behind a CI run, deployed by a script. None of those four things inherit the agent's conversation. The agent's "understanding" of your codebase is a residue that lives in token activations and gets thrown out with the session.

That is fine for a 10-line proof of concept. It is fatal for a 200-file app that three people ship every day. The fix is not a better agent — those are improving on their own. The fix is moving the understanding out of the conversation and into the repo.

OTF's structured context — what ships in the box

Every paid OTF kit ships with three layers of structured context that survive the session, the handoff, and the model swap:

  • CLAUDE.md at the repo root — the brief the agent reads first. Stack, conventions, component contracts, the things it must never do.
  • .cursorrules — Cursor-specific rules the agent picks up automatically on cursor ..
  • ai/prompts/ — 20+ tested prompt templates for the recurring tasks: add a Stripe webhook, scaffold a screen, write a migration, add a tRPC route, generate a typed client. Each one was run against Claude Code and Cursor and refined until the output matched the kit's conventions without a second pass.

This is the part that doesn't change when the model changes. Claude Code 4, GPT-5, whatever ships next quarter — they all read files. They all respect .cursorrules. They all consume CLAUDE.md. The prompts in ai/prompts/ are plain markdown; the model doesn't care which one runs them.

What a CLAUDE.md actually looks like

# Kit: SaaS Dashboard
Stack: TypeScript, Next.js App Router, tRPC, Postgres, Better Auth, Stripe.

## Conventions
- All routes live under `src/app/<route>/page.tsx`. Never in `pages/`.
- DB schema is the source of truth — `drizzle/schema.ts`. Never write raw SQL in a route.
- Server actions live next to the route in `actions.ts`.
- Components: import from `@otfdashkit/ui`, never from a UI library directly.
- Button: always `<Button variant="primary|secondary|ghost">`. Never `<button>`.
- Card: wrap in `forwardRef`. Never render raw `<div>`.

## Do not
- Don't add a state library. Zustand is the only one. It's in `lib/store.ts`.
- Don't write a new auth flow. Better Auth owns it. See `lib/auth.ts`.
- Don't scaffold a webhook by hand. Use `ai/prompts/stripe-webhook.md`.

## Tested recipes
- Add a Stripe webhook: `ai/prompts/stripe-webhook.md`
- Scaffold a dashboard screen: `ai/prompts/dashboard-screen.md`
- Write a typed tRPC procedure: `ai/prompts/trpc-procedure.md`

That file is ~50 lines. It is the difference between an agent that extends your codebase and an agent that re-derives it. A teammate's agent, the CI bot, the dev who joins next month — they all start from the same brief. No reverse-engineering. No 25-minute tax.

Tested prompts are the part that compounds

A CLAUDE.md describes the world. A prompt in ai/prompts/ describes a task. The two together are what makes the agent predictable. The way OTF tests them is mechanical:

# Run a prompt against a fresh checkout and diff the output
otf test-prompt ai/prompts/stripe-webhook.md \
  --against kits/saas-dashboard \
  --model claude-code-4 \
  --expect fixtures/stripe-webhook.expected.diff

# Same prompt, different model — should produce the same shape
otf test-prompt ai/prompts/stripe-webhook.md \
  --against kits/saas-dashboard \
  --model gpt-5 \
  --expect fixtures/stripe-webhook.expected.diff

If the diff matches the expected fixture, the prompt ships. If it doesn't, the prompt gets refined until it does. By the time a kit ships to a customer, every recipe in ai/prompts/ has been run against at least two models and produces a consistent output. That's the "tested" in "tested prompts." It is the reason a teammate's agent, on day one, with no context, ships a webhook that fits the codebase — not one that almost fits.

The handoff that doesn't lose information

When the first agent shipped the billing refactor, it left a CLAUDE.md that said "billing webhook signs payloads with STRIPE_WEBHOOK_SECRET; idempotency is keyed on event.id; the route is app/api/webhooks/stripe/route.ts." When the second agent picked up the next task, it read that file, looked at the route, and continued.

That is not magic. It is the same agent, in a new session, reading the same repo. But because the repo carried the understanding, the second session was as productive as the first. The handoff cost dropped from 25 minutes to 30 seconds — the time to read the file.

the agent is a consumer, the repo is the source of truth

What this gets us

The pitch for any new agent this year is the same: "we read your repo, we plan, we ship multi-file diffs." That is table stakes now. The actual production question is: when the model rolls over in three months — and it will — does your team's understanding survive?

If the understanding lived in the session, no. You rewrite every brief, re-test every prompt, re-explain every convention.

If the understanding lived in the repo, yes. You swap the model, you keep CLAUDE.md, you keep .cursorrules, you keep the tested prompts. The agent changes. The code keeps moving. The new hire on day three reads the same CLAUDE.md the senior dev wrote on day one. The CI bot reads the same .cursorrules the IDE reads. The mobile build script reads the same component contracts the web app reads.

That is the durable layer. The agent is the tool. The repo is the product.

clay character at a laptop shipping a multi-file diff, the same component rendered web + i

Use the agent. Make the repo hold the context.

Claude Code and Cursor are genuinely good right now. Use them. Run them hard. Ship the multi-file diff in 8 minutes, not 8 hours. That part of 2026 is real.

Then make sure the context that made the agent effective is not sitting in the conversation history. Move it into CLAUDE.md. Move the conventions into .cursorrules. Move the recurring recipes into ai/prompts/. Test each one — run it, diff the output, refine it until it ships first-pass.

That is the part that survives the model swap, the team change, the 2am incident, the new hire on day three. That is what makes the agent a teammate instead of a one-shot generator.

The agent is a consumer of your context. Make the context good, and ship.

ai-toolsarchitecturebackend
OTF SaaS Dashboard Kit

Ship the product, not the setup.

  • 11 production screens — auth, billing, team, analytics, settings
  • Real database, payments, and login — all wired on day 1
  • AI configs pre-tuned so your agent extends instead of regenerates