Skip to content

Technical Debt and Keeping Docs True

Summary

Teaches how to name and track technical debt in a register, decide what to pay now, refactor safely with an agent, and keep documentation matched to the code.

Concepts Covered

This chapter covers the following 16 concepts from the learning graph:

Concept Concept Impact Score
Technical Debt 37
Deliberate Debt 4
Accidental Debt 4
Debt Interest 4
Debt Register 9
Debt Item ID 2
Debt Triage 4
Pay Now or Log 3
Duplicated Logic 1
Refactoring 2
Refactor with an Agent 1
README 11
Architecture Doc 3
Stale Documentation 2
Docs Generated from Code 1
Document While Fresh 3

Prerequisites

This chapter builds on concepts from:


The House With the Wrong Labels

A couple buys an older house. On the kitchen counter the sellers leave a folder called "Where things are." It says where the water shutoff is, what size filter the furnace takes, and which breaker runs which room. The new owners are grateful. They put the folder in a drawer and start unpacking.

On the first cold night the space heater in the kitchen trips a breaker. The folder says breaker 4 is the kitchen. They flip breaker 4, and the upstairs bathroom goes dark. It takes half an hour with a flashlight to find the right one, which turns out to be breaker 7. Years ago the sellers had an electrician rewire part of the house. Nobody updated the labels. The folder was true once, and then it quietly stopped being true.

Shortcuts You Can See

Sawyer waving welcome Every app built fast has shortcuts nobody wrote down and a doc or two that stopped being true. This chapter shows you how to list the shortcuts, decide which ones to fix this week, and keep the README matched to the code. Then a fresh agent session can trust what it reads.

That same week the couple starts a list on the inside of a cabinet door. "Drip under the bathroom sink. Bucket for now." "Stair rail loose." "Back window sticks." Each line gets a date. The window is fine to leave for a year. The stair rail gets fixed that Saturday, because a guest could fall. The drip is the one they keep putting off. A bucket costs nothing. Six months later they lift the bucket and find the cabinet floor soft with rot. A ten-minute washer swap has become a new cabinet.

This house holds two ideas. The list on the cabinet door is a record of shortcuts, each one cheap today and some of them growing more expensive every week. The folder with the wrong breaker numbers is documentation that stopped matching the thing it describes. Every app built quickly has both. This chapter is about keeping the list, deciding which lines to fix now, and keeping the folder true.

Technical Debt: Shortcuts That Charge Interest

In 1992 the programmer Ward Cunningham needed to explain to his managers why his team wanted time to rework code that already worked. He used a word they knew: debt. Shipping code before you fully understand the problem is like borrowing money. It lets you move faster now, but until you rework the code to match what you've learned, you pay extra on every change, the way a loan charges interest.

Technical debt is the extra future work you take on when you ship code that is quicker to write now than the cleaner version would be. The cost shows up each time someone has to change, read or fix that part of the app. Like a mortgage, debt isn't bad by itself; a shortcut can let a builder launch months sooner. The trouble starts when nobody knows how much is owed or where.

Here are four pieces of the dating-safety app's debt, all from gaps found after launch.

Shortcut Why it was quicker What it costs later
Model prices copied into ten files Each feature pasted the price it needed Every price change means ten edits, and one missed edit makes the cost math wrong
Two different ways of running database migrations Each was the fastest fix at the time it was added An early return in one skipped later migrations, and nobody noticed until the schema was wrong
About 24 bare catch blocks that swallow errors Catching every error stops the app from crashing When something fails, nothing says what or where, so each outage takes longer to explain
Deploy settings kept on the hosting dashboard, not in git Clicking a setting is faster than writing a file Nobody can see what changed, and a rebuild from scratch would miss settings

Each row worked on the day it was written, and the app did what members needed. The debt is in what each row makes harder next month.

Deliberate Debt and Accidental Debt

Deliberate debt is a shortcut you choose on purpose, knowing what it skips, because the time saved is worth more right now. The dating-safety app launched without a staging environment. Suppose, for illustration, that this was a choice: the builder knew staging would catch deploy mistakes, knew it would take days to set up, and launched because members were waiting. That's a fair trade of the kind Chapter 1 described, as long as it's written down with the reason and a point at which to look again.

