You just inherited a repo. A client handed you a half-finished app, or you opened a side project you haven't touched since spring, or you forked something from GitHub because it's 80% of what a gig needs. The clock is running, so you point your AI coding agent at it and say "add invoice exports." Twenty minutes later it has rewritten a config file, invented a second date formatter, and edited the wrong entry point. You now spend your evening untangling an agent that was trying to help.
That's the cost of letting an agent edit before it understands. The fix costs you one conversation: a read-only mapping pass, where the agent studies the codebase and reports back before it's allowed to change a single line. Do that, verify the map, save it, and your first real edit goes where you meant it to.
Why edit-first fails on unfamiliar code
An agent starts each session with no memory of your repo. When you ask for a change in code they've never seen, they don't go find your conventions. They write the fastest thing that looks right from the few files they've opened. So you get the same three failures, over and over.
Duplicated utilities. Your repo already has a formatCurrency in src/lib/money.ts. The agent can't see it from the file it's editing, so it writes formatMoney in src/utils/helpers.js. Now two sources of truth drift apart, and the next person to touch the code inherits your mess.
Wrong entry point. Lots of repos have several ways in: main.py for local runs, worker.py for the queue, a FastAPI app object the server actually loads. An agent that guesses picks the one that looks most important, wires your change in there, and it never runs in production.
Ignored conventions. Every repo has unwritten rules. This team puts types in a separate folder, that one forbids default exports, this client's project uses absolute imports only. The agent doesn't know any of that unless something tells it, and its first commit is where you find out.
None of this is the agent being dumb. It's the agent being honest: it only knows what it has read. So the job is to make it read everything, once, before the editing starts.
The mapping pass: read-only, on purpose
Before any feature work, run one prompt whose only output is a report. The rules that matter: no edits, no file writes, no refactors "while we're in here." If the agent offers to fix something it spotted, note it and move on. You want a map, not a renovation.
Ask for six things:
- Entry points. What actually starts this app, and what's the difference between the candidates.
- How to run, build, and test. The exact commands, and whether tests even exist yet.
- A folder map. What lives where, in plain language, not a file dump.
- Data flow for one feature. Pick a feature you know end to end and have it trace the request from UI to database and back. If it can explain a path you already understand, you can trust its reading of the ones you don't.
- Conventions. Naming, file placement, error handling, state management, the patterns the existing code repeats.
- Risky areas. Generated code, vendored files, anything with a "don't touch" smell, and spots where the agent is genuinely unsure.
That last one is the quiet payoff. "I'm not sure whether this script is still used" is exactly the flag you want before you build on top of it.
Verify the map yourself
The map is only as good as its reading, so spot-check it before you lean on it. This takes ten minutes and it's the ten minutes that save your evening.
Run the commands it claims. If it says npm run dev and npm test are the way in, actually run them. A map that invents a working test suite is worse than no map, because you'll build on that belief.
Open two or three files it cites. If it says "user auth lives in src/auth/session.ts and touches the sessions table," open that file and confirm. One wrong citation means re-read that section; two means run the mapping pass again with sharper instructions.
Cross-check the data flow against what you know. You picked a feature you understand precisely so you could judge this. If its trace misses a step you know exists, the map has gaps you need to know about too.
Save it where every session starts from it
A map that lives in one chat log dies when the chat ends. The whole point is that you don't pay this cost again next session, or with a different agent, or when a teammate's agent picks up the repo.
Put the verified map in a file the agent reads every time it starts. AGENTS.md is an open format meant for exactly this kind of project guidance (build and test commands, conventions); if your harness reads a different file, use that, or keep a plain PROJECT_NOTES.md you paste at the top of a session. If you're still choosing a harness for this kind of read-first workflow, you can try the ZCode agent harness free (that's our invite link; the app itself is free, and you bring a model plan or API key, per its FAQ). Include the verified commands, the entry points, the conventions, the risky areas, and one line on what you changed since the last update. Keep it short. A map is a reference, not an essay, and it should fit on one screen.
Then maintain it like you'd maintain a README. Shipped a feature that adds a folder? One line in the map. Changed the entry point? Update it the same day. Two minutes now beats a stale map that lies to the next session, which is the edit-first failure wearing a disguise.
Then make the first change small and close to the map
Don't follow a perfect map with a sprawling feature. The first edit after a mapping pass is a test of the map, so pick something small, in an area the map just covered, with a clear definition of done. Fix a bug, add one endpoint, wire one button.
Watch how the agent uses the map. If it respects the conventions and lands the change in the right file, you're cleared for bigger work. If it drifts anyway, you've learned that cheap, and you know to tighten the map or the prompt before the next task. A mapping pass does read a lot of files, so it isn't free in tokens. If you'd rather pay one subscription than watch a per-request meter, there's a referral discount on GLM coding plans with our referral link (the discount applies to a first subscription, per the campaign rules). Small first change, correct second change, real feature third. That's the ramp.
The copy-paste mapping prompt
Here's the prompt I run before any work on an unfamiliar repo. Paste it into a fresh session, with no code changes allowed.
You are mapping this codebase. READ-ONLY PASS: do not edit,
create, or delete any file. Do not refactor anything you find.
If you spot bugs, list them under "Risky areas" instead of fixing.
Report the following, in this order:
1. ENTRY POINTS: every way this app starts, and which one is
the real one for local dev / production. Flag anything that
looks like a dead or duplicate entry point.
2. RUN / BUILD / TEST: the exact commands to install, run,
build, and test. Say plainly if there are no tests.
3. FOLDER MAP: what each top-level directory is for, in one
line each. No file-by-file listing.
4. DATA FLOW: trace ONE feature end to end, from UI or route
to database and back, naming the actual files involved.
Choose [FEATURE]. If you're unsure at any hop, say so.
5. CONVENTIONS: naming patterns, where new files are expected
to go, state management approach, error handling style,
import style. Base this on patterns that repeat in the
existing code, not best practices from elsewhere.
6. RISKY AREAS: generated or vendored code, anything fragile,
anything you are unsure about. Be honest about uncertainty.
Output plain markdown I can save as project notes. No code
changes of any kind.
Swap in your feature on the [FEATURE] line, run it, verify with the steps above, and paste the cleaned-up result into your project notes file. After that, every session starts smart instead of starting blind.
More notes from real builds are on our blog. Once the map is saved, Write a spec your coding agent can finish and verify is the natural next step.
If this saved you an hour on a repo you didn't write, a small tip on this post keeps these guides coming.






Latest comments
0