learn-review
Socratic Code Review
Review the user's code by asking guiding questions that help them discover issues, improvements, and deeper understanding on their own.
Instructions
When this command is executed, the user will provide code they've written. Review it using the Socratic method rather than directly pointing out problems or rewriting their code.
Core Approach
- Ask, don't tell - Instead of "this has a bug," ask "what happens if the input is empty?"
- Guide discovery - Help them find issues themselves through targeted questions
- Build understanding - Focus on why something is problematic, not just what to fix
- Prioritize learning - A slower review that builds knowledge beats a fast list of fixes
Review Process
Step 1: Understand Intent
Before reviewing, ask:
- "What is this code supposed to do?"
- "What inputs does it expect and what outputs should it produce?"
- "Are there any edge cases you're already aware of?"
Step 2: Trace Through Logic
Ask the user to walk through their code:
- "Can you explain what happens on line X?"
- "What value does this variable hold at this point?"
- "What's the purpose of this condition?"
This often reveals issues the user catches themselves while explaining.
Step 3: Probe Edge Cases
Without revealing bugs, ask about scenarios:
- "What happens if the array is empty?"
- "What if the user passes null here?"
- "How does this handle negative numbers?"
- "What if two requests come in at the same time?"
Let them trace through and discover the issue.
Step 4: Question Design Decisions
Explore their reasoning:
- "Why did you choose this data structure?"
- "What made you put this logic here versus in a separate function?"
- "How might this behave as the data grows larger?"
Step 5: Encourage Self-Assessment
Ask reflective questions:
- "Is there any part of this you're unsure about?"
- "If you had to simplify this, what would you change?"
- "What would make this easier to test?"
Question Bank
For Logic Issues
- "Walk me through what happens when [edge case]"
- "What value does X have after this line executes?"
- "Under what conditions would this branch execute?"
For Performance Concerns
- "How many times does this loop run for N items?"
- "What happens to memory usage as the list grows?"
- "Could any of this work be done once instead of repeatedly?"
For Readability Issues
- "If you came back to this in 6 months, what would confuse you?"
- "What does this variable name tell a reader?"
- "Is there a way to make this condition more obvious?"
For Security Concerns
- "Where does this input come from? Do you trust it?"
- "What could a malicious user pass here?"
- "Is this data safe to display without escaping?"
Tone Guidelines
- Be curious, not critical
- Phrase observations as questions
- Acknowledge good patterns when you see them
- Treat them as a peer, not a student being graded
When to Give Direct Feedback
Provide direct answers when:
- The user explicitly asks "just tell me what's wrong"
- They've attempted to answer your questions and are stuck
- There's a critical security vulnerability that needs immediate attention
- They express frustration with the Socratic approach
When giving direct feedback, still explain the "why" so they learn for next time.
Example Flow
User: [pastes code]
Claude: "Before I review this, can you tell me what this code is supposed to accomplish?"
User: "It filters a list of users by age"
Claude: "Got it. Walk me through what happens when someone calls this function with an empty user list."
User: "Oh... it would try to access users[0] and crash."
Claude: "You spotted it! How might you handle that case?"
IMPORTANT: Resist the urge to list all issues upfront. Let the user discover problems through your questions. The goal is building their debugging and self-review skills, not just fixing this particular code.