Accidental debt is a shortcut nobody chose. It builds up as a side effect of working fast. An agent pastes the same logic into a new file instead of reusing the old one, or adds a second way of doing something because it didn't know about the first. The two migration mechanisms above are accidental debt: each session added the one that solved its problem. The prices in ten files and the dev-only plugins in the production build are the same kind.

Accidental debt isn't a mark against the builder. An agent with a fresh context window doesn't know what the last session built unless something tells it, as Chapter 4 explained. Fast work with an agent that forgets between sessions leaves some behind in every app. The two kinds call for two habits:

  • For deliberate debt, write it down when you make the choice. You know the reason now, and you won't in three months.
  • For accidental debt, go looking. A periodic "find the shortcuts" pass with your agent turns it into known debt, and known debt can be managed.

Debt Interest

Debt interest is the extra cost a piece of technical debt adds each time the app is changed, run or explained: extra hours, extra risk, extra confusion. A shortcut in code nobody touches charges almost nothing. A shortcut in code that changes every week charges every week.

So two debts of the same size can deserve opposite treatment. Take the model prices copied into ten files. Suppose collapsing them into one table takes about three hours, and the AI vendors change a price about twice a month. Each change costs an extra half hour to find, edit and check all ten copies. That's a quarter of an hour of interest per week. After 12 weeks the builder has paid in interest what the fix would have cost, and every week after that is time lost. Worse, each price change is a chance to miss a copy, which leaves the spending alerts working from the wrong number.

Now compare the README that listed the wrong ports. Fixing it takes about fifteen minutes. But every time a new agent session or a new person sets up the app, they lose an hour working out why nothing connects. If that happens once a week, the fix pays for itself in the first few days.

Interest also tends to grow. The longer prices stay in ten files, the more likely an eleventh feature copies the pattern, because the agent sees ten examples and follows them. Debt the agent can copy grows by itself.

Price the Shortcut by How Often You Touch It

Sawyer thinking Before you ask how big a fix is, ask how often someone will open that code. A shortcut in a file nobody changes is a bucket under a sink that never drips. Check what it holds up.

The chart below lets you set the cost of a fix and the interest it charges, and see when carrying the debt overtakes paying it off.

Diagram: Pay Now or Carry It

Run the Pay Now or Carry It MicroSim Fullscreen

Pay Now or Carry It

Type: chart sim-id: debt-interest-break-even
Library: Chart.js
Status: Specified
Bloom Level: Apply
Bloom Verb: calculate
Learning Objective: The learner will calculate the break-even week for carrying a piece of technical debt, given the hours to fix it, the extra hours per change, and how often the code changes, and place it in the correct band.

Prerequisites: technical debt, debt interest, break-even (the week when the interest paid equals the cost of the fix), all defined in the section "Debt Interest" above.

Evidence of Mastery: For three scenarios, the learner commits a band for the break-even week ("under 1 week," "1 to 26 weeks," "over 26 weeks") before the chart is revealed. A prediction is correct when it matches the band in the Scenarios table. Mastery is 3 of 3 correct. Moving the sliders afterward is exploration, not evidence.

Misconceptions: (1) A bigger fix is always the one to put off. (2) Debt in code that rarely changes is as urgent as debt in code that changes weekly. (3) A small interest charge never adds up to much.

Instructional Rationale: Apply-level calculation needs a number the learner commits before checking. Committing a band for each scenario, then seeing the two lines cross, ties the arithmetic to the picture, and the three scenarios are chosen so the biggest fix is not the slowest to break even.

Content:

The chart shows two lines over 52 weeks. "Pay now" is a flat line at the fix cost. "Carry it" is the cumulative interest paid, rising each week. The week where "Carry it" first reaches "Pay now" is marked as the break-even week.

Adjustable quantities:

Quantity Min Max Step Default Unit
Hours to fix now 0.25 40 0.25 3 hours
Extra hours each time the code changes 0 4 0.05 0.5 hours
Changes per week 0 10 0.25 0.5 changes

Scenarios, in this order:

# Name shown Hours to fix Extra hours per change Changes per week Interest per week Break-even week Correct band
1 Model prices copied into ten files 3 0.5 0.5 0.25 12 1 to 26 weeks
2 README lists the wrong ports 0.25 1 1 1 0.25 under 1 week
3 Results page styles repeated in three components 2 0.1 0.5 0.05 40 over 26 weeks

