Black Friday 2026: 80% off everything · code BLACKFRIDAY80 · ends Dec 1 · free Claude course

Ends in0d 00h 00m 00s

Free sample · no email · 1,393 of 8,856 words

The AI Codebase Playbook

The opening of the playbook as your AI agent reads it. The full volume adds the step-by-step playbook, the prompts, the checklist and the sources.

1. The problem

AI coding agents are very good at producing code. That is the problem.

When a person writes code by hand, the cost of writing limits how much gets written. With an agent, writing is nearly free. Reading, understanding, reviewing and maintaining are not. A codebase can grow faster than anyone’s understanding of it.

What usually goes wrong

  • Parallel inventions. The agent does not find the existing date helper, so it writes a new one. Then another. Soon there are three ways to format a date, each with slightly different behavior.
  • Hardcoded values. URLs, IDs, thresholds and sometimes secrets end up inline instead of in configuration.
  • Large, mixed diffs. One request produces a feature, a refactor, a dependency upgrade and formatting changes at once. Nobody can review that properly.
  • Dead code. Old versions of functions, commented-out blocks, unused exports, files named utils2 or new_handler_final.
  • Plausible but wrong code. It compiles, looks idiomatic, and fails in edge cases the agent did not consider: retries, concurrency, time zones, empty input.
  • Tests that test nothing. Tests that mock everything, assert on implementation details, or were adjusted to match the bug.
  • Dependency sprawl and risk. New packages added for trivial tasks. Occasionally the agent suggests a package name that does not exist, which attackers can exploit by registering that name (sometimes called “slopsquatting”; research on package hallucination is in the Sources).
  • Secrets in the wrong place. API keys pasted into code, logs or prompts, then committed.
  • Docs that drift. The README describes the architecture of three months ago.
  • Architecture by accident. Each session makes locally reasonable choices; together they produce import cycles, mixed transports and unclear boundaries.

None of these are unique to AI. Humans do all of them. AI makes them faster and quieter.

What good looks like

  • The repository contains a short, current rules file that agents read at the start of each session.
  • There is a written architecture guide: boundaries, where things live, which patterns to use.
  • Changes are small and single-purpose. Each can be reviewed in minutes.
  • Tests protect behavior that matters, and the agent must run them.
  • Configuration is centralized and validated; secrets never enter the repository.
  • Dependencies are deliberate, pinned and audited.
  • There is a cleanup pass on a schedule, not “someday.”
  • Every agent change is reviewed by a human who understands it.
  • Docs and decision records are updated as part of the change, not later.
  • A short weekly routine keeps all of the above from decaying.

2. Before you start

Inputs

  • Repository access for you and your agent, with version control and a remote.
  • The agent or agents you use, and how each reads project instructions (for example CLAUDE.md, AGENTS.md, .cursor/rules/, .github/copilot-instructions.md).
  • Your stack: languages, frameworks, package manager, test runner, linter, formatter, type checker, build tool.
  • How the code runs: local dev command, environments (development, staging, production), deployment method.
  • Existing CI, if any.
  • Where secrets live today. Be honest; if the answer is “some are in the code,” write that down.
  • The parts of the system that must not break: payments, authentication, data deletion, anything that touches customers or money.
  • One hour for the initial audit, and a recurring weekly slot of thirty to sixty minutes.

Intake checklist

  • I know which agents touch this repository and which instruction files each one reads.
  • I can run the app, the tests, the linter and the type checker locally with documented commands.
  • I have listed the critical paths that must not break.
  • I know where every secret is stored, including any in code or history.
  • I know whether CI runs on every change, and what it checks.
  • I have blocked out a weekly maintenance slot.

3. The method

Ten steps. The first three set up the system; the rest are how you work inside it.

Step 1. Write the project rules file

  • What to do: Create a short rules file at the repository root that your agents read: commands, structure, conventions, boundaries, and things never to do.
  • Why: Agents start each session with little memory of your project. The rules file is the shared context that prevents the same mistakes recurring.
  • Done when: The file exists in each format your agents read (or one file referenced by the others), it is under a few hundred lines, and a fresh agent session can state your test command and two “never” rules after reading it.

