Codebase Analysis Workflow
Execute a 3-phase codebase analysis workflow. This workflow explores a codebase, analyzes its architecture, and generates a comprehensive report.
CRITICAL: Complete ALL 3 phases. After completing each phase, immediately proceed to the next phase without waiting for user prompts.
Phase Overview
- Codebase Exploration - Explore structure, patterns, and dependencies
- Deep Analysis - Analyze findings to identify architecture and patterns
- Output & Context Loading - Present options and deliver results in user's preferred format
Phase 1: Codebase Exploration
Goal: Thoroughly explore the codebase to gather raw findings.
Determine the analysis path:
- If
$ARGUMENTS was provided, use that path
- Otherwise, use the current working directory
- Inform the user of the scope being analyzed
Launch 3 code-explorer agents in parallel using the Task tool with subagent_type: "dev-tools:code-explorer":
Agent 1: Project Structure & Configuration
Explore and analyze the project structure and configuration.
Path to analyze: [path]
Focus on:
- Project root structure (directories and their purposes)
- Entry points (main files, index files, CLI entry points)
- Configuration files (package.json, pyproject.toml, tsconfig.json, etc.)
- Build configuration (webpack, vite, rollup, etc.)
- Development tools (.eslintrc, .prettierrc, etc.)
- CI/CD configuration (.github/workflows, Jenkinsfile, etc.)
- Environment configuration (.env.example, config files)
Return a structured report of:
- Directory structure overview
- Key entry points and their purposes
- Configuration summary
- Build and development tooling
Agent 2: Core Modules & Business Logic
Explore and analyze the core modules and business logic.
Path to analyze: [path]
Focus on:
- Core source directories (src/, lib/, app/)
- Key classes, functions, and modules
- Business logic and domain models
- State management (if applicable)
- Data models and schemas
- Service layers and APIs
- Utility and helper modules
Return a structured report of:
- Key modules and their responsibilities
- Important classes/functions with brief descriptions
- Design patterns observed
- Code organization patterns
Agent 3: Dependencies & Integrations
Explore and analyze dependencies and external integrations.
Path to analyze: [path]
Focus on:
- Package dependencies (production vs development)
- Internal module dependencies (how modules import each other)
- External API integrations
- Database connections and ORM usage
- Third-party service integrations
- Authentication/authorization mechanisms
- Caching layers
- Message queues or event systems
Return a structured report of:
- Dependency analysis (major frameworks, libraries)
- External integration points
- Data storage mechanisms
- Communication patterns
Wait for all agents to complete and collect their findings.
Synthesize exploration findings:
- Combine results from all 3 agents
- Identify overlapping or conflicting information
- Note any gaps in coverage
- Create a consolidated findings document
Phase 2: Deep Analysis
Goal: Analyze exploration findings to identify architecture, patterns, and insights.
Launch codebase-analyzer agent using the Task tool with subagent_type: "dev-tools:codebase-analyzer":
Analyze the following codebase exploration findings and produce a deep analysis.
Path analyzed: [path]
## Exploration Findings
[Include the synthesized findings from Phase 1]
---
Produce a comprehensive analysis covering:
1. Architecture style identification
2. Key modules and their responsibilities
3. Dependency relationships between modules
4. Technology stack summary
5. Code patterns and conventions
6. Entry points and data flow
7. External integrations
8. Testing approach
9. Build and deployment patterns
10. Strengths and areas for improvement
Wait for analysis to complete and collect the results.
Phase 3: Output & Context Loading
Goal: Present output options and deliver analysis results in the user's preferred format.
Ask user for output preferences using AskUserQuestion with multi-select:
Question: "How would you like to use the analysis results?"
Header: "Output"
Options:
- Label: "Save detailed report"
Description: "Generate a comprehensive markdown report to internal/reports/"
- Label: "Load into session context"
Description: "Inject analysis into this session so I can reference it when answering questions"
- Label: "Update project docs"
Description: "Update README.md and/or CLAUDE.md with analysis summary"
MultiSelect: true
Handle the user's selection:
If NEITHER option is selected:
- Display a brief summary (~200-300 words) directly in the chat
- Confirm: "Analysis complete. Key findings displayed above."
- Skip to final message
If "Save detailed report" is selected:
If "Load into session context" is selected:
- Ask for detail level (Condensed summary or Full analysis)
- Display the formatted context directly in the response
- Confirm: "Analysis loaded into session context."
If "Update project docs" is selected:
- Ask which files to update (README.md, CLAUDE.md, or both)
- Launch report-generator agent with appropriate mode
- Confirm which files were updated
Final message:
- Summarize what was done
- Offer next steps: ask questions, run on different path, deep-dive modules
Error Handling
If any phase fails:
- Explain what went wrong
- Ask the user how to proceed: Retry, Skip, or Abort
If an agent returns incomplete results:
- Note the gaps in coverage
- Continue with available information
- Document limitations in the final report
Agent Coordination
When launching parallel agents in Phase 1:
- Give each agent a distinct focus area
- Wait for all agents to complete before synthesizing
- Handle agent failures gracefully (continue with partial results)
When calling Task tool for agents:
- Use
model: "opus" for codebase-analyzer agent
- Use default model (sonnet) for code-explorer and report-generator agents
1---2name: analyze-codebase3description: Analyze a codebase to generate a comprehensive architecture and structure report. Use when user wants to understand a codebase, explore project structure, or generate analysis.4---56# Codebase Analysis Workflow78Execute a 3-phase codebase analysis workflow. This workflow explores a codebase, analyzes its architecture, and generates a comprehensive report.910**CRITICAL: Complete ALL 3 phases.** After completing each phase, immediately proceed to the next phase without waiting for user prompts.1112## Phase Overview13141. **Codebase Exploration** - Explore structure, patterns, and dependencies152. **Deep Analysis** - Analyze findings to identify architecture and patterns163. **Output & Context Loading** - Present options and deliver results in user's preferred format1718---1920## Phase 1: Codebase Exploration2122**Goal:** Thoroughly explore the codebase to gather raw findings.23241. Determine the analysis path:25 - If `$ARGUMENTS` was provided, use that path26 - Otherwise, use the current working directory27 - Inform the user of the scope being analyzed28292. **Launch 3 code-explorer agents in parallel** using the Task tool with `subagent_type: "dev-tools:code-explorer"`:3031 **Agent 1: Project Structure & Configuration**32 ```33 Explore and analyze the project structure and configuration.34 Path to analyze: [path]3536 Focus on:37 - Project root structure (directories and their purposes)38 - Entry points (main files, index files, CLI entry points)39 - Configuration files (package.json, pyproject.toml, tsconfig.json, etc.)40 - Build configuration (webpack, vite, rollup, etc.)41 - Development tools (.eslintrc, .prettierrc, etc.)42 - CI/CD configuration (.github/workflows, Jenkinsfile, etc.)43 - Environment configuration (.env.example, config files)4445 Return a structured report of:46 - Directory structure overview47 - Key entry points and their purposes48 - Configuration summary49 - Build and development tooling50 ```5152 **Agent 2: Core Modules & Business Logic**53 ```54 Explore and analyze the core modules and business logic.55 Path to analyze: [path]5657 Focus on:58 - Core source directories (src/, lib/, app/)59 - Key classes, functions, and modules60 - Business logic and domain models61 - State management (if applicable)62 - Data models and schemas63 - Service layers and APIs64 - Utility and helper modules6566 Return a structured report of:67 - Key modules and their responsibilities68 - Important classes/functions with brief descriptions69 - Design patterns observed70 - Code organization patterns71 ```7273 **Agent 3: Dependencies & Integrations**74 ```75 Explore and analyze dependencies and external integrations.76 Path to analyze: [path]7778 Focus on:79 - Package dependencies (production vs development)80 - Internal module dependencies (how modules import each other)81 - External API integrations82 - Database connections and ORM usage83 - Third-party service integrations84 - Authentication/authorization mechanisms85 - Caching layers86 - Message queues or event systems8788 Return a structured report of:89 - Dependency analysis (major frameworks, libraries)90 - External integration points91 - Data storage mechanisms92 - Communication patterns93 ```94953. **Wait for all agents to complete** and collect their findings.96974. **Synthesize exploration findings:**98 - Combine results from all 3 agents99 - Identify overlapping or conflicting information100 - Note any gaps in coverage101 - Create a consolidated findings document102103---104105## Phase 2: Deep Analysis106107**Goal:** Analyze exploration findings to identify architecture, patterns, and insights.1081091. **Launch codebase-analyzer agent** using the Task tool with `subagent_type: "dev-tools:codebase-analyzer"`:110111 ```112 Analyze the following codebase exploration findings and produce a deep analysis.113114 Path analyzed: [path]115116 ## Exploration Findings117118 [Include the synthesized findings from Phase 1]119120 ---121122 Produce a comprehensive analysis covering:123 1. Architecture style identification124 2. Key modules and their responsibilities125 3. Dependency relationships between modules126 4. Technology stack summary127 5. Code patterns and conventions128 6. Entry points and data flow129 7. External integrations130 8. Testing approach131 9. Build and deployment patterns132 10. Strengths and areas for improvement133 ```1341352. **Wait for analysis to complete** and collect the results.136137---138139## Phase 3: Output & Context Loading140141**Goal:** Present output options and deliver analysis results in the user's preferred format.1421431. **Ask user for output preferences** using `AskUserQuestion` with multi-select:144145 ```146 Question: "How would you like to use the analysis results?"147 Header: "Output"148 Options:149 - Label: "Save detailed report"150 Description: "Generate a comprehensive markdown report to internal/reports/"151 - Label: "Load into session context"152 Description: "Inject analysis into this session so I can reference it when answering questions"153 - Label: "Update project docs"154 Description: "Update README.md and/or CLAUDE.md with analysis summary"155 MultiSelect: true156 ```1571582. **Handle the user's selection:**159160 ### If NEITHER option is selected:161 - Display a brief summary (~200-300 words) directly in the chat162 - Confirm: "Analysis complete. Key findings displayed above."163 - Skip to final message164165 ### If "Save detailed report" is selected:166 - Ensure output directory exists: `mkdir -p internal/reports`167 - **Launch report-generator agent** using Task tool with `subagent_type: "dev-tools:report-generator"`:168 ```169 Generate a comprehensive codebase analysis report in markdown format.170171 Path analyzed: [path]172 Analysis date: [current date]173174 ## Analysis Findings175176 [Include the complete analysis from Phase 2]177178 ---179180 Generate a well-structured markdown report and save it to:181 internal/reports/codebase-analysis-report.md182 ```183 - Confirm: "Report saved to `internal/reports/codebase-analysis-report.md`"184185 ### If "Load into session context" is selected:186 - Ask for detail level (Condensed summary or Full analysis)187 - Display the formatted context directly in the response188 - Confirm: "Analysis loaded into session context."189190 ### If "Update project docs" is selected:191 - Ask which files to update (README.md, CLAUDE.md, or both)192 - Launch report-generator agent with appropriate mode193 - Confirm which files were updated1941953. **Final message:**196 - Summarize what was done197 - Offer next steps: ask questions, run on different path, deep-dive modules198199---200201## Error Handling202203If any phase fails:2041. Explain what went wrong2052. Ask the user how to proceed: Retry, Skip, or Abort206207If an agent returns incomplete results:208- Note the gaps in coverage209- Continue with available information210- Document limitations in the final report211212## Agent Coordination213214When launching parallel agents in Phase 1:215- Give each agent a distinct focus area216- Wait for all agents to complete before synthesizing217- Handle agent failures gracefully (continue with partial results)218219When calling Task tool for agents:220- Use `model: "opus"` for codebase-analyzer agent221- Use default model (sonnet) for code-explorer and report-generator agents