Skip to content
Development
Skill

/codebase-index

3-layer codebase indexing system for token-efficient code navigation. Builds compact index + symbol map so agents read targeted lines instead of entire files. Achieves ~5-10x token savings.

From plugin
codecrew
1312 skills11 agents10 commands1 hook

Claude Code

$ npx -y skills add d3x293/code-crew --skill codebase-index --agent claude-code

SKILL.md

codebase-index.SKILL.md
name: codebase-index
description: 3-layer codebase indexing system for token-efficient code navigation. Builds compact index + symbol map so agents read targeted lines instead of entire files. Achieves ~5-10x token savings.

Codebase Index - 3-Layer Memory Optimizer

Build and maintain a progressive disclosure index that prevents agents from reading entire files when they only need a function signature or a specific line range.

When to Activate

  • During `/crew init` (full build)
  • During `/crew reindex` (full rebuild)
  • When an agent needs to find code but the index exists (consult mode)
  • After file edits (incremental update mode via index-updater skill)

Three-Layer Architecture

Layer 1 - Compact Index (`.claude/crew-index.json`, ~2-5KB)

The cheapest layer. Costs ~50 tokens to read. Contains just enough to route queries to the right file:

**Per-file entry:**

  • `hash`: SHA-256 of file content (for change detection)
  • `size`: file size in bytes
  • `type`: language (javascript, python, typescript, etc.)
  • `exports`: exported functions/classes/constants
  • `imports`: external dependencies
  • `functions`: all function/method names
  • `classes`: all class names
  • `lines`: total line count
  • `category`: core | test | config | docs | util
  • `summary`: 1-line description of what this file does

**Global metadata:**

  • `version`: schema version
  • `generated`: ISO timestamp
  • `contentHash`: hash of all file hashes combined
  • `dependencies`: package dependencies with versions
  • `architecture.entryPoint`: main entry file
  • `architecture.pipeline`: data flow description
  • `architecture.patterns`: detected patterns (MVC, pipeline, event-driven, etc.)
  • `stats`: totalFiles, totalLines, languages, lastIndexed

Layer 2 - Symbol Map (`.claude/crew-symbols.json`, ~5-15KB)

Mid-detail layer. Costs ~100-200 tokens for relevant section. Contains function signatures and relationships:

**Per-symbol entry** (keyed as `filepath::symbolName`):

  • `type`: function | class | method | constant | type
  • `signature`: full signature string
  • `params`: parameter list with types if available
  • `returns`: return type if available
  • `calls`: what this symbol calls
  • `calledBy`: what calls this symbol
  • `lineRange`: [startLine, endLine]
  • `description`: 1-line description

**Relationship maps:**

  • `callGraph`: which functions call which
  • `fileRelationships`: import/export connections between files

Layer 3 - Full Details (on-demand file reads)

Agents read actual file contents ONLY after consulting Layer 1+2 to know exactly which file and line range they need. Use the Read tool with `offset` and `limit` parameters to read specific line ranges.

Building the Index (Full Build)

When triggered for full build:

Step 1: Discover source files

