Asking a Coding Agent to Explain Code You Did Not Write

JS
Jai Singh
02 Dec, 2026 4 min read 6 views

One of the safest and most useful things you can do with a coding agent is ask it to explain code. It changes nothing, it saves hours of searching, and it helps you build a mental model of a project before you change it. The key is to ask concrete questions, make the agent cite the files it used, and check important claims yourself.

Start broad, then narrow

Begin with a map of the project, then follow one thread at a time.

Give me an overview of this repository: what it does, the main modules, how
data flows through it, and where the entry points are. Cite file paths.

Then pick a specific flow:

Trace what happens when a user submits the checkout form, from the route
handler to the database write. List each function in order with its file
and line, and note where errors are handled.

Asking for file paths and function names turns a vague essay into something you can open and verify.

Good questions to ask

  • "Where is X decided?" for example, where is the shipping cost calculated?
  • "What calls this function, and what would break if I changed its return type?"
  • "What does this regular expression match? Give three examples that match and three that do not."
  • "Why might this code use a lock here? Look at how it is called."
  • "Which tests cover this module, and what do they not cover?"
  • "What are the external services this code talks to?"

Ask for output you can use

A diagram in text, a table of modules or a sequence of steps is easier to check than prose. For example:

Produce a table of the files in src/billing with one line each describing
its responsibility, and list which other modules each one imports.

Another useful trick is asking the agent to write an explanation as a comment or document you will keep, such as an ARCHITECTURE.md. Review it, correct it and commit it. Future sessions, and future teammates, benefit.

Verify what matters

Explanations can be wrong. The agent may confuse two similarly named functions, miss code that is wired up through configuration, or describe how the code should work from a comment that is out of date. Habits that protect you:

  1. Open the cited files and read the key lines yourself.
  2. Run the code with a debugger or log line to see the real path for important flows.
  3. Ask the agent how sure it is, and what it could not find.
  4. Cross-check with tests: a test usually shows intended behaviour.
# Quick checks you can run yourself to confirm a claim
grep -rn "calculateShipping" src
git log --oneline -5 -- src/billing/shipping.js   # recent history of that file

The git history is another source of explanation. Ask the agent to summarise the recent commits touching a file, or run git blame on a puzzling line to see which change introduced it and read that commit message.

Use explanation before modification

Before asking for a change in unfamiliar code, run an explanation round first: "Explain how invoices are numbered. I want to add a prefix per region." Then use the answer to write a better prompt. You will name the right files and avoid the changes that conflict with the existing design.

Explanations are also a good way to find gaps in the documentation. If the agent struggles to say where something happens, a new teammate probably will too. Note those places and improve the README or add a short comment. When the agent gives you a surprising answer, treat it as a prompt to investigate rather than a fact: open the file, read the lines, and decide whether the explanation or the code needs correcting.

Learning, not only reading

If your goal is to learn, ask the agent to quiz you or to explain at a level you choose: "Explain this like I know Python but not Go." Ask why a design choice was made, and what alternatives exist. Then try predicting the behaviour of a small function before running it. Active use beats passive reading.

Cautions

  • Be careful when you share proprietary code with an external service. Follow your organisation's rules.
  • Do not treat an explanation of security-sensitive code as an audit.
  • Keep questions read-only. If the tool is in a mode that allows edits, say "do not change any files".
Was this article helpful?

Comments

No comments yet. Have a question or a tip? Be the first to share it.

Leave a comment

Comments are reviewed before they appear.