Step 2. Write an architecture guide

  • What to do: Document boundaries, module layout, data flow, patterns to use and patterns to avoid, with decision records for important choices.
  • Why: Without a written architecture, every session invents one.
  • Done when: A one to three page architecture document exists, each top-level folder has a stated purpose, dependency direction is written down, and at least one decision record explains a major choice.

Step 3. Install mechanical guardrails

  • What to do: Formatter, linter, type checker, tests, secret scanning and dependency checks, run locally and in CI on every change.
  • Why: Rules in prose are suggestions. Rules enforced by tools are rules.
  • Done when: One command runs all checks locally, CI runs the same checks on every pull request, and a deliberately broken change fails.

Step 4. Work in small, reviewable changes

  • What to do: One concern per change. Plan first, then implement, then verify. Separate refactors from features from fixes.
  • Why: Small changes are reviewable, reversible and bisectable. Large ones are trusted on faith.
  • Done when: Your recent changes each have a single purpose described in one sentence, and most can be reviewed in a few minutes.

Step 5. Use tests as guardrails

  • What to do: Require tests at the seam each change touches. Write characterization tests before refactors. Have the agent run tests and show results.
  • Why: Tests are how you check that plausible code is correct code.
  • Done when: Critical paths have happy, edge and failure tests; the agent’s workflow includes running tests; and coverage on critical paths does not drop without a written reason.

Step 6. Review agent output as a skeptic

  • What to do: Read every diff with a checklist: correctness, duplication, config, security, tests, docs, scope.
  • Why: The reviewer is the last line of defense, and agents are confidently wrong in specific, predictable ways.
  • Done when: You have a written review checklist and have applied it to every agent change for at least two weeks.

Step 7. Keep config, secrets and dependencies clean

  • What to do: Centralize and validate configuration, keep secrets out of code and history, approve every new dependency, pin versions, and audit regularly.
  • Why: These are where AI-assisted code most often creates security and reliability risk.
  • Done when: There is a validated config module and an example env file, secret scanning runs in CI, the lockfile is committed, and there is a written rule for adding dependencies.

Step 8. Run cleanup passes

  • What to do: On a schedule, find and remove dead code, duplicates, stale flags and misleading names, using static tools and review.
  • Why: Entropy is constant. Cleanup must be too.
  • Done when: A cleanup pass has run in the last month, its findings are recorded, and safe removals are merged in small changes.

Step 9. Refactor safely

  • What to do: Characterize behavior with tests, change structure in small steps, keep public interfaces stable, deprecate before removing.
  • Why: Agents can refactor quickly; without guardrails they also change behavior quickly.
  • Done when: Each refactor has tests before it starts, keeps behavior identical as shown by those tests, and lands in steps that each pass CI.

Step 10. Document and maintain weekly

  • What to do: Update docs and decision records as part of each change, keep a changelog, and run a short weekly maintenance routine.
  • Why: The rules file, architecture guide and tests only work if they stay true.
  • Done when: You have run the weekly routine for four consecutive weeks and recorded each run.
THE AI CODEBASE PLAYBOOK cover

Keep going: the full playbook

  • Playbook steps
  • About
  • Commands
  • Structure
  • Conventions
  • Boundaries
  • Workflow
  • Never
  • More
Get the full volume · $5.80BF −80%

Book + Claude skill + MCP access. Black Friday 2026 price. Back to the book page

Or start free

4 complete playbooks, the 7-day Claude Code course and a key your AI can use right now. No card.

Free. We email you about new lessons and volumes now and then. Unsubscribe any time.

Secure checkout with Stripe

Where should we send your key?

Your licence key and receipt go to this email. If checkout fails or you get interrupted, we can send you a link to finish.

One payment, instant access. We never see your card.