Understand a code base before you change it with Claude

The struggle: You inherited a code base nobody documented and you are afraid to change a line in case something breaks.

What you end up with: A written map of the modules, data flow, risky spots and a first safe change you can check.

Run Claude Code in the repo, ask broad questions first, then trace one real flow end to end. You get a map in your own words and a short list of what to test before touching anything.

Tools: Claude. Level: Pro. Time: 1 to 2 hours.

Use it if

  • You joined a project or took over old code
  • There are no docs or the docs are out of date
  • You can run the code and its tests on your machine

Skip it if

  • You cannot give an AI tool access to this code
  • You need a formal security audit

What you need first

  • Claude Pro or higher (Claude Code is included from Pro)
  • Claude Code installed or the Code tab in Claude Desktop, and the repo on your machine

The method

  1. Start it in the project (Claude: Claude Code)

    Open a terminal in the project root and type claude, or open the Code tab in Claude Desktop and choose the folder. Log in when asked. Claude Code reads the folder as it works.

    You get: Claude Code running inside the repo.

    Tip: Start in plan mode (claude --permission-mode plan, or Shift+Tab until the status bar shows plan mode) so it proposes and makes no edits. Use a clean git branch too.

  2. Get the overview (Claude: Claude Code)

    Start with the broad question, then narrow. Ask one follow-up per component you do not understand. Write the answers into a notes file only if you read them first.

    Prompt to copy:

    Give me an overview of this code base. List the main modules, what each one is for, the key data models, the entry points, and how it is built and run. Mark anything you are unsure about as Unsure. Do not change any files.

    You get: A first map of structure and patterns.

    Tip: Ask for a glossary of project-specific terms. Old code is full of them.

  3. Trace one real flow (Claude: Claude Code)

    Pick the flow you will touch, such as login or checkout, and ask Claude to trace it from the front end to the database. Open each file it names and read the lines it cites.

    Prompt to copy:

    Trace the [flow name] flow from the first user action to the database and back. For each step give the file and function. Then list side effects such as emails, queues and cache writes, and anything that looks fragile or unused. Do not edit files.

    You get: The path of one feature through the code, with file names.

    Tip: Use the domain words from the project. Vague questions get vague traces.

  4. Find what protects you (Claude: Claude Code)

    Ask which parts have tests and which do not. Run the existing tests yourself in the terminal and note what fails before you change anything.

    Prompt to copy:

    Find the functions around [module] that are not covered by tests. List the five riskiest ones, why each is risky, and what behaviour a test should lock in before anyone changes it. Do not write any code yet.

    You get: A baseline of passing and failing tests.

    Tip: A test that already fails is not your bug. Record it now.

  5. Write the map for the next person (Claude: Chat)

    Paste the answers you trust into a chat and ask for a one-page README section. Add it to the repo yourself after you read it.

    Prompt to copy:

    Turn these notes into a README section called How this code works: structure, main flows, how to run and test, risky areas, and Not yet understood. Plain English, under 400 words. Use only what is in my notes: [paste notes].

    You get: A short document so the next person does not start from zero.

    Tip: Ask Claude to put the unknowns in a section called Not yet understood.

Where this goes wrong

  • Claude Code can edit files and run commands. Plan mode makes no edits, and git shows anything that changes. Review every change before you commit.
  • A confident explanation can still be wrong. Open the files it cites before you rely on a claim.
  • Old code often has behaviour that only shows at run time. Run it and test it before you refactor.
  • Keep .env files, API keys and production credentials out of its reach, and do not paste them into prompts.

Sources

More like this

Updated . Written with AI help and checked by an independent review step, as described in our editorial standards.