Explore a codebase with an agent
Before you change an unfamiliar project, you need to understand how it is structured, where a behavior is implemented, and what trade-offs the current design makes. An agent can help you map the architecture, trace a feature across files, locate relevant tests, and weigh alternatives before you write code. Treat its explanation as a starting point to check against the source, not as an authoritative description of the project.
In this guide, you investigate an existing repository without editing files. You move from a high-level architecture overview to a targeted code trace, verify claims directly in the editor, and evaluate pros, cons, and alternatives for a future change.
Prerequisites
Project: Your repository. Harness: Copilot. Interface: Chat view.
- Set up GitHub Copilot.
- Open the repository you want to explore in VS Code.
- Have a feature or behavior in mind that you want to understand or extend, such as search filtering, request authorization, or data persistence.
Review the security guidance for working with agents before you trust or run unfamiliar code. You don't need to install dependencies or run the application to start reading its source.
1. Map the overall architecture
Start with a broad view of the project so you know where application code, shared modules, configuration, and tests live.
-
Open the Chat view and start a new chat.
-
Keep Copilot selected as the Session Target, Agent as the role, and Manual permissions enabled.
TipIf you want read-only tools enforced so the session cannot edit files or run state-changing commands, switch the role to Ask. In the Agent role, telling the agent not to edit or run code in a prompt is an instruction, not a permission boundary. Review permissions and tool activity as you work.
-
Optionally, select Maximize Secondary Side Bar in the Chat view title bar to give long explanations and diagrams more room.
-
Ask for an architecture overview and a diagram:
Give me a high-level overview of this project's architecture. Explain the main directories, entry points, and how data flows through the application, and include an architecture diagram. Do not edit files or run commands.
Review the overview to identify the area of the codebase you want to inspect next. If the repository contains multiple applications or packages, name the one you care about in your follow-up prompts.
2. Trace how a specific feature is implemented
Next, narrow your focus to one concrete behavior. Include an entry point if you know one, such as a UI control, route, command, or folder.
For example, adapt this prompt to a feature in your repository:
Explain how the destination search on the blog page filters posts.
Trace the flow from the UI input through any helper functions to the
rendered results, cite the relevant files and symbols, and list any
tests that cover this behavior. Do not edit files or run commands.
As you read the response, verify its claims against the actual code:
-
If you maximized the Chat view, select Restore Secondary Side Bar so you can view the conversation and editor side by side.
-
Select the file and symbol links in the chat response to jump directly to the referenced code and tests in the editor.
-
Check that:
- The entry point is active code, not an unused example, generated copy, or test fixture.
- Callers pass the expected values, return values reach the UI or response, and error paths match what the agent described.
- Cited tests actually assert the behavior you care about, rather than only matching by name.
If the explanation skips a connection, ask a focused follow-up to locate the missing call site. Add key files as chat context if you want subsequent turns focused on a specific area.
If you need runtime confirmation for tests, review the project's setup instructions and test command first. Only run commands in a repository you trust, either in the terminal yourself or through the Agent role with Manual permissions. Don't treat an unexecuted test as a passing check.
3. Evaluate pros, cons, and alternatives
Once you verify how the current implementation works, use the agent to surface design trade-offs, edge cases, and options before you commit to a change:
Based on the implementation and tests we inspected, what are the pros,
cons, and limitations of the current approach? Suggest practical
alternatives if we need to extend this feature, and note any missing
test coverage or risks to watch out for. Do not edit files.
Compare the suggested alternatives against your constraints, such as performance, maintainability, backward compatibility, and existing project patterns. Ask follow-up questions to probe assumptions or clarify which files an alternative would affect.
4. Move from exploration to your next step
When you can locate the implementation, explain its key paths and edge cases, and weigh the trade-offs, you are ready to act on what you learned:
- To design and implement a change, stay in the session (or start a fresh chat with the key files attached) and ask for a plan before editing.
- If you want to save architecture notes for your team, verify every file reference and claim against the source first rather than committing an unchecked AI summary.