How to Use AI to Understand Code You Did Not Write

· 6 min read

Ask the AI for a map of the code first, have it trace one real input step by step, then check each claim in a throwaway copy or the documentation before you change anything. A fluent explanation can be wrong, so treat it as a lead to test.

This guide covers reading only. For a bug, see debugging code with AI; to let an assistant edit files, see the safe workflow for AI coding assistants.

What should I ask an AI to explain first?

Ask for a map before any detail: where the code starts running, what data goes in and out, what it reads, writes and calls, and its side effects, such as files changed, network calls and database writes.

Say what the chat cannot know: the language, the tool versions and, if you know it, what the code is for. A chat with no access to your repository sees only what you paste or upload, so a function pasted alone hides its callers, configuration and real data. Say what you left out and ask what else it needs. For a large codebase, take one module at a time and keep your own short written map. Keeping a long AI conversation on track covers long threads.

How do I trace one input through unfamiliar code?

Ask for a plain-language trace of one concrete input (try an odd one too, such as an empty folder or a missing argument), with each variable's value after each step, and compare it with what the code does.

Here is a script we invented and have not given to an assistant. We ran it in throwaway folders on one Linux machine (GNU bash 5.2.21, GNU coreutils 9.4, POSIX locale); another shell or version may differ. It lowercases the .txt names in a folder and replaces spaces with underscores:

cd "$1" || exit 1; for f in *.txt; do new=$(echo "$f" | tr ' ' '_' | tr 'A-Z' 'a-z'); [ "$f" != "$new" ] && mv -n "$f" "$new"; done

Two of our runs:

  • A normal name. With f set to "Q3 Report.txt", the two tr steps leave new as q3_report.txt; the names differ, so mv renames the file.
  • A collision. With both "Q3 Report.txt" and q3_report.txt present, a plain rename would overwrite one. On our machine, mv -n refused, printed "mv: not replacing 'q3_report.txt'" and left both alone.

What does the code assume, and what could the AI not see?

Ask: "What does this code assume about its input, working folder and environment?" and "Which statements depend on code I have not shown you?" Treat the answers as places to check first, not a guarantee about the rest.

A one-line summary ("lowercases .txt names") omits all of this:

  • What it skips. Notes.TXT, a hidden file named .Hidden Draft.txt and a file in a subfolder were left alone. The POSIX shell page (2024 edition) says an asterisk does not match a leading period.
  • An empty folder. The loop ran once with f set to the literal text *.txt and changed nothing; the POSIX page says a pattern matching no file is left unchanged.
  • No argument. It renamed a file in the folder it was started from, because cd with an empty string succeeded on the Linux shells we ran (Bash, dash). The POSIX cd page says an empty string shall make cd write a diagnostic message and exit with non-zero status; other shells may differ.
  • The exit status. It exited 1 in our empty-folder, skipped-files and collision runs and 0 in a run where the renamed file came last, with nothing lost. The POSIX page gives a for loop the status of its last command, and which file comes last depends on the locale's sort order.

How do I check what the AI told me about the code?

OWASP's 2026 entry on misinformation says humans and systems often treat fluent, confident or well-structured outputs as authoritative, lists incorrect or fabricated code and dependencies among its examples, and advises verifying claims before acting. Ways to check a claim about behavior:

  • Run a throwaway copy. Read the script first for network calls and writes outside the folder, which a copy does not contain. Then run it in a copy and list the folder afterward, never on real files on an assistant's say-so.
  • Make the shell show its steps. Run the copy with bash -x, which the POSIX page describes as tracing each command after expansion and before it runs. bash -n reads the script without running it, so it checks syntax only.
  • Read the documentation. Python's page on built-in types, as read on 3 December 2026, says str.lstrip's argument is a set of characters, not a prefix: 'Arthur: three!'.lstrip('Arthur: ') gives 'ee!' where removeprefix gives 'three!'. A description like "removes the prefix" is worth checking. Its version notes, such as "Added in version 3.9." for removeprefix, say which version has a function, so read the page for the version you run.
  • Record what it does today. Before you change anything, write a test that saves the current output for a few inputs. Wikipedia calls it a characterization test, which protects legacy code against unintended changes.
  • Read the history. Git's blame shows the revision that last changed each line, and git log has -S for commits that change how often a string appears. Without repository access a chat cannot see history unless you paste or upload it, and commit messages are only as informative as people wrote them.

Could the code hold secrets or other people's data?

It can. OWASP's secrets cheat sheet says many organizations hardcode secrets in plaintext in source code. Search the file for keys, tokens, passwords, connection strings and customer data before it leaves your machine, and replace each with a made-up value of the same shape. A secret that already went into a chat counts as exposed: revoke or rotate it (our inference; the sheet advises revoking on any suspicion of compromise).

Rules on proprietary code and customer data differ by workplace and place; this is not legal advice, so check yours. The privacy checklist lists what to ask a tool. Code from outside your team can carry text meant to steer an AI that reads it (our inference); see prompt injection explained.

Which questions about code need the code's owner?

Ask the code's owner or a colleague who knows the system when:

  • The stakes are high. A wrong guess could cost money, lock people out or lose data that cannot be restored.
  • The answers disagree. The explanation and your own run differ and you cannot say why, or two explanations conflict.
  • You cannot test it. You cannot reproduce the behavior in a copy, or the system is live and has no tests.
  • A rule looks arbitrary. A number or condition is unexplained; history may hold a clue, but its authors can say why.

When to keep a human in the loop covers the wider question.

Where NAMELESS stands

NAMELESS is our own AI model, built on its own architecture, and it is still in training. It is not available and has no launch date, so nothing above can be tried on it. Our goals are unlimited context with no rereading of the conversation, extremely fast answers, stronger logic and reasoning, and a cost of pennies compared with today's leading assistants. To hear how it develops, join the waitlist.

Keep reading

All posts