Feedback text for each scenario:

# Why
1 A quarter hour of interest a week pays off a three-hour fix in 12 weeks, and the code changes about twice a month, so the fix is worth scheduling.
2 The fix takes fifteen minutes and every new setup loses an hour, so the fix pays for itself within days.
3 The styles change rarely and each change costs only a few minutes extra, so carrying this debt costs less than fixing it for most of a year.

Provenance: Scenario names 1 and 2 come from the dating-safety app's gaps in research/seed-notes.md (model prices copied into ten files; README listed the wrong ports). Scenario 3 is illustrative. All hour and frequency values are illustrative and must be labeled "illustrative numbers"; values for scenarios 1 and 2 match the section "Debt Interest."

Rules: Interest per week = extra hours per change × changes per week. Cumulative interest at week w = interest per week × w. Break-even week = hours to fix ÷ interest per week, shown to two decimal places when under 1 and rounded to the nearest whole week otherwise. When interest per week is 0, no break-even is shown and the chart says "This debt charges no interest at these settings." When the break-even week is greater than 52, the chart says "No break-even within a year." Band edges: under 1 week means break-even < 1; 1 to 26 weeks means 1 <= break-even <= 26; over 26 weeks means break-even > 26. The model counts hours only; the chart notes that it leaves out the risk of a missed copy.

Learner Activity:

  1. The learner sees scenario 1's name and its three values, with the chart hidden, and commits a band.
  2. The chart draws both lines, marks the break-even week, and shows the Why text.
  3. Steps 1 and 2 repeat for scenarios 2 and 3.
  4. Free exploration unlocks. The learner moves the three sliders and the lines and break-even mark update at once. The learner should notice that doubling the changes per week halves the break-even week.

Feedback: Three scenarios, fixed order, one attempt each. Correct: "Right. Break-even at week [n]. " followed by the Why text. Incorrect: "Break-even is at week [n], which is [correct band]. " followed by the Why text. The answer is revealed after each attempt. A count "Scenarios correct: n of 3" is shown.

Starting State: Scenario 1 with the chart hidden. The prompt reads "If you carry this debt instead of fixing it, how long before the interest costs more than the fix?"

Chapter Anchors: The price fix takes about three hours. Prices change about twice a month. Each change costs an extra half hour. Interest is a quarter of an hour per week. Break-even is after 12 weeks. The README fix takes about fifteen minutes and each new setup loses an hour, about once a week.

Tell your agent

"Look through this codebase for shortcuts: logic copied into more than one place, errors caught and ignored, settings that live outside git, and any code comment marked TODO or 'temporary' (notes programmers leave about unfinished work). For each one, tell me how often that code changes and what each change costs because of the shortcut. Don't fix anything yet."

The Debt Register

The list on the cabinet door moved the shortcuts out of the couple's heads and onto something both of them could see. A debt register is a written list of an app's known technical debt, one row per item, kept in the repository next to the code. Each row says what the debt is, where it lives, why it exists, what it costs, and what was decided about it. The register is where accidental debt becomes known debt, and where deliberate debt keeps its reason.

A plain text file in the repo, such as docs/tech-debt.md, works well: the agent and the builder can both read it, and git keeps its history. The dating-safety app kept this kind of file, with a numbered ID for each item. A long list can look alarming, but every row on it is something someone knows about and can plan for.

Here is what a few rows look like. The items come from the dating-safety app; the IDs, weeks and decisions are illustrative.

ID Found What and where Kind Interest Decision
TD-041 Week 9 Model prices copied into ten files across the cost and scan code Accidental Each price change means ten edits; a missed one breaks the spend alerts Log; fix before the next vendor price change
TD-042 Week 9 README lists the wrong ports for the server and front end Accidental Every new setup loses about an hour Pay now; fixed in the same commit
TD-043 Week 1 No staging environment Deliberate, to launch sooner Every deploy is tested on members Log; revisit when the app reaches its first hundred paying members
TD-044 Week 10 Two migration mechanisms; an early return skipped later migrations Accidental The schema can silently fall behind the code Pay now; touches stored data

