Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Workflow recipe

Understand an unfamiliar codebase with an AI agent

Get a read-only map where every claim cites a file and line, check the citations, trace one path and test what you learned.

By Checked Beginner1 h 5 min6 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

To understand a codebase with AI, start the agent in a read-only mode on a fixed commit and ask for a map in which every claim cites a file and line. Open the citations to check them, have the agent trace one real code path to the test that covers it, then predict the effect of a small change and run the tests to see whether you were right. Keep only what you checked in your notes.

An agent can read a repository far faster than you, and its summary will sound right either way. The danger is the confident sentence about code it never opened, or a claim that something does not exist (“no dead code”, “this case is untested”) that nobody checked. When we ran this recipe on a small Python library, every line citation we opened was accurate, but one claim of absence was false. The citations are what make the map checkable, and the last step tests your understanding rather than the agent’s.

TerminalAbout 5 min

1. Pin the commit and start the agent read-only

Fix the version you are reading and start the agent in plan mode, so nothing can change while you explore and every line number in the map stays valid.

git switch --detach 2.2.0      # a tag or commit, so line numbers stay put
git rev-parse --short HEAD     # write this down at the top of your notes
claude --permission-mode plan

In plan mode Claude Code reads files and proposes, but makes no edits until you approve. In our runs it still ran harmless read-only commands, such as collecting the test list. In a session that is already open, press Shift+Tab until the status bar shows “plan mode on”, and check it does before you paste anything.

Claude CodeAbout 10 min

2. Ask for a map with a citation on every claim

The citations are the point of this prompt. Without them you cannot tell what the agent read from what it guessed.

Codebase map with citations · Claude Code
I am new to this repository and need a map of it that I can check. Read the code; do not edit any file or run anything that changes state. Write a map with these sections: 1. What the project does, in two sentences. 2. Entry points: where execution or the public API starts. 3. The main modules or folders, one line each on what they own. 4. How data flows through one typical use, step by step. 5. Where configuration, tests and build or release scripts live, and the commands to run the tests. 6. Anything surprising: unusual patterns, dead code, deprecated paths. Rules: - Every claim must end with a citation in the form path/to/file:line or path/to/file:start-end. Use only files you have opened in this session. - If you are inferring rather than reading, mark the claim INFERRED and say what you would need to open to confirm it. - Do not describe files you have not opened. If something is out of reach, list it under "Not read". - Keep the whole map under 600 words.

On itsdangerous the agent took about a minute and returned seven modules, a seven-step data flow for a signed token, the tox and pytest commands, and a “Not read” list (the docs folder, the pinned requirements files). It overran the word limit by about a hundred words, which is harmless. Save the answer as MAP.md outside the repository.

EditorAbout 15 min

3. Open the citations and mark each claim

Check at least eight citations, chosen from different sections, and mark each one in MAP.md as checked, wrong or loose. Give priority to claims you will rely on, and to every claim of absence.

What counts as wrong: the cited lines say something else, or the file does not exist. What counts as loose: the right code, a few lines away from the cited range. We opened eight citations and found seven exact and one loose (a claim about the default hash cited the key-derivation function a few lines below the real default).

Claims that something is missing (“no CLI”, “no dead code”, “this case is untested”) have nothing to cite, so check them with a search instead:

git grep -n "future" tests/

Anything marked INFERRED stays out of your notes until you have opened what the agent said would confirm it.

Claude CodeAbout 10 min

4. Trace one real path to the test that covers it

A map tells you where things are; a trace tells you how they behave. Pick a call your team uses, or the one that worries you, and ask for the chain with the test that exercises it.

Trace one call · Claude Code
Trace what happens, step by step, when this runs: [CALL TO TRACE, E.G. A PUBLIC FUNCTION WITH ITS ARGUMENTS AND THE SITUATION]. Rules: - Follow the real call chain function by function. Give each step as path/to/file:line and one sentence. - Do not edit files. Do not guess at code you have not opened; mark any guess INFERRED. - End with: the exception the caller sees, the existing test that covers this path (file and test name), and the exact command to run only that test.

Replace the bracketed part. We traced URLSafeTimedSerializer("secret").loads(token, max_age=60) with an expired token: 27 steps across four files, ending in SignatureExpired. Then run the test it names yourself:

python -m pytest "tests/test_itsdangerous/test_url_safe.py::TestURLSafeTimedSerializer::test_max_age" -v

Both cases passed. The same answer also claimed a future timestamp was an “untested edge case”. A search of tests/ found test_future_age, so that claim went into the notes as wrong.

TerminalAbout 15 min

5. Predict the effect of a change, then run the tests

This step tests what you now believe. Choose a one-line change in code the map says matters, ask the agent to predict which tests fail without running them, then make the change on a scratch branch and compare.

