Files
SuperCharged-Claude-Code-Up…/hooks/codebase-indexer-hook.sh
Claude 809d129197 Implement Chippery codebase-indexer scripts
Adds complete implementation of the Chippery framework integration for semantic codebase navigation:

- build-index.sh: Scan and build semantic index from codebase
- search.sh: Natural language code search with relevance scoring
- update-index.sh: Incremental index updates (git-aware)
- concept-map.sh: Show concept relationships and file mappings
- stats.sh: Display index statistics and token savings
- codebase-indexer-hook.sh: Auto-trigger hook for session start

Features:
- Supports 15+ programming languages (TS, JS, Python, Go, Rust, etc.)
- Concept extraction from filenames, exports, functions, classes
- Token-efficient indexing (~99% savings vs full codebase read)
- JSON-based index with jq integration
- Auto-detection of code projects
- Git-aware incremental updates

Token Efficiency:
- Full codebase read: ~188K tokens
- Index-based query: ~2K tokens
- Potential savings: ~99%

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-26 18:50:16 +04:00

80 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Codebase Indexer - Auto-Trigger Hook
# Runs automatically before sessions to detect and use codebase index
set -e
# Configuration
PROJECT_ROOT="$(pwd)"
INDEX_FILE="$PROJECT_ROOT/.codebase-index.json"
LOG_FILE="$HOME/.claude/logs/codebase-indexer.log"
AUTO_UPDATE="${AUTO_UPDATE:-true}"
# Create log directory
mkdir -p "$(dirname "$LOG_FILE")"
# Logging
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
}
# Check if project has an index
check_index() {
if [ -f "$INDEX_FILE" ]; then
# Index exists - check if it needs updating
if [ "$AUTO_UPDATE" = "true" ]; then
# Check git for changes
if git -C "$PROJECT_ROOT" rev-parse --git-dir > /dev/null 2>&1; then
local changes=$(git -C "$PROJECT_ROOT" diff --name-only HEAD 2>/dev/null | wc -l)
if [ $changes -gt 0 ]; then
log "Changes detected ($changes files), updating index..."
bash "$HOME/.claude/skills/codebase-indexer/update-index.sh" "$PROJECT_ROOT" > /dev/null 2>&1 &
fi
fi
fi
# Export index info for Claude
export CODEBASE_INDEX_EXISTS="true"
export CODEBASE_INDEX_PATH="$INDEX_FILE"
log "Index found at $INDEX_FILE"
return 0
fi
# No index - check if this is a code project
if is_code_project "$PROJECT_ROOT"; then
log "Code project detected but no index found"
export CODEBASE_INDEX_SUGGEST="true"
fi
return 1
}
# Check if directory is a code project
is_code_project() {
local dir="$1"
# Check for common code project indicators
[ -f "$dir/package.json" ] && return 0
[ -f "$dir/tsconfig.json" ] && return 0
[ -f "$dir/pyproject.toml" ] && return 0
[ -f "$dir/requirements.txt" ] && return 0
[ -f "$dir/go.mod" ] && return 0
[ -f "$dir/Cargo.toml" ] && return 0
[ -f "$dir/pom.xml" ] && return 0
[ -d "$dir/src" ] && return 0
[ -d "$dir/lib" ] && return 0
# Check for code files
local code_files=$(find "$dir" -maxdepth 2 -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" -o -name "*.go" -o -name "*.rs" \) 2>/dev/null | wc -l)
[ $code_files -gt 5 ] && return 0
return 1
}
# Main function
main() {
check_index
}
main