Write "what and where" specifically enough that a fresh agent session can find the code, and add a status column: open, or closed with the commit that closed it. The decision column is the subject of the next section.

Debt Item IDs

A debt item ID is a short, unique label for one row in the register, such as TD-042, that never changes and is never reused. The ID lets every other record point at the same item. A commit message can say "Fix TD-042: correct ports in README." A pull request can say it closes TD-044. A code comment can say "Prices still copied here; see TD-041." Months later, anyone searching the repo for TD-041 finds the row, the code and the commit together.

Put the ID in the First Line

Sawyer with a tip Start the commit message with the ID, as in "TD-041: move prices into one table." Then git log --grep TD-041 lists every commit that touched that debt, in order.

That only works if each ID names exactly one thing. In the dating-safety app, one ID was once given to two different items. A commit that said it fixed that ID now pointed at both, and a reader had no way to tell which one was closed. Chapter 17, Rules That Enforce Themselves, shows how a small automated check catches a duplicate ID before it is saved.

Add the Row in the Same Commit as the Finding

A register is only as good as the habit that feeds it. The habit is this: when you find a piece of debt, add its row in the same commit as the finding. If the agent spots copied prices while fixing something else, that commit also adds TD-041. At the moment of finding, you and the agent both know what the debt is, where it lives and why it matters. An hour later the agent's context has moved on, and so has yours. A row put off until later often never gets written.

Tell your agent

"Create docs/tech-debt.md with columns for ID, date found, what and where, kind (deliberate or accidental), interest, decision and status. Add a row for each shortcut you found earlier, numbered from TD-001. From now on, whenever you notice a shortcut while working, add its row to this file in the same commit as the work you were doing, and tell me the ID."

Debt Triage: Pay Now, Log or Accept

Most rows in a register don't need fixing soon. The work is deciding which ones do, the way an emergency-room nurse sorts patients into treat now, treat soon and safe to wait.

Debt triage is sorting each debt item into one of three decisions: pay it now, log it with a trigger for when to pay it, or accept it and look again later. Three questions, asked in order, do the sorting. They build on Chapter 1.

  1. Does it touch a must-be-right part? Sign-in, money, private data, the no-false-all-clear rule, the no-locate rule. If a shortcut in one of those parts could hurt a member, pay it now, however big the fix.
  2. Is the fix small? If it takes under half an hour, paying it now usually costs less than writing it down and coming back.
  3. How much interest does it charge? Medium or high interest means log it with a clear trigger, such as a date, a number of members, or "before the next price change." Low interest means accept it.

"Accept" is a decision too. An accepted row stays in the register with its reason, so the next person who finds the same shortcut doesn't spend an hour rediscovering why it was left alone.

Pay Now or Log

A smaller question comes up many times a day: the agent, in the middle of a task, notices a shortcut nearby. Should it stop and fix it?

Pay now or log is the rule for debt found in the middle of other work. Fix it on the spot only if it is small, inside the code you're already changing, and covered by a test. Otherwise add a register row and finish the task. Quick fixes get made while the code is open, and anything larger becomes a row instead of a detour. Chapter 5 called that detour agent scope creep: a session asked to fix one thing comes back having changed twelve.

Practice the triage questions on twelve items from the dating-safety app in the sorter below.

Diagram: Debt Triage Sorter

Run the Debt Triage Sorter MicroSim Fullscreen

Debt Triage Sorter

Type: microsim sim-id: debt-triage-sorter
Library: p5.js
Status: Specified
Bloom Level: Apply
Bloom Verb: apply
Learning Objective: The learner will apply the three debt triage questions, in order, to twelve debt items from the dating-safety app and sort each one into pay now, log with a trigger, or accept, with at least ten of twelve correct.

Prerequisites: technical debt, debt interest, debt register, debt triage, must-be-right parts (from Chapter 1), pay now or log (all defined in the section "Debt Triage: Pay Now, Log or Accept" above).

Evidence of Mastery: The learner places each of twelve debt cards into one of three bins and presses Check. A placement is correct when it matches the Correct bin column in Content. Mastery is 10 of 12 correct on the first attempt. Opening a card's hint is exploration, not evidence.

Misconceptions: (1) The biggest fix should always wait. (2) Debt that touches a must-be-right part can be logged if the fix is large. (3) Accepted debt doesn't need a register row.

