Skip to main content

Understanding your codebase

You do not need to read every file before using an agent. With 4RGE, the reliable order is the same as onboarding with a teammate — just faster:

Ask → map → verify → then edit.

This lesson covers how to explore a repo — new project, new service, or a corner you have never touched — without turning exploration into a reckless refactor. Understand first, change second.

What this page is for

You want to…This page helps you…
Run the explore loopAsk → map → verify → then edit
Onboard fasterAsk the agent the same questions you would ask a teammate
Search effectivelyDescribe what you need in plain language
Avoid bad first editsExplore read-only before big changes
Trust but verifyConfirm answers against real files and tests
Move to implementationWhen you are ready to build — Developing features
Part of 4RGED Learn · Coding agents

Start with Working with agents for session habits. This page is exploration only — no feature implementation yet. For @ mentions and attachments, see Prompting.

Who this page is for

You are…Focus on
New to the repoAsk like a teammate → Build a mental map
Familiar dev, new areaHow the agent finds code + Verify
Team leadShare "questions before refactors" as team norm
Before a large refactorExplore before you edit — then plan in a fresh run

The explore loop in four moves

MoveYouAgent
1. AskOne focused question (flow, symbol, or area)Searches and reads — no edits unless you ask
2. MapFollow up on gaps ("who calls this?", "what tests cover it?")Explains paths, layers, dependencies
3. VerifyOpen cited files; run a narrow test if behavior mattersShows paths or quotes when you ask for evidence
4. Then editNew run with scoped spec — Developing featuresImplements only after you are oriented

The agent is a fast tour guide, not an oracle. Your editor and tests stay the source of truth — Hallucination & limitations.

SituationStart with
Brand-new repoMonorepo layout + one critical flow (e.g. auth or checkout)
New area, rest familiarOne feature flow + "show existing pattern for X"
Error or stack tracePaste evidence + "trace from here to root cause path"
Before a big refactorCallers, tests, and risk — read-only until map is clear
Ready to buildStop exploring; open a new run with a mini-spec — Developing features

Explore before you edit

Agents can edit on the first message — that does not mean they should. Wide changes on code you have not oriented to are how teams get surprise diffs and broken conventions.

PhaseYour askAgent mode
Orient"Where is auth handled?" / "What calls this API?"Read and search — no edits
Map"Summarize the flow from login to session storage"Read, search, explain
Plan"Outline steps to add OAuth — match existing patterns"Plan only; you approve before code
ImplementScoped task with acceptance criteriaEdit and test — Developing features

Say "inspect only" or "no file changes yet" when you want exploration. That keeps the run focused and saves context for when you actually implement.

Ask like a teammate

Good exploration prompts sound like Slack messages to someone who knows the repo:

Instead of…Try…
"Explain the codebase""How does checkout work from cart to payment confirmation?"
"Find auth""Where do we validate JWTs on incoming API requests?"
"What's the architecture?""What are the main packages in this monorepo and what does each own?"
"Is this safe to change?""Who imports UserService and what tests cover it?"

Start narrow (one flow, one feature, one error). Go broad only after you have an entry point. If you know a symbol or file name, say it — that gives the agent a precise target. If you only know the feature name, describe behavior and let the agent search.

How the agent finds code

You describe what you need; the agent searches and reads — it does not magically hold the whole repo in memory — Context.

You describe…What usually happens
Behavior ("where we send password reset emails")Search by meaning and keywords, then read likely files
Exact name (processRefund, AuthMiddleware)Trace that symbol and its callers
File or folderRead and follow imports from there
Broad survey ("every place we validate user input")Many searches; may delegate a focused sub-task and return a summary

You do not need to run search commands yourself. For large surveys, a summary back to your main chat is intentional — it keeps the thread readable. If you need a specific file, ask to show the path or @ mention it — Prompting.

Learn patterns before you add new ones

Ask: "Show how we already do X" before "Add X." The agent is less likely to invent a duplicate pattern or break team conventions.

Anchor when you can

When you know where to start, attach it:

You have…Do this
Entry file@ mention it — e.g. @src/app/api/auth/route.ts
Error or stack tracePaste it or @ terminal output
Similar feature"Same approach as @components/SettingsForm.tsx"
Only a hunchDescribe the area; skip @ and let search work

