| name | project-index |
| description | Generate and maintain project structure index for fast AI navigation. Creates docs/structure.md with optimized file index. Load this skill when starting new project, after major changes, or when docs/structure.md is outdated. |
Project Index Skill
Generate optimized project structure file for fast AI context loading.
When to Use
- First time: Project has no
docs/structure.md - After changes: Added/removed files, restructured folders
- Periodic refresh: Weekly or after major features
- On demand: User says "update structure", "refresh index", "scan project"
Output File
Location: docs/structure.md
Purpose: Single source of truth for AI to understand project layout without scanning entire codebase.
Cross-Platform Scripts (Recommended)
This skill includes pre-built scripts that work on all platforms:
Node.js Script
# Basic usage (from project root)
node .claude/skills/project-index/scripts/scan-structure.js . 4
# Output to file
node .claude/skills/project-index/scripts/scan-structure.js . 4 > docs/structure.md
# JSON format
node .claude/skills/project-index/scripts/scan-structure.js . 4 json
Python Script
# Basic usage
python .claude/skills/project-index/scripts/scan_structure.py . 4
# Output to file
python .claude/skills/project-index/scripts/scan_structure.py . 4 > docs/structure.md
# JSON format
python .claude/skills/project-index/scripts/scan_structure.py . 4 json
Script Features
- ✅ Cross-platform (Windows, macOS, Linux)
- ✅ Auto-detect entry points (main., index., app., server.)
- ✅ Auto-detect config files (package.json, tsconfig.*, etc.)
- ✅ Auto-detect key files (README, CHANGELOG, LICENSE)
- ✅ File distribution by language/type
- ✅ Customizable depth and ignore patterns
- ✅ Output: Markdown or JSON
Generation Workflow
Step 1: Scan Project (Alternative Methods)
Option A: Use Built-in Scripts (Recommended)
# Node.js
node .claude/skills/project-index/scripts/scan-structure.js . 4
# Python
python .claude/skills/project-index/scripts/scan_structure.py . 4
Option B: VS Code Tools
# Use list_dir tool recursively
# Use file_search tool with glob patterns
Option C: Native Commands (Platform-specific)
# Linux/macOS
tree -L 4 -I 'node_modules|.git|dist|build' --dirsfirst
# Windows PowerShell
Get-ChildItem -Recurse -Depth 4 | Where-Object { $_.FullName -notmatch 'node_modules|\.git|dist|build' }
# Windows CMD (limited)
dir /s /b /ad
Step 2: Identify Key Files
Scan for these important files:
- Entry points:
main.*,index.*,app.*,server.* - Config:
*.config.*,*.json,*.yaml,*.toml,.env* - Docs:
README*,CHANGELOG*,docs/* - Routes/API:
**/routes/**,**/api/**,**/controllers/** - Components:
**/components/**,**/views/**,**/pages/** - Services:
**/services/**,**/lib/**,**/utils/** - Database:
**/models/**,**/schema/**,**/migrations/** - Tests:
**/*.test.*,**/*.spec.*,**/tests/**
Step 3: Generate Structure File
Create docs/structure.md with this format:
# Project Structure Index
> Auto-generated by project-index skill. Last updated: YYYY-MM-DD HH:mm
## Quick Stats
- Total files: X
- Main language: TypeScript/Python/etc
- Framework: Next.js/Angular/Express/etc
- Package manager: npm/yarn/pnpm
## Directory Tree
\`\`\`
<tree output here>
\`\`\`
## Key Entry Points
| File | Purpose |
|:---|:---|
| src/index.ts | Main entry |
| src/app.ts | App initialization |
## Config Files
| File | Purpose |
|:---|:---|
| package.json | Dependencies |
| tsconfig.json | TypeScript config |
## Feature Map
| Feature/Domain | Location | Key Files |
|:---|:---|:---|
| Authentication | src/auth/ | login.ts, session.ts, middleware.ts |
| User Management | src/users/ | user.model.ts, user.service.ts |
| API Routes | src/api/ | routes.ts, handlers/ |
| Database | src/db/ | schema.prisma, migrations/ |
| UI Components | src/components/ | Button.tsx, Modal.tsx, Layout.tsx |
## File Patterns
| Looking for | Path pattern |
|:---|:---|
| Components | src/components/**/*.tsx |
| API handlers | src/api/**/*.ts |
| Database models | src/models/**/*.ts |
| Tests | **/*.test.ts, **/*.spec.ts |
| Styles | src/styles/**/*.css |
## Recent Changes (Optional)
- 2024-01-15: Added payment module at src/payment/
- 2024-01-10: Restructured auth to src/auth/
Step 4: Validate & Save
- Ensure
docs/folder exists - Write to
docs/structure.md - Confirm file created/updated
JSON Alternative (Optional)
If project prefers JSON, create docs/structure.json:
{
"generated": "2024-01-15T10:30:00Z",
"stats": {
"totalFiles": 150,
"language": "TypeScript",
"framework": "Next.js"
},
"entryPoints": [
{"path": "src/index.ts", "purpose": "Main entry"},
{"path": "src/app.ts", "purpose": "App init"}
],
"features": {
"auth": {
"location": "src/auth/",
"files": ["login.ts", "session.ts", "middleware.ts"]
},
"api": {
"location": "src/api/",
"files": ["routes.ts", "handlers/"]
}
},
"patterns": {
"components": "src/components/**/*.tsx",
"api": "src/api/**/*.ts",
"tests": "**/*.test.ts"
}
}
Update Triggers
Structure file should be updated when:
- Manual trigger: User says "update structure"
- New feature: After adding new module/feature folder
- Restructure: After moving/renaming folders
- Weekly maintenance: As part of regular cleanup
- Before major task: Ensure index is fresh before big changes
Integration with AGENTS.md
After generating docs/structure.md, AI should:
- Read structure first before searching for files
- Use Feature Map to locate relevant code areas
- Use File Patterns for glob searches
- Skip full tree scan if structure file exists and is recent
Quick Commands
# Check if structure exists (cross-platform)
test -f docs/structure.md && echo "EXISTS" || echo "NEEDS GENERATION"
# Generate with Node.js script
node .claude/skills/project-index/scripts/scan-structure.js . 4 > docs/structure.md
# Generate with Python script
python .claude/skills/project-index/scripts/scan_structure.py . 4 > docs/structure.md
# Quick check last modified (Linux/macOS)
stat docs/structure.md | grep Modify
# Quick check last modified (PowerShell)
(Get-Item docs/structure.md).LastWriteTime
AI Agent Workflow
When generating structure as AI agent:
Method 1: Use Built-in Script (Fast)
node .claude/skills/project-index/scripts/scan-structure.js . 4 > docs/structure.md
Method 2: Use VS Code Tools (No Script Required)
- Use
list_dirtool to scan root - Use
list_dirrecursively on key folders - Use
file_searchwith patterns like**/*.tsx,**/*.ts - Combine results into structure.md format
Method 3: Hybrid Approach
- Run script for basic tree
- Use
read_fileon package.json to detect framework - Manually add Feature Map based on codebase understanding
Best Practices
- Keep it updated: Stale index is worse than no index
- Feature-focused: Group by business domain, not just folders
- Include purpose: Don't just list files, explain what they do
- Patterns over lists: For large folders, show patterns instead of listing all files
- Version control: Commit structure.md so team shares same understanding
- Use scripts: Prefer built-in scripts over platform-specific commands