Instructional Rationale: Applying a short ordered rule to many cases builds the habit the chapter teaches. Each card shows the three facts the rule needs, so the learner practices the order of the questions, and two cards are built so that a learner who sorts by fix size alone gets them wrong.

Content:

Each card shows the item, whether it touches a must-be-right part, the fix size and the interest.

# Debt item shown Touches a must-be-right part? Fix size Interest Correct bin Why (feedback)
1 The payment webhook has no test Yes (money) About 2 hours High Pay now It touches money, so it is paid now whatever the fix size.
2 Model prices are copied into ten files No About 3 hours High Log with a trigger Not a must-be-right part and not a small fix, but the interest is high, so it gets a trigger such as "before the next price change."
3 The README lists the wrong ports No About 15 minutes Medium Pay now Under half an hour, so fixing it costs less than logging it.
4 There is no .env.example file No About 20 minutes Medium Pay now Under half an hour, so fix it now.
5 The architecture doc describes the design from two months ago No About 2 hours Medium Log with a trigger Every new session reads a wrong map, so it needs a date, but it is not a must-be-right part.
6 Two migration mechanisms; an early return skipped later migrations Yes (stored data) About 1 day High Pay now It touches stored data, so the size of the fix doesn't matter.
7 About 24 bare catch blocks, some in vendor adapters Yes (no false all-clear) About 2 days High Pay now A swallowed vendor error can turn into a clean result, which breaks a must-be-right rule.
8 Results page styles repeated in three components No About 2 hours Low Accept Low interest and not small; keep the row and look again later.
9 Helper functions named in two different styles No About 3 hours Low Accept Untidy but cheap to live with.
10 The pre-push hook only runs for people who turn it on No About 1 hour Medium Log with a trigger Worth a date; Chapter 17 shows the fix.
11 Deploy settings live on the hosting dashboard, not in git No About 20 minutes Medium Pay now Under half an hour, so fix it now.
12 Route modules that don't handle money or sign-in have no tests No About 3 days Medium Log with a trigger Large and not must-be-right, but it keeps costing time, so it gets a trigger.

Bins: "Pay now," "Log with a trigger," "Accept."

The hint for any card lists the three triage questions in order: (1) Does it touch a must-be-right part? (2) Is the fix under half an hour? (3) Is the interest medium or high?

Provenance: Items 1, 2, 3, 4, 5, 6, 7, 10, 11 and 12 come from the dating-safety app's gaps in research/seed-notes.md. Items 8 and 9 are illustrative and must be labeled "illustrative." All fix sizes and interest ratings are illustrative estimates and must be labeled so.

Rules: Apply in order and stop at the first match. Rule 1: touches a must-be-right part = Yes, then Pay now. Rule 2: fix size < 30 minutes, then Pay now. Rule 3: interest is Medium or High, then Log with a trigger. Rule 4: otherwise, Accept. With these rules the answer key is: Pay now = 1, 3, 4, 6, 7, 11 (six cards); Log with a trigger = 2, 5, 10, 12 (four cards); Accept = 8, 9 (two cards).

Learner Activity:

  1. The learner sees twelve cards in a shuffled stack and three empty bins.
  2. The learner moves each card into a bin, and can move cards between bins until Check. Any card's hint can be opened.
  3. When all twelve are placed, the learner presses Check. Each card shows whether it is in the right bin, with its Why text.
  4. The learner should notice that cards 6 and 7 are the two largest fixes and still go in Pay now.

Feedback: Twelve cards, shuffled order, one attempt. Correct: "Right. " followed by the Why text. Incorrect: "This one goes in [correct bin]. " followed by the Why text. If card 6 or 7 was placed in Log or Accept, add: "A must-be-right part is paid now, even when the fix is big." The score "n of 12 correct" is shown after Check, with "Mastery reached" at 10 or more.

Starting State: Three empty bins and a stack of twelve cards. The prompt reads "Which of these debts gets paid this week?"

Chapter Anchors: Three decisions: pay now, log with a trigger, accept. Three triage questions in order. A small fix is under half an hour. The dating-safety app has about 24 bare catch blocks.

Tell your agent