Open the right folder — repo root vs one package in a monorepo — so search stays in the tree you care about. Wrong root is the #1 "agent can't find my code" issue.

Example explore prompts

Copy, edit, and paste. Say "inspect only — no file changes" when you want read-only exploration.

Monorepo orientation:

Inspect only — no file changes.
What are the main packages in this monorepo and what does each own?
Then walk one flow: login → session storage → protected API route.
Show file paths for each step.

Find where behavior lives:

Where do we validate JWTs on incoming API requests?
List the middleware or handler files and who imports them.
Inspect only.

Before changing something:

I'm about to change UserService.updateProfile.
Who calls it, what tests cover it, and what would break if the signature changed?
Show evidence (file paths). No edits yet.

Learn the existing pattern (before building):

Show how we already implement coupon/discount logic — files and flow.
I want to add discount codes at checkout using the same pattern.
Inspect only; summarize in bullet steps.

Verify a claim:

You said checkout calls PricingService.applyDiscount.
Open that file and quote the handler — confirm callers with search results.

When the map is clear, start a new run with implementation — Developing features. For @ mentions and attachments, see Prompting.

Build a mental map

Use the agent to compress orientation into something you can remember:

GoalExample prompt
Layering"Which folders are UI vs API vs shared libs?"
One flow"Walk through request → handler → database for POST /orders"
Dependencies"What external services does billing touch?"
Risk"What would break if I change this interface?"
Diagram"Draw a simple flowchart of our auth path" (Mermaid or bullet steps)

Take notes or save the agent's summary in your team's docs. The next person (or your next run) starts ahead — you do not need to re-explore from zero every time.

When the map feels clear enough to change one thing safely, switch to a new run with a scoped implementation ask — Working with agents.

Verify — don't memorize the chat

Exploration answers can sound authoritative and still be wrong — Hallucination & limitations.

CheckWhy
Open the cited fileConfirm the function or route actually exists
Run a narrow testProves behavior, not just narrative
Grep yourself for one symbolQuick sanity check on "all callers" claims
Ask for evidence"Show the grep result" or "read that file and quote the handler"

Treat exploration like a tour guide, not a source of truth. Your editor and tests are the truth.

What good exploration looks like

SignalMeaning
One flow per runYou asked about auth or billing — not everything at once
Paths you can openAnswers cite real files you verified in the editor
No surprise editsExploration stayed read-only until you chose to implement
Pattern before greenfieldYou saw how the repo already does similar work
Clean handoffNew run for implementation — exploration chat did not become a mega-diff
You could explain itYou can describe the flow to a teammate without re-reading the chat

Habits that work

  1. Questions before refactors — always.
  2. Read-only first on unfamiliar code — explicit "no edits."
  3. One flow per run — auth today, billing tomorrow.
  4. Name symbols when you know them — faster than vague feature words alone.
  5. Copy patterns — "match existing X" beats greenfield invention.
  6. New run to implement — exploration context is noisy for clean diffs.
  7. Verify key claims — especially before deleting or moving code.

Leads: encourage new hires to spend their first agent sessions exploring with these prompts before assigning production edits.

Where to go next

Your goalNext step
Build somethingDeveloping features
DebugFinding and fixing bugs
Session habitsWorking with agents
@ mentions & search helpersPrompting
What agents can read/doTools
Agent loop basicsAgents

Questions about understanding code?

QuestionAnswer
Will the agent read my entire repo?No — it searches and reads relevant parts per ask — Context.
Should I explore in the same run as edits?Separate runs work better — explore, then implement with a short recap.
Can it onboard me to a monorepo?Yes — ask about packages, owners, and one flow at a time; open the right root.
Why a short summary instead of all files?Keeps your chat usable; ask to open any path you need to see.
What if answers conflict with my knowledge?Verify in code — the model may confabulate paths or APIs.
Is exploration metered?Search and reads use tokens like any agent work — Tokens & pricing.
How long should I explore?Until you can name files and risks for your change — then switch to Developing features.
Agent edited when I wanted read-only?Say "inspect only" up front; revert and restate — Working with agents.
Same run for explore + build?Possible but messy — separate runs keep diffs and context cleaner.
Debugging vs exploring?Explore = understand structure; debug = repro + fix — Finding and fixing bugs.