---
name: config-audit:analyze
description: Phase 2 - Generate analysis report with hierarchy map and issue detection
allowed-tools: Read, Write, Edit, Glob, Grep, Agent
model: opus
---

# Config-Audit: Analysis (Phase 2)

Generate comprehensive analysis report from discovery findings.

## Prerequisites

- Must have completed Phase 1 (discovery)
- Findings must exist in `~/.claude/config-audit/sessions/{session-id}/findings/`

## Implementation

### Step 1: Verify session state

Read `~/.claude/config-audit/sessions/{session-id}/state.yaml` and verify discovery phase completed. If not, tell the user: "Discovery hasn't been run yet. Start with `/config-audit discover` or just run `/config-audit` for a full audit."

### Step 2: Tell the user what's happening

```
## Analyzing Configuration

Reading your scan findings and generating a detailed analysis report...
This includes hierarchy mapping, conflict detection, and prioritized recommendations.
```

### Step 3: Spawn analyzer agent

Tell the user: **"Generating analysis (this takes about 30 seconds)..."**

```
Agent(subagent_type: "config-audit:analyzer-agent")
  model: sonnet
  prompt: |
    Analyze all findings in: ~/.claude/config-audit/sessions/{session-id}/findings/
    Generate comprehensive report covering:
    1. Executive summary with key metrics
    2. Hierarchy map visualization
    3. Conflict detection across config layers
    4. CLAUDE.md quality assessment
    5. Security issues (secrets, permissions)
    6. Top 10 prioritized recommendations
    Output to: ~/.claude/config-audit/sessions/{session-id}/analysis-report.md
```

### Step 4: Present summary

After the agent completes, read the generated report and show a brief summary:

```markdown
### Analysis Complete

Report generated with:
- {N} conflicts detected
- {N} optimization opportunities
- {N} security notes
- Top recommendation: {first recommendation}

Full report: `~/.claude/config-audit/sessions/{session-id}/analysis-report.md`

### What's next

- **`/config-audit plan`** — Turn findings into a prioritized action plan
- **`/config-audit fix`** — Auto-fix deterministic issues right away
```

### Step 5: Update state

Update `state.yaml` with `current_phase: "analyze"`, `next_phase: "plan"`.