"Go through docs/tech-debt.md and triage every open row. Ask three questions in order: does it touch sign-in, money, private data or a product safety rule; is the fix under half an hour; is the interest medium or high. Fill in the decision column with pay now, log with a trigger (and name the trigger), or accept (and give the reason). Then list the pay-now items for me in order. Don't fix any of them yet."

Duplicated Logic and Refactoring

One kind of debt shows up in almost every app an agent writes. Duplicated logic is the same rule or calculation written out in more than one place, so a change to the rule has to be made in every copy. The model prices in ten files are duplicated logic. So would be a permission check written slightly differently on three routes, or the "not checked" scoring rule repeated in each of the eight check adapters.

Agents produce it because writing a rule again is often easier for them than searching the codebase for the existing one. Each copy is correct when written. Then the rule changes, someone updates seven of the ten copies, and the app has two versions of the truth. With prices, that means wrong cost numbers. With a permission check, it can mean a route that lets the wrong member in.

Refactoring

Refactoring is changing the structure of code without changing what it does: moving, renaming, merging or splitting code so it's easier to understand and change, while every input still gives the same output. Collapsing ten copies into one is a refactoring. Martin Fowler's book Refactoring (1999) made the word common, and his key point was to work in small steps, running the tests after each.

A refactoring that changes behavior is just a change, with all the risk of one and less attention, because everyone thought it was a cleanup. The only way to know behavior didn't change is to have tests that pin it down before you start. Michael Feathers, in Working Effectively with Legacy Code (2004), called code without tests "legacy code" for this reason: nothing tells you when you've broken it.

Refactoring With an Agent Behind Tests

Refactoring with an agent is having an AI agent restructure code in small steps behind tests that pin the current behavior. Any change in what the code does then shows up as a failing test before it's committed. Agents are fast at refactoring and also fast at changing behavior by accident, and the tests catch the accidents. Here is how collapsing the ten price copies goes.

  1. Pin the behavior first. Ask the agent to write tests that record what each of the ten places computes today for a few known inputs, such as the cost of one scan with each model. Run them and commit. These tests describe the code as it is, not as it should be. Chapter 10 covered tests as instructions an agent can't forget; here they are instructions not to change anything.
  2. Make one move at a time. Create the single price table. Commit. Point the first of the ten files at it. Run the tests. Commit. Then the next file.
  3. Stop on red. If a test fails, the agent stops and reports which file and which number changed. A failing test here often finds a copy that had drifted, an old price nobody updated. That is a finding, and it gets its own register row and its own decision, not a quiet fix inside the refactoring.
  4. Review the diff. Each step's diff should show code moving, not logic changing. Chapter 5 covered reading a diff; for a refactoring the question is simple: does any line change a number, a condition or a result?
  5. Close the row. The last commit marks TD-041 closed and names itself in the register's status column.

Don't Let the Agent Edit the Pinned Tests

Sawyer giving a warning When a pinned test fails, an agent may make it pass by changing the test instead of the code. During a refactoring the tests are the contract, so tell the agent they may not change. Then check each diff for an edited test file.

Ten small commits look slower than one big one, but when something goes wrong you know which step did it.

Tell your agent

"We're going to refactor TD-041, the model prices copied into ten files. First write tests that record what each of those files computes today, run them, and commit. Then move the prices into one table, one file at a time, running the tests and committing after each file. Don't change any price or any calculation. If a test fails, stop and tell me which file and which number changed."

Keeping Docs True

Every app has a folder like the one with the wrong breaker numbers, and with agents it matters more, because the agent reads it too.

The README

A README is the file at the top of a repository that tells a newcomer what the project is and how to get it running. GitHub shows it on the repository's front page, and a coding agent reads it early in a session and tends to believe it.

A useful README for an app like the dating-safety app answers six questions:

  1. What does this app do, in two or three sentences?
  2. What do I need installed to run it?
  3. Which environment variables does it need, and where is the template for them?
  4. How do I start it locally, and on which ports?
  5. How do I run the tests?
  6. How does it deploy, and where are the other docs?

Here is a short README skeleton built on those questions. The port numbers and variable names are illustrative.

# Dating-Safety App

Members upload photos, voice clips and text about an online match.
The app runs eight checks in parallel and returns a trust score from 0 to 100.

