| name | codebase-analysis |
| description | TRIGGER when user asks to analyze, document, understand, or review a codebase or code module. Use when user wants to: generate technical docs, trace data flow, analyze algorithms, document data structures, understand architecture, or review code logic. Triggers on: 'analyze code', 'codebase analysis', 'document this code', 'understand this project', 'trace data flow', '็ฎๆณๅๆ', 'ไปฃ็ ๅๆ', 'ไปฃ็ ๆขณ็', 'ๆฐๆฎ็ปๆๅๆ', 'ๆๆฏๆๆกฃ'. DO NOT trigger for: simple file reading, single-function explanation, general coding questions. |
| level | 3 |
| version | 2.1 |
| triggers | ["codebase analysis","analyze codebase","ไปฃ็ ๅๆ","ไปฃ็ ๆขณ็","ๆฐๆฎ็ปๆๅๆ","algorithm flow"] |
| argument-hint | <target_directory_or_module> |
Codebase Analysis Skill
Purpose: Perform rigorous, code-based analysis of software projects to generate comprehensive technical documentation similar to the fastlivo2-tech-docs reference style.
What This Skill Does
This skill systematically analyzes a codebase and produces detailed markdown documentation covering:
- System Overview (็ณป็ปๆฆ่ฟฐ) - Architecture, modules, and relationships
- Data Structures (ๆฐๆฎ็ปๆ่ฏฆ่งฃ) - Detailed breakdown of all key data structures
- Data Flow (ๆฐๆฎๆตๅๆ) - How data moves through the system
- Algorithm Flows (็ฎๆณๆต็จ) - Core algorithms with step-by-step analysis
- Key Functions (ๅ
ณ้ฎๅฝๆฐๅๆ) - Deep dive into critical functions
Key Principle: All analysis is strictly based on actual code - no hallucinations, no assumptions without verification.
When to Use
Invoke this skill when you need to:
- Understand a complex codebase systematically
- Create technical documentation for a project
- Analyze data structures and their relationships
- Trace data flow and algorithms
- Generate codebase reference materials
- Review and document architecture decisions
Output Format
Each analysis module generates a corresponding .md file with:
- Code references with file:line:column citations
- ASCII diagrams for visualization
- Verification checkpoints
- Cross-references between documents
- Consistent structure across all documents
Usage
/codebase-analysis <target_directory>
/codebase-analysis src/core
/codebase-analysis --module=StateEstimator
Methodology (9 Phases for Deep Analysis)
Phase 0: Project Context Detection & Auto-Initialization (้กน็ฎไธไธๆๆฃๆตไธ่ชๅจๅๅงๅ) โญ NEW
Purpose: Ensure CLAUDE.md exists for enhanced context, or auto-generate it
Time: < 1 second (if CLAUDE.md exists) or 1-3 minutes (auto-/init)
Output: Project context metadata + CLAUDE.md (generated if needed)
Steps:
-
Detect CLAUDE.md
if [ -f "CLAUDE.md" ]; then
echo "โ Found CLAUDE.md - reading project context"
else
echo "โน No CLAUDE.md found - auto-generating with /init"
fi
-
Auto-initialization (if CLAUDE.md missing)
echo "๐ Running /init to generate CLAUDE.md..."
echo " This may take 1-3 minutes..."
/init
echo "โ CLAUDE.md generated"
echo "๐ Reloading context with CLAUDE.md..."
echo "โ Context loaded with CLAUDE.md enhancement"
echo ""
echo "Note: /init took ~X minutes. This is a one-time cost."
echo " Future analyses will use existing CLAUDE.md (~2 seconds)."
-
Verify CLAUDE.md loaded
if [ -f "CLAUDE.md" ]; then
echo "โ CLAUDE.md context available for analysis"
else
echo "โ ๏ธ CLAUDE.md not available - using code structure analysis"
fi
-
Detect project type (enhanced with CLAUDE.md)
if grep -q "Project Type" CLAUDE.md 2>/dev/null; then
PROJECT_TYPE=$(grep "Project Type" CLAUDE.md)
elif [ -f "package.xml" ] || [ -f "CMakeLists.txt" ]; then
PROJECT_TYPE="ROS/Catkin"
elif [ -f "Cargo.toml" ]; then
PROJECT_TYPE="Rust"
-
Detect build system
if grep -q "catkin_make" CLAUDE.md 2>/dev/null; then
BUILD_SYSTEM="CMake (Catkin)"
elif [ -f "CMakeLists.txt" ]; then
BUILD_SYSTEM="CMake"
Checkpoint:
Key Principle:
- โ
Auto-ensure CLAUDE.md: Generate if missing for better context
- โ
Transparent: User sees what's happening
- โ
One-time cost: /init runs once, then reused
- โ
Fallback: Works even if /init fails
Behavior Changes:
- Before (v2.0): No CLAUDE.md โ code-only analysis
- After (v2.1): No CLAUDE.md โ auto-/init โ enhanced analysis
User Experience:
$ /codebase-analysis /path/to/fresh/clone
โน No CLAUDE.md found - auto-generating with /init
๐ Running /init to generate CLAUDE.md...
This may take 1-3 minutes...
[init output...]
โ CLAUDE.md generated
๐ Reloading context with CLAUDE.md...
โ Context loaded with CLAUDE.md enhancement
Note: /init took ~2 minutes. This is a one-time cost.
Future analyses will use existing CLAUDE.md (~2 seconds).
โ Phase 0: Context Detection Complete
[Continues to Phase 1...]
See: INIT_GUIDE.md for detailed fresh clone handling
โ ๏ธ MANDATORY PRE-REQUISITE: Read WORKFLOW.md First
CRITICAL: Before starting any analysis, you MUST read WORKFLOW.md which contains the mandatory verification workflow.
Core Rule: All analysis MUST be based on actual code. Every claim MUST have a [VERIFY:] tag. No exceptions.
Workflow: Code Reading โ Draft Generation โ Verification โ Fix Discrepancies โ Final Output
Quality Gates: Cannot proceed to next phase without passing verification checkpoints.
Phase 1: Global Exploration (ๅ
จๅฑๆข็ดข)
- โ ๏ธ MANDATORY: Read actual source files first
- Identify project structure and key modules
- Map dependencies and relationships
- Understand framework and architecture
- โ ๏ธ NEW: Generate complete module inventory
Checkpoint:
Phase 1.5: Analysis Planning (ๅๆ่งๅ) โญ NEW
- โ ๏ธ MANDATORY: Generate explicit Phase 4 plan
- Map Phase 1 modules to Phase 4 documents
- Prioritize by complexity/importance
- Generate PHASE4_PLAN.md
- โ ๏ธ MANDATORY: All Phase 1 items must have Phase 4 coverage
Output: PHASE4_PLAN.md
- Complete list of algorithm documents to generate
- Expected length per document
- Code locations for each
- Mathematical focus areas
- Execution order
Checkpoint:
See: PHASE1_ENHANCED.md for detailed methodology
Phase 2: Data Structure Analysis (ๅ
ณ้ฎๆฐๆฎ็ปๆ่ฏฆ็ปๆขณ็)
- โ ๏ธ MANDATORY: Read struct/class definitions from code
- Enumerate all key data structures
- Document fields, methods, and relationships
- Create structure diagrams with ASCII art
- Cross-reference actual code definitions
Checkpoint: Every structure has [VERIFY: file:line] tag?
Phase 3: Data Flow Analysis (ๆฐๆฎๆตๆขณ็)
- โ ๏ธ MANDATORY: Trace through actual code execution
- Trace data movement through the system
- Identify transformation points
- Document inputs and outputs at each stage
- Validate against actual code execution paths
Checkpoint: All flow steps traceable to code?
Phase 4: Algorithm Deep Dive (็ฎๆณๆทฑๅบฆๅๆ) โญ NEW
- โ ๏ธ MANDATORY: Read algorithm implementation line-by-line
- Mathematical formulations with complete derivations
- Step-by-step execution flow with intermediate states
- Complexity analysis with bottlenecks identified
- Comparison with alternative approaches
- Design rationale for algorithmic choices
- Every formula verified against code
- Generate:
ALGORITHM_XX-[Name].md (1500-3000 lines each)
Checkpoint: Every derivation has code evidence?
Phase 5: Key Function Analysis (ๅ
ณ้ฎๅฝๆฐๅ
้จๆต็จๆขณ็)
- โ ๏ธ MANDATORY: Read function implementation completely
- Deep dive into critical functions
- Internal logic flow with line-by-line analysis
- Dependencies and call graphs
- Verification against implementation
- Performance profiling data
Checkpoint: Each line analysis references actual code?
Phase 6: Q&A Documentation (้ฎ้ข่งฃ็ญๆๆกฃ) โญ NEW
- โ ๏ธ MANDATORY: All answers backed by code evidence
- Answer "Why" questions about design decisions
- Explain "How" questions about implementation
- Provide configuration guidance for different scenarios
- Document common pitfalls and solutions
- Generate:
KEY_QUESTIONS-[Module].md (500-1000 lines each)
Checkpoint: Every answer has [VERIFY:] tag?
Phase 7: Verification and Review (ๅคๆ ธๆ กๅ) โ ๏ธ MANDATORY
See WORKFLOW.md for complete verification protocol
- โ ๏ธ MANDATORY: Automated verification of all [VERIFY:] tags
- โ ๏ธ MANDATORY: Manual code cross-reference checking
- โ ๏ธ MANDATORY: Mathematical formula validation
- โ ๏ธ MANDATORY: Fix all discrepancies before output
- โ ๏ธ MANDATORY: Zero tolerance for hallucinations
- Cross-check all claims against code
- Validate code references
- Ensure no hallucinations
- Mathematical correctness verification
- Peer review checklist
Quality Gate: Cannot generate final output until:
Quality Guarantees
Every analysis document MUST include:
- Code Evidence: Every claim references actual code with
file:line
- Verification Tags:
[VERIFY: relative/path/file:line] on EVERY claim
- Anti-Hallucination: Zero speculation without code evidence
- Consistency: Uniform structure and formatting
- Traceability: Clear line from claim to code evidence
โ ๏ธ MANDATORY REQUIREMENT:
- If you cannot provide a [VERIFY:] tag, DO NOT make the claim
- If you haven't read the code, DO NOT speculate
- If uncertain, DELETE the content entirely
See: WORKFLOW.md for mandatory verification protocol
File System Structure
codebase-analysis-skill/
โโโ SKILL.md # Claude Code native auto-discovery
โโโ skill.md # OMC skill definition (this file)
โโโ WORKFLOW.md # โญ MANDATORY verification workflow (READ FIRST!)
โโโ README.md # Usage guide
โโโ Gotchas.md # Common pitfalls (MOST IMPORTANT)
โโโ CHANGELOG.md # Version history
โโโ CONTRIBUTING.md # Contribution guide
โโโ LICENSE # MIT License
โโโ templates/ # Document generation templates
โ โโโ system_overview.md # Architecture overview
โ โโโ data_structures.md # Data structure breakdown
โ โโโ algorithm_flow.md # โญ Deep algorithm analysis (v2.0)
โ โโโ key_questions.md # โญ Q&A documentation (v2.0)
โโโ verification/ # Verification tools
โ โโโ verify_all_refs.sh # โญ Automated [VERIFY:] tag checker
โ โโโ verify_analysis.sh # Full analysis verification
โ โโโ code_reference_checklist.md # Manual verification checklist
โโโ helpers/ # Helper scripts
โ โโโ ascii_diagrams.sh # ASCII diagram utilities
โ โโโ code_ref_formatter.sh # Code reference formatting
โโโ docs/ # Detailed methodology docs
โ โโโ ANALYSIS_FLOW.md # Progressive refinement explained
โ โโโ INIT_GUIDE.md # CLAUDE.md handling strategy
โ โโโ PHASE1_ENHANCED.md # Phase 1 enhanced methodology
โ โโโ PHASE4_GUIDE.md # Algorithm deep dive guide
โโโ examples/ # Usage examples
โโโ example-output.md # Sample output from Voxel-SLAM
Critical Files (read in this order):
- WORKFLOW.md - Mandatory verification workflow
- Gotchas.md - Common pitfalls to avoid
- skill.md - This file (methodology overview)
Progressive Disclosure
This skill uses file system structure for progressive disclosure (Tip 3 from skill creation guide):
- Core: skill.md loaded first
- Templates: Loaded when analysis begins
- Helpers: Loaded when generating output
- Verification: Loaded during review phase
This prevents overwhelming Claude with all context at once.
Gotchas (Common Pitfalls)
This is the most valuable section - learned from real analysis failures.
See Gotchas.md for detailed coverage of:
- Hallucinating features not in code
- Misinterpreting data structures
- Missing critical code paths
- Incorrect data flow assumptions
- Verification blind spots
Verification Requirements
Every document must pass:
- โ
All claims reference actual code (file:line:column)
- โ
ASCII diagrams match code structure
- โ
Data flows validated by execution tracing
- โ
No speculative statements without evidence
- โ
Cross-references resolve correctly
- โ
Verification checkpoints completed
Example Output Style
Reference: fastlivo2-tech-docs (reference repo)
Key characteristics:
- Bilingual (Chinese + English) where appropriate
- Multi-layer structure (Concept โ Structure โ Operation โ Integration โ Summary)
- Extensive ASCII diagrams
- Actual code snippets with line numbers
- Step-by-step algorithm breakdowns
- Verification checklists at end of each section
Next Steps: When this skill is invoked:
- FIRST: Read
WORKFLOW.md (mandatory verification protocol)
- SECOND: Read
Gotchas.md (common pitfalls)
- THEN: Begin with Phase 1 and proceed systematically
- ALWAYS: Verify all claims against code before proceeding to next phase
- FINALLY: Pass all quality gates before generating output
Non-negotiable: Zero tolerance for unverified claims or hallucinations.