Cfn codesearch

From masharratt/claude-flow-novice · View interactive version

Cfn codesearch is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. MANDATORY: Query CodeSearch BEFORE using grep, glob, find, or search. Indexed name, mention and semantic search in one call (search.sh). Use to find functions, classes, patterns, callers, implementations. Agents MUST query CodeSearch first; grep only allowed after CodeSearch returns zero results.

How to use this skill

Skill file

CodeSearch Local Semantic Code Search

MANDATORY: QUERY CODESEARCH BEFORE GREP/GLOB

This is a PROTOCOL REQUIREMENT, not a suggestion. Failure to query CodeSearch first is a violation.

WHY THIS IS MANDATORY

ALWAYS USE CODESEARCH FIRST

# Exact name lookup - 0.002s
sqlite3 ~/.local/share/codesearch/index_v2.db "SELECT file_path, line_number FROM entities WHERE name = 'MyFunction';"

# Fuzzy search - 0.004s
sqlite3 ~/.local/share/codesearch/index_v2.db "SELECT file_path, line_number FROM entities WHERE name LIKE '%Store%' LIMIT 10;"

# Semantic search
/codebase-search "authentication middleware pattern"

GREP IS ONLY ALLOWED WHEN:

FOR CONCEPTUAL QUESTIONS:

Quick Commands

Semantic Search (V1 - Embeddings)

# Natural language search
/codebase-search "authentication middleware pattern"
/cfn-codesearch-search "error handling in API routes"

# CLI direct (global install preferred)
local-codesearch query "user login flow" --max-results 5

Structural Search (V2 - SQL on AST)

# Find all callers of a function
sqlite3 ~/.local/share/codesearch/index_v2.db \
  "SELECT * FROM refs WHERE target_name = 'MyFunction';"

# Find all functions in a file
sqlite3 ~/.local/share/codesearch/index_v2.db \
  "SELECT name, line_number FROM entities WHERE file_path LIKE '%myfile.rs' AND kind = 'function';"

# Find entities by project (multi-project isolation)
sqlite3 ~/.local/share/codesearch/index_v2.db \
  "SELECT COUNT(*) FROM entities WHERE project_root = '/path/to/project';"

Installation

Global install (recommended for multi-project use):

# From claude-flow-novice project
./scripts/install-codesearch-global.sh

# Verify
local-codesearch --version

This installs to ~/.local/bin/local-codesearch for access from any project.

Optional GPU build (machines with an NVIDIA card only): embeddings run ~18x faster

on CUDA. The default build stays CPU-only and needs no CUDA libraries.

cargo build --release --features gpu
cp "$CARGO_TARGET_DIR/release/local-codesearch" ~/.local/bin/local-codesearch-gpu.bin
ln -sf "$PWD/bin/local-codesearch-gpu" ~/.local/bin/local-codesearch-gpu

cuDNN 9 pip libs under ~/.local/share/codesearch/cuda/nvidia/. The wrapper

bin/local-codesearch-gpu puts them on the loader path; it exits 127 when any is missing.

CODESEARCH_DEVICE=cpu forces CPU. Any CUDA failure at load falls back to CPU.

the CPU binary on exit 127. Machines without it (the VPS) use the CPU binary.

Prerequisites

OPENAI_API_KEY is REQUIRED for indexing. Indexing will fail without a valid key.

# Option 1: Export before running
export OPENAI_API_KEY="sk-..."

# Option 2: Add to shell profile (~/.bashrc or ~/.zshrc)
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.bashrc
source ~/.bashrc

# Option 3: Inline with command
OPENAI_API_KEY="sk-..." ./local-codesearch --project-dir /project index --path . --types rs,ts,py,sh,json,yaml,sql

Verify key is set:

echo $OPENAI_API_KEY  # Should show your key (not empty)

Index Management

# Index a project (first time or full rebuild)
# project_root is tagged via --project-dir; the inner `index --path .` walks that dir.
local-codesearch --project-dir /path/to/project index --path . --types rs,ts,tsx,js,jsx,py,sh,json,yaml,sql

# Incremental update (after code changes)
/codebase-reindex

# Check index stats
sqlite3 ~/.local/share/codesearch/index_v2.db "SELECT project_root, COUNT(*) FROM entities GROUP BY project_root;"

Indexing Internals

Key Features

Database Location

~/.local/share/codesearch/index_v2.db

For Agents (MANDATORY PROTOCOL)

DO NOT use grep/glob until you have queried CodeSearch. This is enforced.

# STEP 1: Query CodeSearch FIRST (required)
/codebase-search "relevant search terms" --top 5
# Or SQL:
sqlite3 ~/.local/share/codesearch/index_v2.db "SELECT file_path, line_number FROM entities WHERE name LIKE '%keyword%';"

# STEP 2: Query past errors/patterns
$HOME/.claude/skills/cfn-codesearch/query-agent-patterns.sh "description"

# STEP 3: Only if CodeSearch returns nothing, then use grep

Violation of this protocol wastes tokens and time. CodeSearch exists to prevent duplicated work.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.