Explaining Code You Didn't Write
Use /explain to onboard fast — layer questions, verify answers.
What You Will Learn
- Use /explain effectively on inherited code.
- Layer follow-up questions.
- Verify Copilot's explanations against the code.
- Build an onboarding workflow.
- Recognize when /explain hallucinates.
Why This Matters
Onboarding to inherited code is where most developer hours are lost. /explain compresses hours of reading into minutes — but only if you verify and layer questions well.
Concept Explained
/explain is a slash command that produces structured explanations of selected code. It outputs purpose, parameters, returns, side effects, edge cases. Layered follow-ups drill into specific parts.
How It Works
Highlight code, type /explain in Chat. Copilot reads the selection (and surrounding file context) and produces a structured explanation. Follow-ups can drill into specific lines, dependencies, or behaviors.
Step-by-Step Tutorial
1. Highlight and explain
Select the function or block. Type /explain in Chat. Read the structured output.2. Drill into specifics
Follow up: 'what does the second loop do?' or 'why is null checked twice?'3. Trace dependencies
Ask: 'where is X called from?' Use @workspace for repo-wide tracing.4. Verify
Read the actual code alongside the explanation. Catch any hallucinations.5. Document
Save the verified explanation in a comment or docstring.Real-World Example
A new hire inherited a 1500-line legacy module. They ran /explain on each function, layered questions for unclear parts, and verified each explanation. Built a complete mental model of the module in 90 minutes — work that would have taken a full day.
Example Prompts / Commands / Code
Turn 1: /explain (on a function)
Turn 2: What does the regex on line 12 match?
Turn 3: Where is this function called from? (@workspace)
Turn 4: What edge cases are not handled?
Common Mistakes
- Trusting /explain without reading the code.
- Asking vague follow-ups — be specific ('line 12', 'the second loop').
- Not using @workspace for cross-file questions.
- Forgetting to save verified explanations for future readers.
Best Practices
- Always verify /explain output against the actual code.
- Layer follow-ups to drill into specifics.
- Use @workspace for cross-file questions.
- Save verified explanations as comments or docs.
Troubleshooting
| Problem | How to Fix |
|---|---|
| Explanation is wrong | Verify against code. Re-run with more context (attach the file explicitly). |
| Vague explanation | Ask a specific follow-up: 'what does line 12 do exactly?' |
Practical Exercise
Your Turn
Pick a function you didn't write (in your codebase or open source). Run /explain, ask 3 layered follow-ups, verify against the code. Save the result as a docstring.
Key Takeaways
- /explain produces structured explanations.
- Layer follow-ups for specifics.
- Use @workspace for cross-file.
- Always verify against the code.
- Save verified explanations for future readers.
Frequently Asked Questions
Does /explain work on any language?
Can I run /explain on a whole file?
Further Reading
Official References
SEO Metadata
SEO title: Explaining Code You Didn't Write
Meta description: Use /explain to onboard fast — layer questions, verify answers.
Primary keyword: explaining code you didn't write
Secondary keywords: explaining code you didn't write
Search intent: Informational
URL slug: /copilot-explaining-inherited-code-onboarding
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Beginner, Explain, Onboarding, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Explaining Code You Didn't Write
Comments
Comments
Post a Comment