Use Glob to find all source files:
- **/*.{js,ts,jsx,tsx,py,go,rs,java,kt,rb,php,c,cpp,h,cs}
- Exclude: node_modules, .git, dist, build, __pycache__, .next, vendor
- Also find: package.json, requirements.txt, go.mod, Cargo.toml, pyproject.toml

Step 2: Read each file and extract metadata

For each source file: 1. Read the file content 2. Compute SHA-256 hash (use `shasum -a 256` via Bash) 3. Extract exports (look for `module.exports`, `export`, `def`, `func`, `fn`, `public`) 4. Extract imports (look for `require`, `import`, `from`, `use`) 5. Extract function names and signatures with line ranges 6. Extract class names 7. Count lines 8. Categorize: core (src/), test (test/), config (root configs), docs, util (lib/, utils/) 9. Generate 1-line summary

Step 3: Build call graph

From the imports/exports and function calls data: 1. Map which files import from which 2. Map which functions call which (by scanning function bodies for calls to known symbols) 3. Identify entry points (files not imported by anything)

Step 4: Write index files

1. Write `.claude/crew-index.json` (Layer 1) 2. Write `.claude/crew-symbols.json` (Layer 2) 3. Report stats: files indexed, total lines, languages detected

Incremental Update

When a single file changes: 1. Recompute its hash 2. Compare with stored hash in crew-index.json 3. If different: re-read the file, update its Layer 1 + Layer 2 entries 4. Update the global contentHash 5. Do NOT rebuild entries for unchanged files

How Agents Should Use the Index

INDEX-FIRST PROTOCOL (mandatory):

Before reading ANY source file:
1. Read .claude/crew-index.json → find which file(s) are relevant
   - Match by: function names, exports, summary keywords, category
2. Read .claude/crew-symbols.json → find exact symbol and line range
   - Match by: symbol name, signature, calledBy/calls relationships
3. Read ONLY the specific line range you need from the actual file
   - Use: Read tool with offset=startLine and limit=(endLine-startLine+1)

NEVER:
- Read an entire file when you only need one function
- Grep the whole codebase when the index has the answer
- Skip the index because "it's faster to just read the file"

ALWAYS:
- Consult Layer 1 first (cheapest)
- Consult Layer 2 only if Layer 1 isn't specific enough
- Read Layer 3 (actual file) only for the exact lines you need
- After making changes, note which files were modified for index update

Token Savings

| Approach | Tokens Used | When | |----------|-------------|------| | Read all files | ~2000-10000+ | Without index | | Layer 1 only | ~50-100 | Finding which file has a feature | | Layer 1 + Layer 2 | ~150-300 | Finding a specific function | | Layer 1 + 2 + targeted read | ~300-500 | Reading + editing a function | | **Savings** | **5-10x** | Per agent interaction |

Edge Cases

  • **New file not in index**: If an agent creates a new file, add it to the index immediately
  • **Deleted file still in index**: On reindex, remove entries for files that no longer exist
  • **Binary/large files**: Skip files > 100KB or binary files (images, compiled assets)
  • **Generated files**: Skip dist/, build/, .next/ directories
  • **Config files**: Index but categorize a
Read more
@d3x293
Ships withcodecrew

A virtual dev crew for Claude Code — 11 specialized AI agents that decompose, implement, review, and ship your tasks. Instead of one AI doing everything, CodeCrew breaks work into subtasks and routes each to the right specialist on the right model.

1312 skills11 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
13
Star history of d3x293/code-crew on GitHub, a chart by star-history.com

Other skills on codecrew.

agent-manager

agent-manager

Creates, lists, and removes custom project-specific agents. Custom agents are stored in .claude/crew-agents/ and registered in…

@d3x293@d3x293Install Skill
crew-config

crew-config

Manages CodeCrew configuration. Allows users to customize default mode, model tiers, agent activation, token budgets, and…

@d3x293@d3x293Install Skill
crew-init

crew-init

Analyzes a project codebase, builds 3-layer index, generates project profile, and auto-configures the agent team with relevant…

@d3x293@d3x293Install Skill
execution-orchestrator

execution-orchestrator

Smart hybrid execution engine that dispatches agents in parallel or sequential order based on task dependencies. Manages the…

@d3x293@d3x293Install Skill
index-updater

index-updater

Keeps the 3-layer codebase index fresh after file edits. Performs incremental updates by recomputing hashes and re-extracting…

@d3x293@d3x293Install Skill
lite-router

lite-router

Lite task router that bypasses Opus CEO entirely. Classifies tasks and routes directly to Sonnet and Haiku agents only. Use when…

@d3x293@d3x293Install Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills2w309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react5d252k
@facebook@facebookInstall Skill

Questions about codebase-index.

Which coding agents can use codebase-index?
codebase-index installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.