Predict before you run · Claude Code
I am going to make this change on a scratch branch: [ONE-LINE CHANGE, WITH FILE AND THE OLD AND NEW TEXT]. Before I run anything, predict the effect. Rules: - Do not edit files and do not run the tests. Read the code and the tests only. - List each test you expect to fail, as file::test name, with one sentence on why and a path:line citation. - Then list the tests you expect to keep passing that a careless reader might think would fail, and why. - If you are not sure, say so and give your confidence as high, medium or low.

Write your own prediction down before you read the agent’s. Then make the change yourself, run the suite and throw the branch away:

git switch -c scratch/predict
# make the one-line change in your editor
python -m pytest -q
git restore . && git switch --detach -

We changed if age > max_age: to if age >= max_age: in the timed signer. The agent predicted that no test would fail, because no test hits an age exactly equal to max_age, and the suite agreed: 297 passed. That is a finding in its own right: the boundary is untested, and it goes on your list of open questions.

EditorAbout 10 min

6. Write the notes from what you checked

Turn MAP.md into your own notes: keep the checked claims with their citations, drop the wrong ones, and record the commit you read. Add the traced path, the test command and the prediction result.

End with open questions for the team, such as “is the max_age boundary deliberately untested?” or “is the none key derivation meant to be public?”. Those questions make a better first conversation with the code’s owners than “can you explain the architecture?”.

If the notes would help the next person, propose the stable parts (the test commands, the surprising patterns) for the project’s AGENTS.md, which the AGENTS.md maintainer skill can help keep short.

Check it worked

Verification checklist

0 of 7 done

When it goes wrong

If citations point at the wrong lines, the code probably moved under the agent: you switched branches or pulled during the session. Go back to the pinned commit, start a new session and ask again. If the lines are only a few out, the claim is usually right and the citation loose; check the nearby code rather than trusting or discarding it.

If the agent claims something does not exist or is untested, treat that as the least reliable kind of statement in the map. We saw one false “untested” claim in four answers. A one-line git grep settles it.

If the map is generic (“follows clean architecture”, “well-structured modules”), the agent summarised names rather than reading code. Repeat the rule that every claim needs a file and line, and ask for the data-flow section first, which forces it to open files.

If the agent says it saved something, check where: in our runs Claude Code wrote each plan-mode answer to a plan file under ~/.claude/plans/, not into the repository. Your working tree should still be clean.

Variations

With Codex, Cursor or another coding agent, use its read-only or ask mode and paste the same prompts; the citation rule and the checks in steps 3 and 5 do not depend on the agent.

For a large monorepo, run step 2 per top-level folder you care about rather than on the whole repository, and keep one map per folder. Ask for the data flow of the one feature you are about to change, not the whole system.

For a team, run steps 2 to 4 once, check the result, and keep it in the repository as an onboarding page with the commit at the top. Re-run the citation check whenever someone relies on it after a major refactor. To turn the map into maintained docs, follow generate documentation from code with AI.

New to the agent? Start with the Claude Code tutorial and the glossary entry for plan mode. Once you understand the code, debug a bug with an AI agent with the same evidence-first habits, or turn what you learned into an AGENTS.md example and template. The AI-assisted software engineering path puts these recipes in order, and there are more AI workflow examples in the hub.

Outcome and tools

Outcome
A one-page map of the codebase in which every claim cites a file you opened, one traced code path with its test, and a list of open questions.
For
Developers
Variants for
Claude Code

Check your understanding

Understand an unfamiliar codebase with AI quiz

Pinning a commit, plan mode, citations on every claim, checking claims of absence, tracing a path and predicting a change before running tests.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. Why does the recipe start by switching to a fixed tag or commit?
  • Your first session with Claude Code

    Install it, run it in a real repository, approve its first changes, commit a reviewed edit and learn the commands you will use daily.

    TutorialBeginner30 min

  • Write a useful AGENTS.md: example, template and test

    An AGENTS.md example and template with build and test commands, conventions and traps, plus a before-and-after task that shows whether the file actually helps.

    WorkflowBeginner30 min6 steps

  • Debug a bug with an AI agent: reproduce it, then fix it

    Write the bug report, have the agent reproduce it as a failing test, find the root cause, apply a small fix and prove it.

    WorkflowIntermediate55 min6 steps

  • Plan mode

    An agent mode in which it reads and researches the code and proposes a plan, without editing any files until you approve the plan.

    Glossary

  • AI-assisted software engineering

    Learn AI-assisted software engineering on real repositories: set up coding agents, give them good instructions, review their diffs and run several in parallel.

    Learning pathIntermediate11 h14 steps

Back to top