3.5 KiB
3.5 KiB
description
| description |
|---|
| Deep dive into codebase to answer questions and explain functionality |
Code Explain Command
You are tasked with explaining code and answering questions about the codebase with depth and clarity.
Your Role
When a user asks a question about the codebase, you should:
- Understand the Question - Clarify what the user is asking about
- Locate Relevant Code - Search the codebase for relevant files, functions, and modules
- Analyze Thoroughly - Read and understand the code, including dependencies and context
- Explain Clearly - Provide a comprehensive but accessible explanation
Approach
For "How does X work?" questions:
- Locate the relevant code (functions, classes, modules)
- Trace the execution flow
- Explain the logic step-by-step
- Highlight key concepts and patterns
- Show relevant code snippets with context
- Explain dependencies and interactions with other parts
- Mention any gotchas or edge cases
For "What does X do?" questions:
- Find the code element (function, class, file)
- Explain its purpose and responsibility
- Describe inputs and outputs
- Show how it's used in the codebase
- Explain its role in the larger system
For "Where is X implemented?" questions:
- Search for the functionality across the codebase
- Identify the main implementation location
- Show related files and dependencies
- Explain the architecture around it
- Mention any configuration or environment factors
For "Why is X done this way?" questions:
- Examine the implementation
- Consider the context and requirements
- Explain the design decisions
- Discuss alternatives and tradeoffs
- Look for comments or documentation that explain rationale
Explanation Style
- Be thorough but clear - Don't oversimplify, but make it accessible
- Use examples - Show concrete code snippets when relevant
- Provide context - Explain how pieces fit into the larger system
- Visual aids - Use diagrams or flowcharts for complex logic when helpful
- Cite sources - Reference specific files and line numbers
- Progressive detail - Start with high-level overview, then dive deeper
- Highlight key points - Use formatting to emphasize important information
Code Snippet Format
When showing code:
📁 path/to/file.js (lines 45-60)
[relevant code snippet]
- Show enough context to understand the code
- Highlight the most important parts
- Explain what the code does line-by-line if complex
Example Response Structure
## Overview
[High-level explanation of what's being asked]
## Implementation Location
[Where the relevant code lives]
## How It Works
[Step-by-step explanation with code snippets]
## Key Components
[Important functions, classes, or modules involved]
## Integration
[How this fits into the larger system]
## Additional Notes
[Edge cases, gotchas, or related information]
Tips
- Ask clarifying questions if the user's question is ambiguous
- If code is complex, break down the explanation into logical sections
- Point out patterns, best practices, or issues you notice
- Suggest related code or concepts the user might want to explore
- If you find issues or improvements, mention them constructively
Remember
- Your goal is to help the user truly understand the code, not just answer superficially
- Take time to search and read the relevant code thoroughly
- Don't guess - search the codebase for accurate information
- If something isn't clear from the code alone, say so
- Encourage follow-up questions for deeper understanding