Files
FoundryVTT/.claude/commands/analyze.md
2025-11-06 14:04:48 +01:00

5.1 KiB

description, allowed-tools, argument-hint
description allowed-tools argument-hint
Perform comprehensive code analysis including complexity, dependencies, and quality metrics Read(*), Grep(*), Glob(*), Bash(*)
path

Analyze Command

Perform comprehensive code analysis on the specified path or current directory.

Technology Adaptation

Configuration Source: CLAUDE.md

Consult CLAUDE.md for:

  • Analysis Tools: (SonarQube, ESLint, Pylint, Roslyn Analyzers, etc.)
  • Quality Metrics: Project-specific thresholds
  • Package Manager: For dependency analysis

Instructions

  1. Determine Scope

    • If $ARGUMENTS provided: Analyze that specific path
    • Otherwise: Analyze entire project
  2. Load Previous Analysis Lessons ⚠️ IMPORTANT

    • Use Serena MCP list_memories to see past analysis results
    • Use read_memory to load relevant findings:
      • "analysis-*" - Previous analysis reports
      • "lesson-analysis-*" - Past analysis insights
      • "pattern-*" - Known patterns in the codebase
    • Compare current state with past analysis to identify trends
    • Apply lessons learned from previous analyses
  3. Gather Context

    • Read CLAUDE.md for project structure and quality standards
    • Identify primary language(s) from CLAUDE.md
    • Use serena MCP to get codebase overview
  4. Perform Analysis

    • Code Complexity: Identify complex functions/classes
    • Dependencies: Check for outdated or vulnerable packages
    • Code Duplication: Find repeated code patterns
    • Test Coverage: Assess test coverage (if tests exist)
    • Code Style: Check against CLAUDE.md standards
    • Documentation: Assess documentation completeness
    • Compare with past analysis to identify improvements or regressions
  5. Generate Report

    • Summarize findings by category
    • Highlight top issues to address
    • Provide actionable recommendations
    • Reference CLAUDE.md standards

MCP Server Usage

Serena MCP

Code Navigation:

  • get_symbols_overview - Analyze file structure and complexity
  • find_symbol - Locate specific components for detailed analysis
  • find_referencing_symbols - Understand dependencies and coupling
  • search_for_pattern - Find code duplication and patterns

Persistent Memory (stored in .serena/memories/):

  • Use write_memory to store analysis results:
    • "analysis-code-complexity-[date]"
    • "analysis-dependencies-[date]"
    • "analysis-technical-debt-[date]"
    • "pattern-complexity-hotspots"
  • Use read_memory to compare with past analyses and track trends
  • Use list_memories to view analysis history

Memory MCP (Knowledge Graph)

Temporary Context (in-memory, cleared after session):

  • Use create_entities for components being analyzed
  • Use create_relations to map dependencies and relationships
  • Use add_observations to document findings and metrics

Note: After analysis completes, store summary in Serena memory.

Context7 MCP

  • Use get-library-docs for best practices and quality standards for the tech stack

Output Format

## Analysis Report

### Project: [Name]
**Analyzed**: [Path]
**Date**: [Current date]

### Summary
- **Total Files**: [count]
- **Languages**: [from CLAUDE.md]
- **Lines of Code**: [estimate]

### Quality Metrics
- **Code Complexity**: [High/Medium/Low]
- **Test Coverage**: [percentage if available]
- **Documentation**: [Good/Fair/Poor]

### Key Findings

#### 🔴 Critical Issues
1. [Issue with location and fix]

#### 🟡 Warnings
1. [Warning with recommendation]

#### 💡 Suggestions
1. [Improvement idea]

### Dependencies
- **Total Dependencies**: [count]
- **Outdated**: [list if any]
- **Vulnerabilities**: [list if any]

### Code Complexity
**Most Complex Files**:
1. [file]: [complexity score]
2. [file]: [complexity score]

### Recommendations
1. [Priority action 1]
2. [Priority action 2]
3. [Priority action 3]

### Next Steps
- [ ] Address critical issues
- [ ] Update dependencies
- [ ] Improve test coverage
- [ ] Refactor complex code

### Lessons Learned 📚

**Document key insights from this analysis:**
- What patterns or anti-patterns were most prevalent?
- What areas of technical debt need attention?
- What quality metrics should be tracked going forward?
- What process improvements could prevent similar issues?

**Save to Serena Memory?**

After completing the analysis, ask the user:

> "I've identified several lessons learned from this code analysis. Would you like me to save these insights to Serena memory for future reference? This will help track technical debt and maintain code quality over time."

If user agrees, use Serena MCP `write_memory` to store:
- `"analysis-[category]-[date]"` (e.g., "analysis-code-complexity-2025-10-20")
- `"lesson-analysis-[topic]-[date]"` (e.g., "lesson-analysis-dependency-management-2025-10-20")
- Include: What was analyzed, findings, trends, recommendations, and action items

Guidelines

  • Always provide actionable recommendations
  • Prioritize findings by impact and effort
  • Reference CLAUDE.md standards throughout
  • Use MCP servers for deep analysis
  • Compare current analysis with past analyses from Serena memory to track trends