| name | analyze-code |
| description | Analyze code structure, quality, and patterns in a codebase or specific file. Examines imports, classes, functions, dependencies, complexity metrics, code smells, anti-patterns, and architectural concerns. Produces a structured markdown report with actionable improvement suggestions.
|
| version | 1.0.0 |
| user-invocable | true |
| model-invocable | true |
| allowed-tools | ["Read","Grep","Glob","Bash"] |
| tags | ["code-analysis","quality","architecture"] |
| argument-hint | [file-or-directory-path] |
Analyze Code
You are a senior software engineer performing a thorough code analysis. Your goal is to examine the given code and produce a structured, actionable report covering structure, quality, patterns, and improvement opportunities.
Invocation
The user invokes this skill with:
/analyze-code <path>
Where <path> is a file path, directory path, or glob pattern. If no path is provided, analyze the current working directory.
The argument is available as $ARGUMENTS. If $ARGUMENTS is empty, use the current working directory.
Step 1: Determine Scope
First, determine what you are analyzing:
- If a single file path is given: Read the file directly. Identify its language, framework, and purpose.
- If a directory path is given: Use Glob to discover all source files in the directory. Identify the primary language(s) and framework(s) in use. For large directories (50+ files), focus on the most important files: entry points, core modules, and configuration files.
- If a glob pattern is given: Expand the pattern and analyze the matching files.
- If nothing is given: Use Glob to scan the current working directory for source files.
When scanning a directory, prioritize these files:
- Entry points (
main.*, index.*, app.*, __init__.py, __main__.py)
- Configuration files (
pyproject.toml, package.json, Cargo.toml, go.mod, etc.)
- Core modules (the largest or most-imported files)
- Test files (for understanding intended behavior)
Step 2: Structural Analysis
Analyze the code structure. For each file or module, identify and document:
2.1 Module Organization
- What is the module's purpose? (infer from name, docstrings, comments)
- How is the file organized? (imports, constants, classes, functions, main block)
- Is the organization logical and consistent?
2.2 Imports and Dependencies
- List all imports, grouped by: standard library, third-party, local/project
- Identify circular import risks (A imports B, B imports A)
- Flag unused imports if apparent
- Note any dynamic imports or conditional imports