Codebase Analysis Workflow
Execute a structured 3-phase codebase analysis workflow to gather insights.
CRITICAL: Complete ALL 3 phases. The workflow is not complete until Phase 3: Post-Analysis Actions is finished. After completing each phase, immediately proceed to the next phase without waiting for user prompts.
Phase Overview
- Deep Analysis — Explore and synthesize codebase findings via deep-analysis skill
- Reporting — Present structured analysis to the user
- Post-Analysis Actions — Save, document, or retain analysis insights
Phase 1: Deep Analysis
Goal: Explore the codebase and synthesize findings.
Determine analysis context:
- If
$ARGUMENTS is provided, use it as the analysis context
- If no arguments, set context to "general codebase understanding"
Run deep-analysis workflow:
- Check if
$ARGUMENTS contains --teams flag
- If
--teams is present:
- Read
${CLAUDE_PLUGIN_ROOT}/skills/teams-deep-analysis/SKILL.md and follow its workflow
- Remove
--teams from the analysis context
- Otherwise:
- Read
${CLAUDE_PLUGIN_ROOT}/skills/deep-analysis/SKILL.md and follow its workflow (default)
- Pass the analysis context from step 1
- This handles exploration (parallel code-explorer agents) and synthesis (codebase-synthesizer agent)
Verify results:
- Ensure the synthesis covers the analysis context adequately
- If critical gaps remain, use Glob/Grep to fill them directly
Phase 2: 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 3.
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 3 now.
Phase 3: 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 2 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 2 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
claude-alchemy-tools:code-architect agent with model: "opus" to design the fix
- Complex (needs investigation): Launch
claude-alchemy-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
Exploration and synthesis agent coordination is handled by the deep-analysis skill in Phase 1. See that skill for agent model tiers and failure handling details.
Additional Resources
- For report structure, see references/report-template.md
- For actionable insights format, see references/actionable-insights-template.md
1---2name: codebase-analysis-133description: 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---56# Codebase Analysis Workflow78Execute a structured 3-phase codebase analysis workflow to gather insights.910**CRITICAL: Complete ALL 3 phases.** The workflow is not complete until Phase 3: Post-Analysis Actions is finished. After completing each phase, immediately proceed to the next phase without waiting for user prompts.1112## Phase Overview13141. **Deep Analysis** — Explore and synthesize codebase findings via deep-analysis skill152. **Reporting** — Present structured analysis to the user163. **Post-Analysis Actions** — Save, document, or retain analysis insights1718---1920## Phase 1: Deep Analysis2122**Goal:** Explore the codebase and synthesize findings.23241. **Determine analysis context:**25 - If `$ARGUMENTS` is provided, use it as the analysis context26 - If no arguments, set context to "general codebase understanding"27282. **Run deep-analysis workflow:**29 - Check if `$ARGUMENTS` contains `--teams` flag30 - If `--teams` is present:31 - Read `${CLAUDE_PLUGIN_ROOT}/skills/teams-deep-analysis/SKILL.md` and follow its workflow32 - Remove `--teams` from the analysis context33 - Otherwise:34 - Read `${CLAUDE_PLUGIN_ROOT}/skills/deep-analysis/SKILL.md` and follow its workflow (default)35 - Pass the analysis context from step 136 - This handles exploration (parallel code-explorer agents) and synthesis (codebase-synthesizer agent)37383. **Verify results:**39 - Ensure the synthesis covers the analysis context adequately40 - If critical gaps remain, use Glob/Grep to fill them directly4142---4344## Phase 2: Reporting4546**Goal:** Present a structured analysis to the user.47481. **Load report template:**49 - Read `${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/report-template.md`50 - Use it to structure the presentation51522. **Present the analysis:**53 Structure the report with these sections:54 - **Executive Summary** — Lead with the most important finding55 - **Architecture Overview** — How the codebase is structured56 - **Critical Files** — The 5-10 most important files with details57 - **Patterns & Conventions** — Recurring patterns and coding conventions58 - **Relationship Map** — How components connect to each other59 - **Challenges & Risks** — Technical risks and complexity hotspots60 - **Recommendations** — Actionable next steps61623. **IMPORTANT: Proceed immediately to Phase 3.**63 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 3 now.6465---6667## Phase 3: Post-Analysis Actions6869**Goal:** Let the user save, document, or retain analysis insights from the report.70711. **Present action menu:**7273 Use `AskUserQuestion` with `multiSelect: true` to present all available actions:74 - **Save report as Markdown file** — Write the full report to a file75 - **Update README.md with analysis insights** — Add architecture/structure info to README76 - **Update CLAUDE.md with analysis insights** — Add patterns/conventions to CLAUDE.md77 - **Keep a condensed summary in memory** — Retain a quick-reference summary in conversation context78 - **Address actionable insights** — Fix challenges and implement recommendations from the report7980 If the user selects no actions, the workflow is complete. Thank the user and end.81822. **Execute selected actions in the following fixed order:**8384 ### Action: Save Report as Markdown File8586 - Check if a `docs/` directory exists in the project root87 - If yes, suggest default path: `docs/codebase-analysis.md`88 - If no, suggest default path: `codebase-analysis.md` in the project root89 - Use `AskUserQuestion` to let the user confirm or customize the file path90 - Write the full report content (same as Phase 2 output) to the confirmed path using the Write tool91 - Confirm the file was saved9293 ### Action: Update README.md9495 - Read the existing README.md at the project root96 - If no README.md exists, skip this action and inform the user97 - Draft updates based on analysis insights — focus on:98 - Architecture overview99 - Project structure100 - Tech stack summary101 - Present the draft to the user for approval using `AskUserQuestion` with options:102 - **Apply** — Apply the drafted updates103 - **Modify** — Let the user describe what to change, then re-draft104 - **Skip** — Skip this action entirely105 - If approved, apply updates using the Edit tool106107 ### Action: Update CLAUDE.md108109 - Read the existing CLAUDE.md at the project root110 - If no CLAUDE.md exists, use `AskUserQuestion` to ask if one should be created111 - If user declines, skip this action112 - Draft updates based on analysis insights — focus on:113 - Key patterns and conventions discovered114 - Critical files and their roles115 - Important dependencies116 - Architectural decisions and constraints117 - Present the draft to the user for approval using `AskUserQuestion` with options:118 - **Apply** — Apply the drafted updates119 - **Modify** — Let the user describe what to change, then re-draft120 - **Skip** — Skip this action entirely121 - If approved, apply updates using the Edit tool (or Write tool if creating new)122123 ### Action: Keep Insights in Memory124125 - Present a condensed **Codebase Quick Reference** inline in the conversation:126 - **Architecture** — 1-2 sentence summary of how the codebase is structured127 - **Key Files** — 3-5 most critical files with one-line descriptions128 - **Conventions** — Important patterns and naming conventions129 - **Tech Stack** — Core technologies and frameworks130 - **Watch Out For** — Top risks or complexity hotspots131 - No file is written — this summary stays in conversation context for reference during the session132133 ### Action: Address Actionable Insights134135 **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.136137 **Step 1: Extract actionable items from the report**138139 Parse the Phase 2 report (in conversation context) to extract items from:140 - **Challenges & Risks** table rows — title from Challenge column, severity from Severity column, description from Impact column141 - **Recommendations** section — each numbered item; infer severity from linked challenges (High if linked to a High challenge, otherwise Medium)142 - **Other findings** with concrete fixes — default to Low severity143144 If no actionable items are found, inform the user and skip this action.145146 **Step 2: Present severity-ranked item list**147148 - Load reference template from `${CLAUDE_PLUGIN_ROOT}/skills/codebase-analysis/references/actionable-insights-template.md`149 - Present items sorted High → Medium → Low, each showing:150 - Title151 - Severity (High / Medium / Low)152 - Source section (Challenges & Risks, Recommendations, or Other)153 - Brief description154 - Use `AskUserQuestion` with `multiSelect: true` for the user to select which items to address155 - If no items selected, skip this action156157 **Step 3: Process each selected item in priority order (High → Medium → Low)**158159 For each item:160161 1. **Assess complexity:**162 - **Simple** — Single file, clear fix, localized change163 - **Complex** — Multi-file, architectural impact, requires investigation164165 2. **Plan the fix:**166 - Simple: Read the target file, propose changes directly167 - Complex (architectural): Launch `claude-alchemy-tools:code-architect` agent with `model: "opus"` to design the fix168 - Complex (needs investigation): Launch `claude-alchemy-tools:code-explorer` agent to investigate before proposing169170 3. **Present proposal:** Show files to modify, specific changes, and rationale171172 4. **User approval** via `AskUserQuestion`:173 - **Apply** — Execute changes with Edit/Write tools, confirm success174 - **Skip** — Record the skip, move to next item175 - **Modify** — User describes adjustments, re-propose the fix (max 3 revision cycles, then must Apply or Skip)176177 **Step 4: Summarize results**178179 Present a summary covering:180 - Items addressed (with list of files modified per item)181 - Items skipped182 - Total files modified table1831843. **Complete the workflow:**185 Summarize which actions were executed and confirm the workflow is complete.186187---188189## Error Handling190191If any phase fails:1921. Explain what went wrong1932. Ask the user how to proceed:194 - Retry the phase195 - Skip to next phase (with partial results)196 - Abort the workflow197198---199200## Agent Coordination201202Exploration and synthesis agent coordination is handled by the `deep-analysis` skill in Phase 1. See that skill for agent model tiers and failure handling details.203204---205206## Additional Resources207208- For report structure, see [references/report-template.md](references/report-template.md)209- For actionable insights format, see [references/actionable-insights-template.md](references/actionable-insights-template.md)