Start reading a codebase with one question
Before a refactoring, select one behavior affected by the change rather than reading every directory. Our question is: how does EnvDoctor's audit command detect an environment-variable reference, and how does that finding become a CLI exit code? This gives us one map covering the entry point, data transformations and externally observable result.
The example uses commit 25e43e45683180775d3a8e891bb1bc157ae0222a of my open-source EnvDoctor repository. The source searches and behavior tests below were executed on 7 October 2026 with Python 3.14.7 and ripgrep 15.2.0. This revision's CLI reports 0.2.0 and requires Python 3.12 or newer. Results describe small demonstration files, not production performance or full repository test coverage.
Pinning the source revision keeps today's observations separate from tomorrow's main branch. The commands below create a new demonstration checkout; do not run the checkout command in an existing working repository. Python, Git and rg must already be installed.
git clone https://github.com/umutgungorr/envdoctor.git envdoctor-reading
cd envdoctor-reading
git checkout --detach 25e43e45683180775d3a8e891bb1bc157ae0222a
python --version
rg --version
rg --files srcFind the entry point and callers with rg
First read the console-script entry in pyproject.toml and src/envdoctor/__main__.py. The installed command points to envdoctor.main:main, and python -m envdoctor reaches the same main function. A textual match does not prove that every runtime caller has been found. Here, we confirm the search results by reading the source.
The first search returned the import at __main__.py:3, dependencies at main.py:12 and :14, the handler at :225, its audit_codebase call at :236 and audit dispatch at :323. The second locates the single-file scanner at auditor.py:68, line-based regex matching at :86, directory auditing at :101 and scanner calls at :110/:116. These line numbers apply only to the pinned commit.
-F treats the search text literally instead of as a regex; -e searches multiple patterns in one pass; -n prints line numbers. We restrict the scope to src/envdoctor. rg skips some hidden and ignored files by default, so no match is not proof that a behavior is absent from the entire project.
rg -n -F -e 'from envdoctor.main import main' -e 'from .auditor import audit_codebase' -e 'from .parser import parse_env_file' -e 'def handle_audit' -e 'res = audit_codebase' -e 'return handle_audit' src/envdoctor
rg -n -F -e 'def scan_file_for_env_keys' -e 'pat.finditer(line)' -e 'def audit_codebase' -e 'scan_file_for_env_keys(' -e 'missing_from_env =' src/envdoctor/auditor.pyTurn imports into a behavior and data-flow map
main parses CLI options and dispatches audit to handle_audit. The handler reads the selected .env file with parse_env_file and passes only its key set to audit_codebase. That function discovers target files; scan_file_for_env_keys applies extension and line filters before the regexes in PATTERNS. This revision does not use an AST parser.
The arrows describe confirmed calls and data transformations, not just import dependencies. A CodeReference carries the key, file path, line number and source snippet. audit_codebase builds unique_referenced_keys, subtracts known keys to obtain missing_from_env, and uses the reverse difference for stale_in_env. The handler formats the JSON report and returns 1 when missing_from_env is nonempty, otherwise 0.
A regex change can affect more than the scanner: references, missing/stale key sets, JSON consumers and CI exit status can all change. Read the side-effect boundary as well: the scanner reads files, the handler reads the selected .env, and _output writes to stdout or a report file when --output is supplied. Our experiment does not use --output or inspect a real .env file.
CLI / python -m envdoctor
-> main(argv)
-> handle_audit(args)
-> parse_env_file(selected .env) -> known_keys
-> audit_codebase(targets, known_keys)
-> scan_file_for_env_keys(file)
-> PATTERNS / pat.finditer(line)
-> list[CodeReference]
-> referenced, missing, stale sets
-> JSON report / _output
-> exit 1 if missing else 0Check the behavior you read with small tests
A map can remain incomplete until tested. The pinned tests/test_auditor.py checks direct Python/JavaScript references and missing/stale keys; tests/test_cli.py checks successful audits and missing-key exits. I found no dynamic-key, alias, multiline-lookup or string-literal cases in these two files. This is not a claim that every other test in the repository lacks boundary coverage.
Each form below was tested as a separate app.py input. We are observing how the scanner interprets text, not executing the application input. API_TOKEN and FAKE_KEY are dummy names. Dynamic and aliased lookups can be valid Python; the scanner failing to recognize them does not mean they are unused.
# direct
import os
value = os.getenv("API_TOKEN")
# dynamic
key = "API_TOKEN"
value = os.getenv(key)
# alias
from os import getenv
value = getenv("API_TOKEN")
# multiline
value = os.getenv(
"API_TOKEN"
)
# string-literal: text, not an environment lookup
text = 'os.getenv("FAKE_KEY")'A reproducible test and its executed output
Save reading-code-contract.py from the Sources section alongside the envdoctor-reading directory. From their parent directory, run python reading-code-contract.py ./envdoctor-reading. No package installation is required: the script imports directly from that checkout. Python must be at least 3.12; the run was verified on 3.14.7. The script first checks SHA-256 values of four source files with LF-normalized line endings and stops on a different revision.
The test creates a temporary .env containing only API_TOKEN=demo_not_a_secret. It checks each input through the single-file scanner, directory audit and actual main function's JSON/exit status. Input files are not executed as applications; the checkout is not modified, no network connection is made, and bytecode writing is disabled. Temporary files are cleaned up at completion. The output below comes from the executed test.
direct is recognized. dynamic, alias and multiline are missed; the CLI can still return 0 because no missing key was detected. string-literal is counted as a FAKE_KEY reference despite not being a getenv call, producing exit 1. These characterize this revision's limits: matching a regex in a line does not prove that the expression is executable code.
The test also confirmed that node_modules is skipped during directory traversal, but a file inside it is scanned when explicitly supplied as a target. The same ignore rule does not govern both entry paths identically. Your impact map therefore needs the target type, not only the function name.
{"case": "direct", "detected": ["API_TOKEN"], "missing": [], "exit": 0}
{"case": "dynamic", "detected": [], "missing": [], "exit": 0}
{"case": "alias", "detected": [], "missing": [], "exit": 0}
{"case": "multiline", "detected": [], "missing": [], "exit": 0}
{"case": "string-literal", "detected": ["FAKE_KEY"], "missing": ["FAKE_KEY"], "exit": 1}
PASS: 5 scanner/report/CLI cases and directory-vs-explicit-file boundaryRecord the map's limits and change scope
This is a characterization test documenting current behavior, not declaring every result correct product behavior. Fixing the string-literal false positive or supporting multiline access requires a separate source change and revised expectations. EnvDoctor's source was not changed for this guide. Capturing a known limitation in a test does not make it a permanent product requirement.
Text search is a starting point, not a complete call graph. Dynamic imports, aliases, plugin registration, environment-selected branches and out-of-scope consumers need separate review. These five inputs do not verify every lookup in other languages, large-repository performance or every CLI option. For a broader change, run the repository's own tests and check external JSON consumers' contracts.
A short note to complete before the first change
For your own repository, record: the behavior to change; pinned revision; entry point; direct callers; data transformations; file/network/write side effects; observable output; failing counterexample; and consumers not covered. Fill each item with evidence relevant to your question, not the entire directory tree.
In the EnvDoctor example, a proposed change to scan_file_for_env_keys cannot be accepted on regex matches alone. Evaluate CodeReference, missing/stale sets, JSON output and exit code together. Then make a small change and rerun the same checks. The debugging guide covers experiment design, while the EnvDoctor usage guide explains the user-facing differences between check, sync and audit.
Source: EnvDoctor: pinned source revision
Source: Entry point and audit handler
Source: File scanner and data transformations
Source: Reproducible characterization test: reading-code-contract.py
Source: ripgrep: official search and filtering guide
Source: Related guide: debugging
Source: Related guide: EnvDoctor code-usage audit
Source: EnvDoctor project case study
