Local code intelligence: index, query and expose codebase context deterministically
Project description
hybrid-coco
Local code intelligence for AI agents. Index your codebase once, query it deterministically: ~94% fewer tokens than grep + cat.
hybrid-coco builds a local SQLite index of your source code using tree-sitter, exposes it via a CLI and an MCP server, and integrates with Claude Code via hooks. No embeddings, no vector database, no Docker. One install command.
pip install hybrid-coco && hc init
The problem it solves
When Claude reads a file to find one function, it pays for the entire file:
# Without hybrid-coco
Read("src/gitlab_helpers.py") > 12,140 tokens (whole file)
# With hybrid-coco
hc_file_context("src/gitlab_helpers.py") > 297 tokens (symbols only) < 97.6% savings
The hook intercepts Read and Grep calls and suggests the equivalent hc_* tool. Same answer, fraction of the tokens.
How it works
Source files ──tree-sitter──► SQLite + FTS5 ──► CLI (hc)
│
└──────────────► MCP server (hc_*)
│
Claude Code hooks
intercept Read/Grep
> suggest hc_* tools
hc index .: parses every source file with tree-sitter, extracts symbols (functions, classes, methods, imports) with their signatures, docstrings, and line numbers into a FTS5 trigram indexhc query / symbol / file-context: queries the index and returns only what's relevant, not the whole filehc serve: exposes the same queries as MCP tools (hc_search,hc_symbol,hc_file_context,hc_status) for Claude Code- Hooks:
hc initregisters PreToolUse/PostToolUse hooks that suggesthc_*tools whenever Claude is about toReadorGrepan indexed file
Benchmark
Measured on a real Rust codebase: 76 files, 2,242 symbols:
| Query | Traditional | hybrid-coco | Savings |
|---|---|---|---|
Symbol lookup (TimedExecution) |
2,227 tok | 51 tok | 97.7% |
Pattern search (savings) |
3,164 tok | 334 tok | 89.4% |
File structure (tracking.rs) |
12,140 tok | 1,245 tok | 89.7% |
Schema grep (CREATE TABLE) |
92 tok | 29 tok | 68.5% |
File read (git.rs) |
16,343 tok | 377 tok | 97.7% |
| Total (5 queries) | 33,966 tok | 2,036 tok | ~94% |
Traditional = grep -rn + cat. hybrid-coco = hc symbol + hc query + hc file-context.
Quickstart
1. Install
curl -fsSL https://raw.githubusercontent.com/jmeiracorbal/hybrid-coco/main/install.sh | bash
This installs hc, configures Claude Code hooks, and adds the awareness file — no Python knowledge required. Requires Python 3.11+ (detects uv, pipx, or pip automatically).
2. Index your project and register with Claude Code
cd your-project/
hc init
hc init does three things:
- Indexes the current directory (tree-sitter, SHA-256 incremental)
- Registers the MCP server in
.claude/settings.json - Installs global hooks in
~/.claude/hooks/that interceptReadandGrep
Restart Claude Code to activate.
3. Use from Claude Code
The MCP tools are now available in every conversation:
hc_search("savings_pct") # FTS5 search over names, signatures, docstrings
hc_symbol("TimedExecution") # exact/prefix symbol lookup
hc_file_context("src/git.rs") # all symbols in a file, structured
hc_status() # index stats
The hooks will remind you (via stderr) whenever Claude is about to read an indexed file directly.
CLI reference
hc index [PATH] Index PATH (default: cwd)
hc update [PATH] Re-index only changed files (SHA-256 diff)
hc status [PATH] Index stats: files, symbols by kind, last update
hc query <TEXT> FTS5 trigram search on name, signature, docstring
hc symbol <NAME> Exact name lookup, then prefix fallback
hc file-context <PATH> All symbols in PATH grouped by kind (~97% savings vs cat)
hc serve Start MCP server (stdio)
hc init [PATH] Index + register MCP + install hooks
Supported languages
| Language | Parser |
|---|---|
| Python | tree-sitter-python |
| Rust | tree-sitter-rust |
| JavaScript | tree-sitter-javascript |
| TypeScript | tree-sitter-typescript |
Adding a language requires implementing a ~100-line parser in src/hybrid_coco/parsers/.
Design decisions
SQLite + FTS5, not a vector database: deterministic results, zero infrastructure, single file. Trigram search covers partial matches and is fast enough for codebases up to ~100K files. Semantic (embedding) search can be layered on top via sqlite-vec without changing the schema.
tree-sitter, not regex: symbol extraction is grammar-aware. Signatures and docstrings are extracted structurally, not by pattern matching.
No server process: hc serve runs as a stdio MCP server launched on demand by Claude Code. There is no daemon to manage.
Incremental by default: hc update re-indexes only files whose SHA-256 has changed. Full re-index is only needed on first run or after .gitignore changes.
Using with gtk-ai
hybrid-coco and gtk-ai are independent tools that work well together:
- hybrid-coco: reduces tokens on code navigation (
Read,Grep, file structure queries) - gtk-ai: reduces tokens on command output (
find,ls,git,grepand other Bash tools)
When used together, gtk-ai will by default compress all MCP tool output, including hc_* responses. To prevent that, add hc_ to GTK_MCP_PASSTHROUGH_PATTERNS in the gtk-ai hook script:
# ~/.claude/hooks/gtkai-post-tool-use.sh
export GTK_MCP_PASSTHROUGH_PATTERNS="hc_"
This tells gtk-ai to let hc_search, hc_symbol, hc_file_context, and hc_status responses through uncompressed. hybrid-coco already returns minimal output, so compressing it further would lose information.
Neither tool requires the other. Configure this only if you have both installed.
Relation to CocoIndex
hybrid-coco is inspired by CocoIndex but makes different trade-offs:
| CocoIndex | hybrid-coco | |
|---|---|---|
| Search | Vector (semantic) | FTS5 trigram (lexical) |
| Backend | PostgreSQL + pgvector | SQLite (single file) |
| Infrastructure | Docker required | Zero |
| Install | Complex | `curl ... |
| Granularity | Chunks | Symbols (functions, classes) |
| Target | Large-scale RAG | Local dev, agent token reduction |
Development
git clone https://github.com/jmeiracorbal/hybrid-coco
cd hybrid-coco
uv sync
uv pip install -e .
hc --version
Run tests:
uv run pytest
Run the benchmark against any indexed project:
cd path/to/project && hc index .
python scripts/benchmark.py path/to/project
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hybrid_coco-0.1.4.tar.gz.
File metadata
- Download URL: hybrid_coco-0.1.4.tar.gz
- Upload date:
- Size: 81.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f02ea27e2e8f1f8f101b2c569637a97fcd3a2afac8ea59fa0dec48db2d1223b7
|
|
| MD5 |
c6508783d7bbd548abada9ea23273a68
|
|
| BLAKE2b-256 |
4d6508a51695c56de821063eeb35e4b8273b227557d2d7143321e5abb41ed11a
|
File details
Details for the file hybrid_coco-0.1.4-py3-none-any.whl.
File metadata
- Download URL: hybrid_coco-0.1.4-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebfcf83396d30514b4471baa6f4ba4cee3b6a0645c422037f6bedcf465f44357
|
|
| MD5 |
bc00b4a66c101f0170da0ba684e9215d
|
|
| BLAKE2b-256 |
b3e67ba3b4a8911bf7d4b2e2cc7505fd0424f782d60675fb5cb281a462dd91d5
|