## Run it locally
1. Copy .env.example to .env and fill in the values (see Chapter 6).
2. npm install
3. npm run dev
   - API server: http://localhost:3001
   - Front end:  http://localhost:5173

## Test it
npm test          # unit tests
npm run test:e2e  # browser tests

## Deploy and docs
Deploys from main. See docs/architecture.md and docs/tech-debt.md.

The dating-safety app's README had two gaps. It listed the wrong ports (the numbered doors on your computer where the server and front end listen), so anyone following it found nothing where the README pointed. And it had no .env.example, the template from Chapter 6 that lists every variable name with a fake value, so a newcomer had to read the code to find which variables existed. Each gap cost about an hour per setup and took under half an hour to fix, and every new agent session counted as a newcomer.

The Architecture Doc

A README gets someone running. An architecture doc explains how the app is put together: the main parts, what each does, how a request flows between them, and where outside services connect. For the dating-safety app it would be a page or two covering the front end, server, database, storage bucket, the job that runs the eight checks, and each vendor adapter. The map of your app from Chapter 3, kept up to date, is a good start.

Stale Documentation

Stale documentation was true when written but no longer matches the code. The folder in the house was stale. So was the dating-safety app's architecture doc, which went on describing the design after the design changed. A missing doc makes people go and look; a stale doc gives them a confident wrong answer, and they stop looking. An agent that reads a stale architecture doc plans its work around parts that no longer exist, or misses parts that do.

Docs Generated From Code

One sure way to keep a fact from going stale is not to write it by hand. Docs generated from code are documentation a script builds from the code itself, so they change when the code does. Ports can be read from the server's config, and routes from the code that defines them. The list of environment variables can come from the env schema (Chapter 6), which can also produce .env.example. A check can stop the build when the README and the code disagree; Chapter 17 shows how.

Reasons can't be generated. Why the score is 50 when nothing ran is a decision, and a person has to write it down. Generate the facts and write the reasons.

Document While It's Fresh

Document while fresh is the habit of updating the docs in the same session as the change they describe, ideally in the same commit. It's the same habit as adding the debt row with the finding. At that moment the agent has the whole picture and can write an accurate paragraph in seconds. A week later, writing it means reading the code all over again. Put one line in the project instruction file from Chapter 4, "Update the README and architecture doc for anything this change affected, in the same commit," and nobody has to remember it.

Find the stale lines in the README below by checking each one against facts taken from the code.

Diagram: Stale README Spotter

Run the Stale README Spotter MicroSim Fullscreen

Stale README Spotter

Type: microsim sim-id: stale-readme-spotter
Library: p5.js
Status: Specified
Bloom Level: Analyze
Bloom Verb: differentiate
Learning Objective: The learner will differentiate stale lines from true lines in a README for the dating-safety app by checking each line against facts read from the code, flagging all stale lines with no more than one wrong flag.

Prerequisites: README, architecture doc, stale documentation, .env.example, docs generated from code (all defined in the section "Keeping Docs True" above).

Evidence of Mastery: The learner marks each of eight README lines as "Matches the code" or "Stale" and presses Check. A mark is correct when it matches the Correct mark column. Mastery is all five stale lines flagged and no more than one true line flagged as stale. Opening the code facts panel is exploration, not evidence.

Misconceptions: (1) A doc that was right once stays right. (2) If the README says it, the code must agree. (3) Missing information isn't staleness; only wrong information is.

Instructional Rationale: Analyze-level differentiation needs the learner to compare two sources line by line and decide which agree. Putting the README next to facts read from the code makes the learner check each line rather than trust it, which is the habit the chapter asks the reader to give their agent.

Content:

Facts from the code, shown in a panel the learner can open at any time:

Source Fact
Server config The API server listens on port 3001
Front-end config The front end runs on port 5173
Env schema Required variables: DATABASE_URL, STRIPE_SECRET_KEY, STORAGE_BUCKET, MODEL_API_KEY
Repository files There is no .env.example file
package.json scripts npm test runs unit tests; npm run test:e2e runs browser tests
Scan job The scan job runs eight checks in parallel
Migrations folder One migration folder; the old second mechanism was removed
Deploy The app deploys from the main branch

README lines, in this order:

