Back to Commands

/code_analysis

🧪Code & Analysis & Testing

Perform comprehensive code analysis with quality metrics and recommendations

Arguments: [file-or-directory-path]
Allowed Tools: Read, Grep, Glob, TodoWrite

Quick Actions

Installation

Option A: Install as User Command (available in all projects)

macOS/Linux:

cp code_analysis.md ~/.claude/commands/

Windows:

copy code_analysis.md %USERPROFILE%\.claude\commands\

Option B: Install as Project Command (current project only)

macOS/Linux:

mkdir -p .claude/commands && cp code_analysis.md .claude/commands/

Windows:

mkdir .claude\commands 2>nul && copy code_analysis.md .claude\commands\

Note: After installation, restart Claude Code to load the new command.

Usage

Slash command:

/code_analysis [file-or-directory-path]

Command Instructions


Perform a comprehensive code analysis on the specified files or directory. If no path is provided, analyze the current working directory.


Analysis Process:


  • **Parse Arguments**:
  • - Extract the path from $ARGUMENTS (defaults to current directory if not specified)

    - Determine scope: single file, multiple files, or entire directory


  • **Language Detection**:
  • - Identify programming language(s) based on file extensions

    - Apply language-specific analysis rules


  • **Code Quality Analysis**:
  • - **Complexity Metrics**: Cyclomatic complexity, nesting depth, function length

    - **Code Smells**: Long methods, large classes, duplicate code patterns

    - **Best Practices**: Naming conventions, code organization, documentation

    - **Security Issues**: Common vulnerabilities, unsafe patterns, input validation

    - **Performance**: Inefficient algorithms, memory leaks, blocking operations

    - **Maintainability**: Code coupling, cohesion, test coverage indicators


  • **Generate Report**:
  • - Summary with overall health score

    - Detailed findings by category

    - Priority-ranked issues (High/Medium/Low)

    - Specific file and line references

    - Actionable recommendations for improvement


  • **Track with TodoWrite**:
  • - Create todos for high-priority issues found

    - Organize by fix complexity and impact


    Example Usage:

  • `/code_analysis` - Analyze entire current directory
  • `/code_analysis src/` - Analyze all code in src directory
  • `/code_analysis app.js` - Analyze specific file
  • `/code_analysis "src/**/*.py"` - Analyze all Python files in src

  • Target path: $ARGUMENTS