Code explanation
Claude in VS Code: Pair Programming
One of the most immediately useful things Claude can do inside VS Code is explain code — a function you inherited, a library you've never used, a codebase you've just joined. This chapter covers how to ask for explanations at the right level of detail, how to use Claude to onboard onto an unfamiliar project quickly, and which questions actually produce useful answers versus which ones waste your time.
Why Explanation in the Editor Is Different
Asking Claude to explain code in VS Code is fundamentally different from pasting code into a browser chat. In the editor, Claude already has the file open — and can reach out to read other files in the project when the explanation requires it. You don't have to copy anything; you don't have to provide imports or class definitions separately; Claude can follow a function call into the file that defines it.
This changes the questions you can ask. "What does this function do?" is fine. But so is "What calls this function, and does anything depend on the value it returns?" — a question that requires reading multiple files, which Claude can do automatically.
Levels of Explanation
The right explanation depends on what you already know and what you're trying to decide. Match the prompt to the level:
A paragraph-level summary. Use when you're orienting — skimming a codebase to understand its structure before reading any code in detail. Ask:
"Give me a one-paragraph summary of what this file does and why it exists."
Detailed explanation of logic, parameters, return values, and side effects. Use when you need to understand a specific piece of behaviour before modifying it. Ask:
"Explain what this function does step by step, including what each parameter controls."
For unfamiliar syntax, idioms, or patterns you don't recognise. Select the exact text and ask. Ask:
"What does this line do and why is it written this way?"
Prompt Patterns That Work Well
Before and After: Vague vs Specific
The specificity of your question directly determines the usefulness of the answer. These examples show the same request — one vague, one specific:
The pattern: replace "explain this" with a specific question about behaviour, edge cases, or intent. You'll get a targeted answer instead of a generic walkthrough.
Onboarding onto an Unfamiliar Codebase
When you're new to a project — joining a team, picking up someone else's code, or returning to your own code after six months — Claude can dramatically compress the time it takes to get oriented. Here's a sequence that works well:
main.py, index.ts, App.jsx) and ask: "What is the entry point of this application and what does it set up?" Claude explains the bootstrapping sequence.
Asking About Third-Party Code
Claude is also useful for explaining library and framework code — not just code you wrote. If you're using a library you don't fully understand:
- Paste a usage example from the library and ask what each argument does
- Ask: "What does this middleware actually do under the hood?" — Claude draws on its training knowledge of common libraries
- Ask: "Are there any gotchas with using this pattern in production?" — surfaces known pitfalls
- Ask: "What's the difference between [method A] and [method B] in this library?" — faster than reading docs
When Explanation Falls Short
| Situation | What happens | What to do instead |
|---|---|---|
| Highly domain-specific logic | Claude explains the code structure correctly but misses business intent (e.g. tax calculation rules, medical protocols) | Provide context: "This is a VAT calculation for EU digital goods — explain with that in mind." |
| Generated or minified code | Claude can explain it but the explanation is rarely useful — the code isn't meant to be read | Ask Claude to rewrite it as readable code first, then explain the rewrite |
| Macro-level architecture | Claude can describe files and directories but can't draw architectural diagrams without help | Ask Claude to produce a plain-text description of the architecture, then turn that into a diagram yourself |
| Runtime behaviour | Claude reads static code — it can't tell you what actually happened at runtime (memory usage, actual values, timing) | Use the debugger for runtime questions; use Claude for static analysis questions |