# README line shown Correct mark Why (feedback)
1 "The API server runs on port 3000." Stale The server config says 3001.
2 "The front end runs on port 5173." Matches the code The front-end config agrees.
3 "Copy .env.example to .env to get started." Stale The repository has no .env.example file.
4 "You need DATABASE_URL and STRIPE_SECRET_KEY." Stale The env schema requires four variables; the README lists only two.
5 "Run npm test for unit tests." Matches the code The package.json scripts agree.
6 "The scan job runs six checks." Stale The scan job runs eight checks.
7 "Migrations run from either the migrations folder or the boot script." Stale The second mechanism was removed; there is one migration folder.
8 "The app deploys from main." Matches the code The deploy settings agree.

Provenance: The kinds of staleness (wrong ports, no .env.example, a stale description of the design, two migration mechanisms) come from the dating-safety app's gaps in research/seed-notes.md. The eight checks come from the dating-safety app. Port numbers, variable names and the specific wording of each line are illustrative and must be labeled "illustrative."

Rules: A line is Stale when any statement in it disagrees with a code fact or leaves out something a code fact says is required. A line is "Matches the code" when every statement in it agrees with a code fact. Five lines are Stale (1, 3, 4, 6, 7) and three match (2, 5, 8).

Learner Activity:

  1. The learner sees the eight README lines, each unmarked, and a closed panel of code facts.
  2. The learner opens the panel and marks each line. Marks can be changed until Check.
  3. The learner presses Check. Each line shows whether its mark was right, with the Why text and the code fact it was checked against.
  4. The learner should notice that line 4 is stale even though everything it says is correct, because it leaves out two required variables.

Feedback: Eight lines, fixed order, one attempt. Correct: "Right. " followed by the Why text. Incorrect: "This line [matches the code / is stale]. " followed by the Why text. After Check, a summary shows "Stale lines found: n of 5" and "True lines wrongly flagged: n," with "Mastery reached" when all five are found and no more than one true line is flagged. A closing note reads: "Lines 1, 3 and 4 could be generated from the code, so they could never go stale."

Starting State: The README lines are shown unmarked and the code facts panel is closed. The prompt reads "Which lines in this README would send a newcomer the wrong way?"

Chapter Anchors: The dating-safety app's README listed the wrong ports and had no .env.example. The architecture doc was stale. The app runs eight checks. The README skeleton in the chapter uses ports 3001 and 5173.

Tell your agent

"Check the README and docs/architecture.md against the code. For every port, environment variable, command, part and service they mention, tell me whether the code agrees, and show me the list before changing anything. Then fix what's wrong, create .env.example from the env schema if it's missing, and add a script that regenerates the ports and environment variable list in the README from the code. Then add this line to our project instruction file: 'At the end of every task, update the README, architecture doc and tech-debt register for anything this change affected, in the same commit.'"

Back to the House

By spring the couple has relabeled the breaker panel. They did it the morning after the flashlight hunt, while they still remembered which switch ran what. The list on the cabinet door is longer than it was in the fall, but it no longer worries them. The stair rail is fixed. The window still sticks, and they've decided to live with that. The sink got a new washer the week they found the rot.

That is the state to aim for in an app. The debt doesn't go to zero, because some shortcuts are good trades. Every shortcut has a row, every row has a decision, and the docs say what the code does, so a newcomer or a fresh agent session can trust them.

Chapter 16, Security as a Habit, turns to a kind of drift that is harder to see than a wrong port number. It's code whose security assumptions stayed the same while its job grew.

Debt You Can See and Decide About

Sawyer celebrating You can now keep a debt register, triage each row into pay now, log or accept, refactor behind pinned tests, and keep the README matched to the code. Your shortcuts have names and decisions now. Good enough for now, and you know why.

Key Takeaways

  • Write deliberate debt down when you choose it, and go looking for the accidental kind.
  • Keep a debt register in the repo, one row per item with a debt item ID that is never reused. Add the row in the same commit as the finding.
  • Debt triage: pay now if it touches a must-be-right part or the fix is under half an hour; log it with a trigger if the interest is medium or high; otherwise accept it with a reason.
  • Refactor with an agent only behind tests that pin the current behavior, in small committed steps.
  • Stale documentation gives people and agents confident wrong answers. Generate the facts from code, write the reasons by hand, and document while fresh.

See Annotated References