code-analysis
Analyze code quality, detect code smells, identify bugs, and provide improvement recommendations. Use when reviewing code, checking quality, analyzing complexity, or when user mentions code review, refactoring suggestions, or quality assessment.
Best use case
code-analysis is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Analyze code quality, detect code smells, identify bugs, and provide improvement recommendations. Use when reviewing code, checking quality, analyzing complexity, or when user mentions code review, refactoring suggestions, or quality assessment.
Teams using code-analysis should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/code-analysis/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How code-analysis Compares
| Feature / Agent | code-analysis | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Analyze code quality, detect code smells, identify bugs, and provide improvement recommendations. Use when reviewing code, checking quality, analyzing complexity, or when user mentions code review, refactoring suggestions, or quality assessment.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Code Analysis
A comprehensive code analysis skill that helps evaluate code quality, identify potential issues, and provide actionable recommendations for improvement.
## Quick Start
Basic code analysis workflow:
```python
# Read the code file
with open("target_file.py", "r") as f:
code = f.read()
# Run an LLM code review following code-review-instructions/copilot-instructions.md
# Summarize findings by severity with clear, actionable recommendations
```
## LLM Code Review Mode (Preferred)
Use the LLM (no scripts) to perform reviews guided by [`code-review-instructions/copilot-instructions.md`](code-review-instructions/copilot-instructions.md):
- Keep the instructions open; follow the severity model (Blocking, Important, Suggestions) and priority order (Security → Reliability → Performance/Cost → Testing → Observability → Readability).
- Make the review scope explicit (files/diff) and skip excluded assets like generated/vendor/lock files unless instructed otherwise.
- Pull the relevant stack rules and checklists referenced in the instructions; cite them when flagging issues.
- Report findings first with file:line, impact, and the specific fix or test to add before closing with positives.
## Review Checklists and Stack Rules
- **Start with general review lists**: `docs/review/code-conventions.md`, `docs/review/readability-checklist.md`, `docs/review/reliability-checklist.md`, `docs/review/security-checklist.md`, `docs/review/performance-checklist.md`, `docs/review/testing-checklist.md`.
- **Apply stack-specific rules**: `docs/stack-rules/react-typescript-rules.md`, `docs/stack-rules/angular-rules.md`, `docs/stack-rules/python-rules.md`, `docs/stack-rules/java-rules.md`, `docs/stack-rules/java-kotlin-rules.md`, `docs/stack-rules/scala-rules.md`, `docs/stack-rules/go-rules.md`.
- **Report with references**: Link findings to the checklist/rule anchor that was violated for fast remediation.
## Core Capabilities
### 1. Code Quality Assessment
Evaluate overall code quality across multiple dimensions:
- **Readability**: Variable naming, function clarity, code organization
- **Maintainability**: Code complexity, coupling, cohesion
- **Performance**: Potential bottlenecks, inefficient patterns
- **Security**: Common vulnerabilities, input validation
- **Best Practices**: Language-specific conventions and idioms
### 2. Code Smell Detection
Identify common code smells:
- **Long Method**: Functions exceeding reasonable length
- **Large Class**: Classes with too many responsibilities
- **Duplicate Code**: Similar code patterns across files
- **Dead Code**: Unused variables, functions, imports
- **Magic Numbers**: Hardcoded values without explanation
- **Deep Nesting**: Excessive indentation levels
- **God Object**: Classes doing too much
### 3. Complexity Metrics
Calculate and interpret:
- **Cyclomatic Complexity**: Number of independent paths
- **Cognitive Complexity**: How difficult code is to understand
- **Lines of Code**: Total, comment, and blank lines
- **Function/Method Count**: Per class or module
- **Dependency Analysis**: Import structure and coupling
### 4. Language-Specific Analysis
#### React + TypeScript
- Reference: `docs/stack-rules/react-typescript-rules.md`
- Component patterns (functional vs class)
- Hooks usage and custom hooks
- Props validation and typing
- State management patterns
- Performance optimization (memo, useMemo, useCallback)
- Key prop usage in lists
- Event handling best practices
- Accessibility (a11y) compliance
#### Angular + TypeScript
- Reference: `docs/stack-rules/angular-rules.md`
- Component lifecycle hooks
- RxJS observable patterns
- Dependency injection
- Change detection strategies
- Template syntax and bindings
- Service architecture
- Module organization
- TypeScript strict mode compliance
#### Python
- Reference: `docs/stack-rules/python-rules.md`
- PEP 8 compliance
- Type hints usage (Python 3.8+)
- Async/await patterns
- Exception handling patterns
- List/dict comprehensions
- Generator vs list usage
- FastAPI/Django best practices
- Pydantic model validation
#### Java + Spring Boot
- Reference: `docs/stack-rules/java-rules.md`
- SOLID principles adherence
- Design pattern opportunities
- Spring annotations usage
- JPA/Hibernate patterns
- Exception handling (@ControllerAdvice)
- Bean validation
- Lombok usage
- Transaction management
- REST API design
#### Kotlin
- Reference: `docs/stack-rules/java-kotlin-rules.md`
- Idiomatic Kotlin patterns
- Coroutines and Flow
- Null safety
- Data classes and sealed classes
- Extension functions
- Scope functions (let, run, with, apply, also)
- Companion objects
- Destructuring declarations
#### Scala
- Reference: `docs/stack-rules/scala-rules.md`
- Option/Either/Try usage instead of null
- Immutability and collection best practices
- Pattern matching exhaustiveness and for-comprehensions
- Concurrency with Future/IO and resource safety
- Controlled use of implicits/givens and type classes
#### Go
- Reference: `docs/stack-rules/go-rules.md`
- Explicit error handling and wrapping with context
- Context propagation and cancellation
- Concurrency correctness with goroutines/channels
- Interface-oriented design and zero-value-safe structs
- Database/HTTP patterns with proper resource management
## Workflows
### Workflow 0: LLM Code Review (Copilot Instructions)
1. **Open the instructions**: Keep [`code-review-instructions/copilot-instructions.md`](code-review-instructions/copilot-instructions.md) in view.
2. **Identify scope**: List files/diffs included; skip excluded files noted in the instructions.
3. **Assess critical paths first**: Security → reliability → performance/cost → tests → observability → readability/UX.
4. **Apply stack rules**: Pull the relevant concise or full stack rule docs referenced by the instructions.
5. **Report findings**: Start with blocking/important issues, cite file:line, describe impact, and propose the fix.
6. **Close with next steps**: Tests to add/run and any follow-ups required to de-risk.
### Workflow 1: Comprehensive File Analysis
1. **Read the target file**
2. **Parse code structure**: Functions, classes, imports
3. **Calculate metrics**: Complexity, LOC, depth
4. **Detect issues**: Code smells, anti-patterns
5. **Generate report**: Structured findings with priorities
6. **Provide recommendations**: Specific, actionable improvements
### Workflow 2: Multi-File Project Analysis
1. **Scan project structure**
2. **Identify dependencies**
3. **Analyze each file**: Apply single-file workflow
4. **Cross-reference issues**: Duplicate code, circular dependencies
5. **Aggregate findings**: Project-wide statistics
6. **Prioritize improvements**: Impact vs effort matrix
### Workflow 3: Focused Issue Investigation
1. **Receive specific concern**: Performance, security, readability
2. **Deep dive analysis**: Targeted inspection
3. **Identify root causes**
4. **Suggest solutions**: Multiple options with trade-offs
5. **Provide examples**: Before/after code snippets
## Analysis Output Format
Structure your analysis as follows:
```markdown
## Code Analysis Report
### Summary
- File: [filename]
- Language: [language]
- Lines of Code: [total]
- Overall Quality: [High/Medium/Low]
### Metrics
- Cyclomatic Complexity: [average] (functions: [list high-complexity ones])
- Maintainability Index: [score]
- Code Smells Detected: [count]
### Critical Issues (Priority: High)
1. [Issue description]
- Location: Line [X]
- Impact: [explanation]
- Recommendation: [specific fix]
### Moderate Issues (Priority: Medium)
[Similar structure]
### Minor Improvements (Priority: Low)
[Similar structure]
### Positive Aspects
- [What's done well]
- [Good patterns observed]
### Actionable Recommendations
1. [Priority 1 action]
2. [Priority 2 action]
3. [Priority 3 action]
```
## Best Practices for Analysis
1. **Be Specific**: Point to exact line numbers and code sections
2. **Provide Context**: Explain why something is an issue
3. **Offer Solutions**: Don't just identify problems, suggest fixes
4. **Show Examples**: Include code snippets when helpful
5. **Consider Trade-offs**: Acknowledge when recommendations have costs
6. **Prioritize**: Not all issues are equal importance
7. **Be Constructive**: Focus on improvement, not criticism
## Common Patterns to Check
### Anti-Patterns
```python
# Anti-pattern: God Object
class UserManager:
def authenticate(self): pass
def send_email(self): pass
def generate_report(self): pass
def process_payment(self): pass
# Too many responsibilities!
# Better: Single Responsibility
class Authenticator:
def authenticate(self): pass
class EmailService:
def send_email(self): pass
```
### Performance Issues
```python
# Inefficient: Multiple iterations
data = [process(x) for x in items]
filtered = [x for x in data if x > 0]
result = [transform(x) for x in filtered]
# Efficient: Single pass
result = [transform(process(x)) for x in items if process(x) > 0]
```
### Security Concerns
```python
# Vulnerable: SQL Injection
query = f"SELECT * FROM users WHERE id = {user_id}"
# Safe: Parameterized query
query = "SELECT * FROM users WHERE id = ?"
cursor.execute(query, (user_id,))
```
## Integration with Other Tools
This skill can reference:
- **Linting tools**: pylint, eslint, golangci-lint
- **Testing**: pytest, jest, JUnit results
- **Coverage**: Code coverage reports
- **Profiling**: Performance profiler output
For detailed language-specific guidelines, see [LANGUAGE_GUIDES.md](LANGUAGE_GUIDES.md).
- Prefer LLM-driven review; do not call scripts like `scripts/analyze.py` unless explicitly requested.
## Limitations
- Cannot execute code for dynamic analysis
- Limited to static code analysis
- May miss runtime-only issues
- Context-dependent recommendations require human judgment
## When to Use This Skill
Use this skill when:
- Reviewing pull requests
- Auditing legacy code
- Planning refactoring efforts
- Conducting code quality assessments
- Training team members on best practices
- Investigating specific code issues
- Preparing for production deployment
## Examples
See [EXAMPLES.md](EXAMPLES.md) for detailed analysis examples across different languages and scenarios.
See [EXAMPLES_STACK.md](EXAMPLES_STACK.md) for comprehensive examples with React, TypeScript, Angular, Python, Java, and Kotlin.Related Skills
binary-analysis-patterns
Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing...
Binary Analysis and Reverse Engineering
Systematic approach to analyzing compiled binaries, understanding program behavior, and identifying vulnerabilities without source code access
ast-grep-code-analysis
Use when analyzing complex codebases for security vulnerabilities, performance issues, and structural patterns - provides systematic AST-based approach using ast-grep for comprehensive code understanding beyond manual inspection
argument-analysis
Analyze argument structure, identify logical gaps, suggest evidence needs, generate counterarguments, apply claim-evidence-warrant framework. Use when strengthening arguments, analyzing persuasive writing, checking logical validity, or when user asks to improve reasoning or logic.
architectural-analysis
Deep architectural audit focused on finding dead code, duplicated functionality, architectural anti-patterns, type confusion, and code smells. Use when user asks for architectural analysis, find dead code, identify duplication, or assess codebase health.
arch-analysis
Analyze LangGraph application architecture, identify bottlenecks, and propose multiple improvement strategies
aqwa-analysis
Integrate with AQWA hydrodynamic software for RAO computation, damping analysis, and coefficient extraction. Use for AQWA file processing, RAO calculation, hydrodynamic coefficient extraction, and pre/post processing workflows.
analysis-swarm
Multi-persona analytical framework for comprehensive code review and decision-making
analysis-diagnose
Perform systematic root cause investigation. Use when you encounter bugs, test failures, or unexpected behavior. Not for trivial or obvious fixes, creative experimentation, or learning new systems.
Advanced RE Analysis
Specialized reverse engineering analysis workflows for binary analysis, pattern recognition, and vulnerability assessment
abaqus-static-analysis
Complete workflow for static structural analysis. Use when analyzing stress, displacement, or reaction forces under constant loads. For strength and stiffness evaluation.
abaqus-coupled-analysis
Complete workflow for coupled thermomechanical analysis. Use when user mentions thermal stress, thermal expansion, or temperature causing deformation.