Codebase Analysis Workflow
Execute a structured 4-phase codebase analysis workflow to gather insights.
CRITICAL: Complete ALL 4 phases. The workflow is not complete until Phase 4: Post-Analysis Actions is finished. After completing each phase, immediately proceed to the next phase without waiting for user prompts.
Phase Overview
- Exploration — Launch parallel agents to investigate the codebase
- Synthesis — Merge and analyze findings via synthesizer agent
- Reporting — Present structured analysis to the user
- Post-Analysis Actions — Save, document, or retain analysis insights
Phase 1: Codebase Exploration
Goal: Thoroughly explore the codebase to gather raw findings.
Determine analysis context:
- If
$ARGUMENTS is provided, use it as the analysis context (feature area, question, or general exploration goal)
- If no arguments, set context to "general codebase understanding"
- Set
PATH = current working directory
- Inform the user: "Analyzing codebase at:
PATH" with the analysis context
Load skills for this phase:
- Read
${CLAUDE_PLUGIN_ROOT}/skills/project-conventions/SKILL.md and apply its guidance
- Read
${CLAUDE_PLUGIN_ROOT}/skills/language-patterns/SKILL.md and apply its guidance
Determine focus areas:
- For feature-focused analysis, use 3 agents:
Agent 1: Explore entry points and user-facing code related to the context
Agent 2: Explore data models, schemas, and storage related to the context
Agent 3: Explore utilities, helpers, and shared infrastructure
- For general codebase understanding, 2 agents may suffice:
Agent 1: Explore application structure, entry points, and core logic
Agent 2: Explore configuration, infrastructure, and shared utilities
Launch code-explorer agents:
Launch agents in parallel using the Task tool with subagent_type: "dev-tools:code-explorer":
Path to analyze: [PATH]
Analysis context: [context from step 1]
Focus area: [specific focus for this agent]
Find and analyze:
- Relevant files and their purposes
- Key functions/classes and their roles
- Existing patterns and conventions
- Integration points and dependencies
Return a structured report of your findings.
Handle agent failures:
- If an agent fails, note which focus area was missed
- Continue with successful results — partial findings are still valuable
- If all agents fail, inform the user and offer to retry or explore manually
Phase 2: Synthesis and Analysis
Goal: Merge exploration findings into a unified analysis.
Launch codebase-synthesizer agent:
Use the Task tool with subagent_type: "dev-tools:codebase-synthesizer" and model: "opus":
Analysis context: [context from Phase 1]
Codebase path: [PATH]
Exploration findings from [N] agents:
--- Agent 1: [Focus Area] ---
[Full report from agent 1]
--- Agent 2: [Focus Area] ---
[Full report from agent 2]
--- Agent 3: [Focus Area] (if applicable) ---
[Full report from agent 3]
Synthesize these findings into a unified analysis. Merge duplicates,
read critical files in depth, map relationships between components,
identify patterns, and assess challenges.
Review synthesis:
- Verify the synthesizer covered all focus areas
- If critical gaps exist, use Glob/Grep to fill them directly
Phase 3: Reporting
Goal: Present a structured analysis to the user.
Load report template:
- Read
${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/report-template.md
- Use it to structure the presentation
Present the analysis:
Structure the report with these sections:
- Executive Summary — Lead with the most important finding
- Architecture Overview — How the codebase is structured
- Critical Files — The 5-10 most important files with details
- Patterns & Conventions — Recurring patterns and coding conventions
- Relationship Map — How components connect to each other
- Challenges & Risks — Technical risks and complexity hotspots
- Recommendations — Actionable next steps
IMPORTANT: Proceed immediately to Phase 4.
Do NOT stop here. Do NOT wait for user input. The report is presented, but the workflow requires Post-Analysis Actions. Continue directly to Phase 4 now.
Phase 4: Post-Analysis Actions
Goal: Let the user save, document, or retain analysis insights from the report.
Present action menu:
Use AskUserQuestion with multiSelect: true to present all available actions:
- Save report as Markdown file — Write the full report to a file
- Update README.md with analysis insights — Add architecture/structure info to README
- Update CLAUDE.md with analysis insights — Add patterns/conventions to CLAUDE.md
- Keep a condensed summary in memory — Retain a quick-reference summary in conversation context
- Address actionable insights — Fix challenges and implement recommendations from the report
If the user selects no actions, the workflow is complete. Thank the user and end.
Execute selected actions in the following fixed order:
Action: Save Report as Markdown File
- Check if a
docs/ directory exists in the project root
- If yes, suggest default path:
docs/codebase-analysis.md
- If no, suggest default path:
codebase-analysis.md in the project root
- Use
AskUserQuestion to let the user confirm or customize the file path
- Write the full report content (same as Phase 3 output) to the confirmed path using the Write tool
- Confirm the file was saved
Action: Update README.md
- Read the existing README.md at the project root
- If no README.md exists, skip this action and inform the user
- Draft updates based on analysis insights — focus on:
- Architecture overview
- Project structure
- Tech stack summary
- Present the draft to the user for approval using
AskUserQuestion with options:
- Apply — Apply the drafted updates
- Modify — Let the user describe what to change, then re-draft
- Skip — Skip this action entirely
- If approved, apply updates using the Edit tool
Action: Update CLAUDE.md
- Read the existing CLAUDE.md at the project root
- If no CLAUDE.md exists, use
AskUserQuestion to ask if one should be created
- If user declines, skip this action
- Draft updates based on analysis insights — focus on:
- Key patterns and conventions discovered
- Critical files and their roles
- Important dependencies
- Architectural decisions and constraints
- Present the draft to the user for approval using
AskUserQuestion with options:
- Apply — Apply the drafted updates
- Modify — Let the user describe what to change, then re-draft
- Skip — Skip this action entirely
- If approved, apply updates using the Edit tool (or Write tool if creating new)
Action: Keep Insights in Memory
- Present a condensed Codebase Quick Reference inline in the conversation:
- Architecture — 1-2 sentence summary of how the codebase is structured
- Key Files — 3-5 most critical files with one-line descriptions
- Conventions — Important patterns and naming conventions
- Tech Stack — Core technologies and frameworks
- Watch Out For — Top risks or complexity hotspots
- No file is written — this summary stays in conversation context for reference during the session
Action: Address Actionable Insights
IMPORTANT: This action always executes last among all selected actions. Code changes could invalidate analysis if documentation is generated after, and this is the most interactive action — it should not block simpler actions.
Step 1: Extract actionable items from the report
Parse the Phase 3 report (in conversation context) to extract items from:
- Challenges & Risks table rows — title from Challenge column, severity from Severity column, description from Impact column
- Recommendations section — each numbered item; infer severity from linked challenges (High if linked to a High challenge, otherwise Medium)
- Other findings with concrete fixes — default to Low severity
If no actionable items are found, inform the user and skip this action.
Step 2: Present severity-ranked item list
- Load reference template from
${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/actionable-insights-template.md
- Present items sorted High → Medium → Low, each showing:
- Title
- Severity (High / Medium / Low)
- Source section (Challenges & Risks, Recommendations, or Other)
- Brief description
- Use
AskUserQuestion with multiSelect: true for the user to select which items to address
- If no items selected, skip this action
Step 3: Process each selected item in priority order (High → Medium → Low)
For each item:
Assess complexity:
- Simple — Single file, clear fix, localized change
- Complex — Multi-file, architectural impact, requires investigation
Plan the fix:
- Simple: Read the target file, propose changes directly
- Complex (architectural): Launch
dev-tools:code-architect agent with model: "opus" to design the fix
- Complex (needs investigation): Launch
dev-tools:code-explorer agent to investigate before proposing
Present proposal: Show files to modify, specific changes, and rationale
User approval via AskUserQuestion:
- Apply — Execute changes with Edit/Write tools, confirm success
- Skip — Record the skip, move to next item
- Modify — User describes adjustments, re-propose the fix (max 3 revision cycles, then must Apply or Skip)
Step 4: Summarize results
Present a summary covering:
- Items addressed (with list of files modified per item)
- Items skipped
- Total files modified table
Complete the workflow:
Summarize which actions were executed and confirm the workflow is complete.
Error Handling
If any phase fails:
- Explain what went wrong
- Ask the user how to proceed:
- Retry the phase
- Skip to next phase (with partial results)
- Abort the workflow
Agent Coordination
When launching parallel agents:
- Give each agent a distinct focus area to minimize overlap
- Wait for all agents to complete before proceeding to synthesis
- Handle agent failures gracefully — continue with partial results
When calling Task tool for agents:
- Use
model: "opus" for codebase-synthesizer agent
- Use default model (sonnet) for code-explorer agents
Additional Resources
- For report structure, see references/report-template.md
- For actionable insights format, see references/actionable-insights-template.md
1---2name: codebase-analysis3description: Execute a structured codebase exploration workflow to gather insights. Use when asked to "analyze codebase", "explore codebase", "understand this codebase", or "map the codebase".4---5
6# Codebase Analysis Workflow
7
8Execute a structured 4-phase codebase analysis workflow to gather insights.
9
10**CRITICAL: Complete ALL 4 phases.** The workflow is not complete until Phase 4: Post-Analysis Actions is finished. After completing each phase, immediately proceed to the next phase without waiting for user prompts.
11
12## Phase Overview
13
141. **Exploration** — Launch parallel agents to investigate the codebase
152. **Synthesis** — Merge and analyze findings via synthesizer agent
163. **Reporting** — Present structured analysis to the user
174. **Post-Analysis Actions** — Save, document, or retain analysis insights
18
19---
20
21## Phase 1: Codebase Exploration
22
23**Goal:** Thoroughly explore the codebase to gather raw findings.
24
251. **Determine analysis context:**
26 - If `$ARGUMENTS` is provided, use it as the analysis context (feature area, question, or general exploration goal)
27 - If no arguments, set context to "general codebase understanding"
28 - Set `PATH = current working directory`
29 - Inform the user: "Analyzing codebase at: `PATH`" with the analysis context
30
312. **Load skills for this phase:**
32 - Read `${CLAUDE_PLUGIN_ROOT}/skills/project-conventions/SKILL.md` and apply its guidance
33 - Read `${CLAUDE_PLUGIN_ROOT}/skills/language-patterns/SKILL.md` and apply its guidance
34
353. **Determine focus areas:**
36 - For feature-focused analysis, use 3 agents:
37 ```
38 Agent 1: Explore entry points and user-facing code related to the context
39 Agent 2: Explore data models, schemas, and storage related to the context
40 Agent 3: Explore utilities, helpers, and shared infrastructure
41 ```
42 - For general codebase understanding, 2 agents may suffice:
43 ```
44 Agent 1: Explore application structure, entry points, and core logic
45 Agent 2: Explore configuration, infrastructure, and shared utilities
46 ```
47
484. **Launch code-explorer agents:**
49
50 Launch agents in parallel using the Task tool with `subagent_type: "dev-tools:code-explorer"`:
51 ```
52 Path to analyze: [PATH]
53 Analysis context: [context from step 1]
54 Focus area: [specific focus for this agent]
55
56 Find and analyze:
57 - Relevant files and their purposes
58 - Key functions/classes and their roles
59 - Existing patterns and conventions
60 - Integration points and dependencies
61
62 Return a structured report of your findings.
63 ```
64
655. **Handle agent failures:**
66 - If an agent fails, note which focus area was missed
67 - Continue with successful results — partial findings are still valuable
68 - If all agents fail, inform the user and offer to retry or explore manually
69
70---
71
72## Phase 2: Synthesis and Analysis
73
74**Goal:** Merge exploration findings into a unified analysis.
75
761. **Launch codebase-synthesizer agent:**
77
78 Use the Task tool with `subagent_type: "dev-tools:codebase-synthesizer"` and `model: "opus"`:
79 ```
80 Analysis context: [context from Phase 1]
81 Codebase path: [PATH]
82
83 Exploration findings from [N] agents:
84
85 --- Agent 1: [Focus Area] ---
86 [Full report from agent 1]
87
88 --- Agent 2: [Focus Area] ---
89 [Full report from agent 2]
90
91 --- Agent 3: [Focus Area] (if applicable) ---
92 [Full report from agent 3]
93
94 Synthesize these findings into a unified analysis. Merge duplicates,
95 read critical files in depth, map relationships between components,
96 identify patterns, and assess challenges.
97 ```
98
992. **Review synthesis:**
100 - Verify the synthesizer covered all focus areas
101 - If critical gaps exist, use Glob/Grep to fill them directly
102
103---
104
105## Phase 3: Reporting
106
107**Goal:** Present a structured analysis to the user.
108
1091. **Load report template:**
110 - Read `${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/report-template.md`
111 - Use it to structure the presentation
112
1132. **Present the analysis:**
114 Structure the report with these sections:
115 - **Executive Summary** — Lead with the most important finding
116 - **Architecture Overview** — How the codebase is structured
117 - **Critical Files** — The 5-10 most important files with details
118 - **Patterns & Conventions** — Recurring patterns and coding conventions
119 - **Relationship Map** — How components connect to each other
120 - **Challenges & Risks** — Technical risks and complexity hotspots
121 - **Recommendations** — Actionable next steps
122
1233. **IMPORTANT: Proceed immediately to Phase 4.**
124 Do NOT stop here. Do NOT wait for user input. The report is presented, but the workflow requires Post-Analysis Actions. Continue directly to Phase 4 now.
125
126---
127
128## Phase 4: Post-Analysis Actions
129
130**Goal:** Let the user save, document, or retain analysis insights from the report.
131
1321. **Present action menu:**
133
134 Use `AskUserQuestion` with `multiSelect: true` to present all available actions:
135 - **Save report as Markdown file** — Write the full report to a file
136 - **Update README.md with analysis insights** — Add architecture/structure info to README
137 - **Update CLAUDE.md with analysis insights** — Add patterns/conventions to CLAUDE.md
138 - **Keep a condensed summary in memory** — Retain a quick-reference summary in conversation context
139 - **Address actionable insights** — Fix challenges and implement recommendations from the report
140
141 If the user selects no actions, the workflow is complete. Thank the user and end.
142
1432. **Execute selected actions in the following fixed order:**
144
145 ### Action: Save Report as Markdown File
146
147 - Check if a `docs/` directory exists in the project root
148 - If yes, suggest default path: `docs/codebase-analysis.md`
149 - If no, suggest default path: `codebase-analysis.md` in the project root
150 - Use `AskUserQuestion` to let the user confirm or customize the file path
151 - Write the full report content (same as Phase 3 output) to the confirmed path using the Write tool
152 - Confirm the file was saved
153
154 ### Action: Update README.md
155
156 - Read the existing README.md at the project root
157 - If no README.md exists, skip this action and inform the user
158 - Draft updates based on analysis insights — focus on:
159 - Architecture overview
160 - Project structure
161 - Tech stack summary
162 - Present the draft to the user for approval using `AskUserQuestion` with options:
163 - **Apply** — Apply the drafted updates
164 - **Modify** — Let the user describe what to change, then re-draft
165 - **Skip** — Skip this action entirely
166 - If approved, apply updates using the Edit tool
167
168 ### Action: Update CLAUDE.md
169
170 - Read the existing CLAUDE.md at the project root
171 - If no CLAUDE.md exists, use `AskUserQuestion` to ask if one should be created
172 - If user declines, skip this action
173 - Draft updates based on analysis insights — focus on:
174 - Key patterns and conventions discovered
175 - Critical files and their roles
176 - Important dependencies
177 - Architectural decisions and constraints
178 - Present the draft to the user for approval using `AskUserQuestion` with options:
179 - **Apply** — Apply the drafted updates
180 - **Modify** — Let the user describe what to change, then re-draft
181 - **Skip** — Skip this action entirely
182 - If approved, apply updates using the Edit tool (or Write tool if creating new)
183
184 ### Action: Keep Insights in Memory
185
186 - Present a condensed **Codebase Quick Reference** inline in the conversation:
187 - **Architecture** — 1-2 sentence summary of how the codebase is structured
188 - **Key Files** — 3-5 most critical files with one-line descriptions
189 - **Conventions** — Important patterns and naming conventions
190 - **Tech Stack** — Core technologies and frameworks
191 - **Watch Out For** — Top risks or complexity hotspots
192 - No file is written — this summary stays in conversation context for reference during the session
193
194 ### Action: Address Actionable Insights
195
196 **IMPORTANT:** This action always executes **last** among all selected actions. Code changes could invalidate analysis if documentation is generated after, and this is the most interactive action — it should not block simpler actions.
197
198 **Step 1: Extract actionable items from the report**
199
200 Parse the Phase 3 report (in conversation context) to extract items from:
201 - **Challenges & Risks** table rows — title from Challenge column, severity from Severity column, description from Impact column
202 - **Recommendations** section — each numbered item; infer severity from linked challenges (High if linked to a High challenge, otherwise Medium)
203 - **Other findings** with concrete fixes — default to Low severity
204
205 If no actionable items are found, inform the user and skip this action.
206
207 **Step 2: Present severity-ranked item list**
208
209 - Load reference template from `${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/actionable-insights-template.md`
210 - Present items sorted High → Medium → Low, each showing:
211 - Title
212 - Severity (High / Medium / Low)
213 - Source section (Challenges & Risks, Recommendations, or Other)
214 - Brief description
215 - Use `AskUserQuestion` with `multiSelect: true` for the user to select which items to address
216 - If no items selected, skip this action
217
218 **Step 3: Process each selected item in priority order (High → Medium → Low)**
219
220 For each item:
221
222 1. **Assess complexity:**
223 - **Simple** — Single file, clear fix, localized change
224 - **Complex** — Multi-file, architectural impact, requires investigation
225
226 2. **Plan the fix:**
227 - Simple: Read the target file, propose changes directly
228 - Complex (architectural): Launch `dev-tools:code-architect` agent with `model: "opus"` to design the fix
229 - Complex (needs investigation): Launch `dev-tools:code-explorer` agent to investigate before proposing
230
231 3. **Present proposal:** Show files to modify, specific changes, and rationale
232
233 4. **User approval** via `AskUserQuestion`:
234 - **Apply** — Execute changes with Edit/Write tools, confirm success
235 - **Skip** — Record the skip, move to next item
236 - **Modify** — User describes adjustments, re-propose the fix (max 3 revision cycles, then must Apply or Skip)
237
238 **Step 4: Summarize results**
239
240 Present a summary covering:
241 - Items addressed (with list of files modified per item)
242 - Items skipped
243 - Total files modified table
244
2453. **Complete the workflow:**
246 Summarize which actions were executed and confirm the workflow is complete.
247
248---
249
250## Error Handling
251
252If any phase fails:
2531. Explain what went wrong
2542. Ask the user how to proceed:
255 - Retry the phase
256 - Skip to next phase (with partial results)
257 - Abort the workflow
258
259---
260
261## Agent Coordination
262
263When launching parallel agents:
264- Give each agent a distinct focus area to minimize overlap
265- Wait for all agents to complete before proceeding to synthesis
266- Handle agent failures gracefully — continue with partial results
267
268When calling Task tool for agents:
269- Use `model: "opus"` for codebase-synthesizer agent
270- Use default model (sonnet) for code-explorer agents
271
272---
273
274## Additional Resources
275
276- For report structure, see [references/report-template.md](references/report-template.md)
277- For actionable insights format, see [references/actionable-insights-template.md](references/actionable-insights-template.md)