Code Analyzer
Provide comprehensive code explanation through multi-agent analysis for architecture, patterns, security, and performance insights.
Execution Steps
Identify the target — Extract the file path or module name from the user's request. If no target is specified, ask: "Which file or module would you like me to analyze?"
Verify the target exists — Use Read or Glob to confirm the file exists. If it doesn't, report and stop: "Could not find <path>. Please check the path and try again."
Infer analysis depth from the user's request:
overview — request uses words like "quick", "summary", "briefly", "what does this do"
deep — request mentions "security", "performance", "vulnerabilities", "thorough", "deep", "comprehensive"
architectural — request mentions "architecture", "system", "how does this fit", "overall design"
- Default to
overview when depth is ambiguous. deep spawns three agents; running
that for "what does this file do" costs three context loads to answer a one-agent
question. Escalate to deep only on evidence — the user asked for it, overview
surfaced a concrete security or performance concern, or the target is a trust boundary
(auth, payments, external input parsing).
Dispatch agents based on depth:
overview: spawn code-explainer-agent only; pass the file path and its contents
deep: spawn code-explainer-agent + security-analyzer-agent + performance-analyzer-agent in parallel
architectural: run context-loader-agent first to gather system-level context, then spawn code-explainer-agent + security-analyzer-agent + performance-analyzer-agent in parallel with that context
Synthesize results — Combine agent outputs into a single structured report. Integrate and deduplicate findings; do not dump raw agent output.
Handle agent failures — If an agent errors or returns empty output, note it in the report ("Security analysis unavailable") and continue with remaining results.
Analysis Depth
| Depth |
Description |
Agents Used |
overview |
Quick summary |
code-explainer |
deep |
Comprehensive analysis |
code-explainer, security-analyzer, performance-analyzer |
architectural |
System-level context |
All agents + context-loader |
Focus Areas
- patterns: Design patterns, SOLID, anti-patterns
- security: Vulnerabilities, input validation, auth
- performance: Algorithm complexity, memory, queries
- all: Complete analysis (default)
Output Includes
- Summary: Purpose and the concrete complexity signals observed (function count, nesting
depth, file length). Do not emit a maintainability score — there is no measurement behind it.
- Architecture: Patterns, layers, coupling analysis
- Functionality: Main purpose, data flow, side effects
- Dependencies: Imports, exports, circular dependencies
- Risks: Security, performance, maintainability issues
- Improvements: Quick wins and refactoring suggestions
Delegation
For simple explanations, use code-explainer-agent directly.
For deep analysis, coordinate:
- code-explainer-agent: Architecture and patterns
- security-analyzer-agent: Vulnerability assessment
- performance-analyzer-agent: Complexity analysis
- context-loader-agent: System-level context
Examples
"Explain src/auth/login.ts to me"
"What does this API endpoint do?"
"Analyze the security of the payment module"
"Is there anything wrong with this code?"
Detailed Reference
For output schemas and advanced options, see explain-file-guide.md.
1---2name: analyze-code3description: Comprehensive code explanation and analysis. Use when user says "explain this file to me", "what does this code do", "analyze the security of this module", "review the performance of this function", or "help me understand this architecture".4---56# Code Analyzer78Provide comprehensive code explanation through multi-agent analysis for architecture, patterns, security, and performance insights.910## Execution Steps11121. **Identify the target** — Extract the file path or module name from the user's request. If no target is specified, ask: "Which file or module would you like me to analyze?"13142. **Verify the target exists** — Use `Read` or `Glob` to confirm the file exists. If it doesn't, report and stop: "Could not find `<path>`. Please check the path and try again."15163. **Infer analysis depth** from the user's request:1718 - `overview` — request uses words like "quick", "summary", "briefly", "what does this do"19 - `deep` — request mentions "security", "performance", "vulnerabilities", "thorough", "deep", "comprehensive"20 - `architectural` — request mentions "architecture", "system", "how does this fit", "overall design"21 - **Default to `overview` when depth is ambiguous.** `deep` spawns three agents; running22 that for "what does this file do" costs three context loads to answer a one-agent23 question. Escalate to `deep` only on evidence — the user asked for it, `overview`24 surfaced a concrete security or performance concern, or the target is a trust boundary25 (auth, payments, external input parsing).26274. **Dispatch agents** based on depth:2829 - `overview`: spawn **code-explainer-agent** only; pass the file path and its contents30 - `deep`: spawn **code-explainer-agent** + **security-analyzer-agent** + **performance-analyzer-agent** in parallel31 - `architectural`: run **context-loader-agent** first to gather system-level context, then spawn **code-explainer-agent** + **security-analyzer-agent** + **performance-analyzer-agent** in parallel with that context32335. **Synthesize results** — Combine agent outputs into a single structured report. Integrate and deduplicate findings; do not dump raw agent output.34356. **Handle agent failures** — If an agent errors or returns empty output, note it in the report ("Security analysis unavailable") and continue with remaining results.3637## Analysis Depth3839| Depth | Description | Agents Used |40| --------------- | ---------------------- | ------------------------------------------------------- |41| `overview` | Quick summary | code-explainer |42| `deep` | Comprehensive analysis | code-explainer, security-analyzer, performance-analyzer |43| `architectural` | System-level context | All agents + context-loader |4445## Focus Areas4647- **patterns**: Design patterns, SOLID, anti-patterns48- **security**: Vulnerabilities, input validation, auth49- **performance**: Algorithm complexity, memory, queries50- **all**: Complete analysis (default)5152## Output Includes5354- **Summary**: Purpose and the concrete complexity signals observed (function count, nesting55 depth, file length). Do not emit a maintainability score — there is no measurement behind it.56- **Architecture**: Patterns, layers, coupling analysis57- **Functionality**: Main purpose, data flow, side effects58- **Dependencies**: Imports, exports, circular dependencies59- **Risks**: Security, performance, maintainability issues60- **Improvements**: Quick wins and refactoring suggestions6162## Delegation6364For simple explanations, use **code-explainer-agent** directly.6566For deep analysis, coordinate:6768- **code-explainer-agent**: Architecture and patterns69- **security-analyzer-agent**: Vulnerability assessment70- **performance-analyzer-agent**: Complexity analysis71- **context-loader-agent**: System-level context7273## Examples7475```76"Explain src/auth/login.ts to me"77"What does this API endpoint do?"78"Analyze the security of the payment module"79"Is there anything wrong with this code?"80```8182## Detailed Reference8384For output schemas and advanced options, see [explain-file-guide.md](explain-file-guide.md).