mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
6.1 KiB
6.1 KiB
name, description, argument-hint, allowed-tools
| name | description | argument-hint | allowed-tools |
|---|---|---|---|
| code-analysis | Deep code analysis and debugging using CLI tools with specialized template | [--agent] [--tool codex|gemini|qwen] [--enhance] [--cd path] analysis target | SlashCommand(*), Bash(*), Task(*) |
CLI Mode: Code Analysis (/cli:mode:code-analysis)
Purpose
Systematic code analysis with execution path tracing template (~/.claude/prompt-templates/code-analysis.md).
Supported Tools: codex, gemini (default), qwen
Key Feature: --cd flag for directory-scoped analysis
Parameters
--agent- Use cli-execution-agent for automated context discovery (5-phase intelligent mode)--tool <codex|gemini|qwen>- Tool selection (default: gemini, ignored in agent mode)--enhance- Enhance analysis target with/enhance-promptfirst--cd "path"- Target directory for focused analysis<analysis-target>(Required) - Code analysis target or question
Execution Flow
Standard Mode (Default)
- Parse tool selection: Extract
--toolflag (default: gemini) - If
--enhanceflag present: Execute/enhance-prompt "[analysis-target]"first - Parse analysis target (original or enhanced)
- Detect target directory (from
--cdor auto-infer) - Build command for selected tool with code-analysis template
- Execute deep analysis (read-only, no code modification)
- Save to
.workflow/WFS-[id]/.chat/code-analysis-[timestamp].md
Agent Mode (--agent flag)
Delegate code analysis to cli-execution-agent for intelligent execution path tracing with automated context discovery.
Agent invocation:
Task(
subagent_type="cli-execution-agent",
description="Analyze code execution paths with automated context discovery",
prompt=`
Task: ${analysis_target}
Mode: code-analysis (execution tracing)
Tool Preference: ${tool_flag || 'auto-select'}
${cd_flag ? `Directory Scope: ${cd_path}` : ''}
Template: code-analysis
Agent will autonomously:
- Discover execution paths and call flows
- Build analysis prompt with code-analysis template
- Execute deep tracing analysis
- Generate call diagrams and save log
`
)
The agent handles all phases internally.
Core Rules
- Analysis Only: This command analyzes code and provides insights - it does NOT modify code
- Tool Selection: Use
--toolvalue or default to gemini - Enhance First (if flagged): Execute
/enhance-promptbefore analysis - Directory Context: Use
cdwhen--cdprovided or auto-detected - Template Required: Always use code-analysis template
- Session Output: Save analysis results to session chat
Analysis Capabilities (via Template)
- Systematic Code Analysis: Break down complex code into manageable parts
- Execution Path Tracing: Track variable states and call stacks
- Control & Data Flow: Understand code logic and data transformations
- Call Flow Visualization: Diagram function calling sequences
- Logical Reasoning: Explain "why" behind code behavior
- Debugging Insights: Identify potential bugs or inefficiencies
Command Template
cd [directory] && gemini -p "
PURPOSE: [analysis goal]
TASK: Systematic code analysis and execution path tracing
MODE: analysis
CONTEXT: @CLAUDE.md @**/*CLAUDE.md [entire codebase in directory]
EXPECTED: Execution trace, call flow diagram, debugging insights
RULES: $(cat ~/.claude/prompt-templates/code-analysis.md) | Focus on [aspect]
"
Examples
Basic Code Analysis (Standard Mode):
/cli:mode:code-analysis "trace authentication execution flow"
# Executes: Gemini with code-analysis template
# Returns: Execution trace, call diagram, debugging insights
Intelligent Code Analysis (Agent Mode):
/cli:mode:code-analysis --agent "trace JWT token validation from request to database"
# Phase 1: Classifies as deep analysis, keywords ['jwt', 'token', 'validation', 'database']
# Phase 2: MCP discovers request handler → middleware → service → repository chain
# Phase 3: Builds analysis prompt with code-analysis template + complete call path
# Phase 4: Executes Gemini with traced execution paths
# Phase 5: Saves detailed analysis with call flow diagrams and variable states
# Returns: Complete execution trace + call diagram + data flow analysis
Standard Template Example:
cd . && gemini -p "
PURPOSE: Trace authentication execution flow
TASK: Analyze complete auth flow from request to response
MODE: analysis
CONTEXT: @CLAUDE.md @**/*CLAUDE.md
EXPECTED: Step-by-step execution trace with call diagram, variable states
RULES: $(cat ~/.claude/prompt-templates/code-analysis.md) | Focus on control flow
"
Directory-Specific Analysis:
cd src/auth && gemini -p "
PURPOSE: Understand JWT token validation logic
TASK: Trace JWT validation from middleware to service layer
MODE: analysis
CONTEXT: @CLAUDE.md @**/*CLAUDE.md
EXPECTED: Validation flow diagram, token lifecycle analysis
RULES: $(cat ~/.claude/prompt-templates/code-analysis.md) | Focus on security
"
Code Tracing Workflow
# 1. Find entry points and related files
rg "function.*authenticate|class.*AuthService" --files-with-matches
rg "authenticate|login" -g "*.ts"
# 2. Build call graph understanding
# entry → middleware → service → repository
# 3. Execute deep analysis (analysis only, no code changes)
/cli:mode:code-analysis --cd "src" "trace execution from entry point"
Output Routing
Output Destination Logic:
- Active session exists AND analysis is session-relevant:
- Save to
.workflow/WFS-[id]/.chat/code-analysis-[timestamp].md
- Save to
- No active session OR standalone analysis:
- Save to
.workflow/.scratchpad/code-analysis-[description]-[timestamp].md
- Save to
Examples:
- During active session
WFS-auth-refactor, analyzing auth flow →.chat/code-analysis-20250105-143022.md - No session, tracing request lifecycle →
.scratchpad/code-analysis-request-flow-20250105-143045.md
Notes
- Command templates and file patterns: see intelligent-tools-strategy.md (loaded in memory)
- Template path:
~/.claude/prompt-templates/code-analysis.md - Uses
@**/*for in CONTEXT field for comprehensive code context