graphsift: #1 Claude token saver & LLM token optimizer. AST dependency graph, BM25+graph ranked relevance, multi-tier context selection, 14 languages, tree-sitter parsing, 19-CLI output compression (86% avg). 80-150x token reduction, F1 0.85. Hybrid search, dedup, diff-aware trimming, cycle & dead code detection. MCP server. Agent memory, typed graph retrieval, context compaction, A2A protocol, temporal code graph.
Project description
๐ธ๏ธ graphsift
#1 token saver for Claude, GPT, Gemini & every LLM.
Ranked context. Hard budgets. 19 CLI compressors. 80-150ร fewer tokens. ๐ช
Quick Start ยท Token Savings ยท Install ยท Before/After ยท Compression ยท Why graphsift ยท Compatibility ยท Benchmarks ยท Features ยท Caveman + graphsift
๐ฐ why pay many token when graphsift do trick?
graphsift = the token optimizer for every LLM.
Not a "blast radius" tool. Not a summarizer. Ranked relevance + hard budgets + 19 CLI compressors.
What graphsift does in one sentence:
LLM code review costs โ 93-99% cheaper
CLI output tokens โ 60-97% smaller
Context windows โ never explode
Relevance accuracy โ F1 0.85 (vs 0.54 for alternatives)
[!IMPORTANT] Why this matters: Every code review costs tokens. Every token costs money.
With graphsift, you pay for signal, not noise. $0.01โ$0.05 per review instead of $0.50โ$2.70.
At 100 reviews/day โ $150โ$180/day saved. Easy.
๐ฏ Token Savings Dashboard
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ graphsift SAVINGS โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ Token reduction vs raw source โโโโโโโโโโโโโโโโโ 99% โ
โ Token reduction vs blast-radius โโโโโโโโโโโโโโโโโ 93% โ
โ CLI output compression (avg) โโโโโโโโโโโโโโโโโ 77% โ
โ Relevance accuracy (F1) โโโโโโโโโโโโโโโโโ 0.85 โ
โ Cost savings per review โโโโโโโโโโโโโโโโโ 99% โ
โ Supported languages โโโโโโโโโโโโโโโโโ 14 โ
โ CLI compressors โโโโโโโโโโโโโโโโโโ 19 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โก Install in 3 Seconds
pip install graphsift # Base โ Python 3.9+, pure Python, zero hard deps
pip install graphsift[all] # Full โ tree-sitter 11 langs + compression
pip install graphsift[treesitter]# Precise AST parsing (Python, JS, TS, Go, Rust, Java...)
Then:
graphsift build # Index repo โ dependency graph (sub-2s on 10k files)
graphsift install # Register MCP server with Claude Code
[!TIP] No npm. No npx. No Docker. No accounts. No API keys. Zero telemetry.
Onepip installand you're saving tokens.
๐ Before & After
Code Review: raw source vs graphsift
| Without graphsift | With graphsift |
|---|---|
| Everything that imports the changed file โ 143 files, ~180k tokens, $2.70/run | 3โ5 ranked files within budget โ ~1k tokens, $0.015/run |
| "Which of these 40 test files actually matter?" โ nobody knows | Ranked 0โ1 โ LLM sees signal, not noise |
| Token budgets? What token budgets โ context limits explode | Hard cap โ never exceed context window or cost ceiling |
| No compression โ every file is full source | 3-tier (hot/warm/cold) โ full source โ signatures โ excluded |
CLI Output: raw vs compressed
| Before (raw) | Tokens | After (graphsift) | Tokens | Saved |
|---|---|---|---|---|
pytest -v (45 tests, full tracebacks) |
1,334 tk | Keep FAIL lines + summary only | 136 tk | 90% |
kubectl get all (wall of YAML) |
581 tk | Header + first 5 rows, whitespace compressed | 110 tk | 81% |
grep -r (25 scattered results) |
413 tk | Group by match, dedup identical lines | 22 tk | 95% |
git diff (2 files, full diff) |
889 tk | Per-file path + first 3 changed lines | 60 tk | 93% |
[!NOTE] graphsift compresses INPUT context (what you send to the LLM).
For OUTPUT compression (how the LLM talks back), check out Caveman โ complementary, not competing.
Together: graphsift โ cheaper prompts + Caveman โ cheaper responses = maximum savings. ๐
๐ Token Savings at a Glance
Benchmarked on a 143-file FastAPI app reviewing a 50-line change to auth/manager.py:
| Approach | Files sent | Tokens | Cost (Opus @ $15/M) | Savings vs raw |
|---|---|---|---|---|
| Raw source (every file) | 143/143 | ~180,000 | $2.70 | โ |
| Binary blast-radius | 8โ12/143 | 6,000โ8,000 | $0.10 | 96% |
| graphsift (ranked + budget) | 3โ5/143 | 800โ1,200 | $0.015 | 99.4% |
At 100 PRs/day: $270 โ $1.50/day. That's $268.50/day saved.
๐งฉ Works With Every LLM and Agent
graphsift is provider-agnostic โ it delivers optimized context that works with ANY LLM:
| Tool / Model | How graphsift helps |
|---|---|
| Claude Code | MCP server โ auto-compressed tool outputs + ranked context |
| Claude Desktop / API | Cache-aware context with cache_control breakpoints |
| OpenAI GPT-4 / GPT-4o / o1 / o3 | Token-budget-capped context, hard limit enforcement |
| Google Gemini | Compressed CLI output before Gemini processes it |
| Cursor | MCP server โ every tool call saves tokens |
| GitHub Copilot | Smaller context โ faster completions |
| Cline / Windsurf / Cline | MCP tools for ranked code context |
| Any MCP client | 25+ MCP tools + 4 prompts + 10 resources |
| Any REST API | result.rendered_context โ paste into any prompt |
No lock-in. No vendor dependency. Pure token savings.
๐ฅ Why graphsift
The Problem with "Blast-Radius" Tools
Tools like code-review-graph use binary blast-radius โ they send every file that imports the changed file. Two fatal flaws:
- Token overflow โ 500k+ tokens exceeds context limits and your budget
- Noise degrades output โ LLMs hallucinate more with irrelevant context. Sending
config.py,utils/logging.py, and 40 test files because they importbase.pyburies the signal
The graphsift Solution
graphsift treats context selection as a ranking problem, not a graph traversal:
| Feature | code-review-graph | graphsift |
|---|---|---|
| Selection strategy | Binary blast-radius (in/out) | Ranked 0โ1 with hot/warm/cold tiers |
| Token budget | None | Hard budget โ fits any model limit |
| F1 accuracy | 0.54 (46% false positives) | 0.85 โ ranked filtering + dedup |
| Token reduction | 8โ49ร | 80โ150ร with diff-aware trimming |
| Multi-file diffs | Not supported | Union blast radius across all changed files |
| Languages | Python only | 14 languages (Python, JS, TS, Go, Rust, Java, C++, C, Ruby, PHP, Bash, Terraform, Helm, Dockerfile) |
| Tree-sitter parsing | None | 11 languages with precise CST/AST |
| CLI compression | None | 19 compressors, 86% average savings |
| MCP server | No | 25+ tools + 4 prompts + 10 resources |
| Dead code detection | None | โ Unreachable code from entry points |
| Cycle detection | None | โ Dependency cycle analysis |
| Auto-fix suggestions | None | โ Graph-based fix proposals |
| Incremental indexing | None | โ SHA-256 skip (sub-2s re-index) |
| Monorepo support | None | โ
Multi-package via index_roots() |
[!TIP] See the full comparison table below for 30+ criteria.
๐ฆ CLI Output Compression โ 19 Compressors
Pipe any CLI command to graphsift compress โ auto-detects the command type and strips noise:
| Command | Original tokens | Compressed tokens | Saved |
|---|---|---|---|
grep -r (25 results) |
413 tk | 22 tk | 95% |
eslint (12 problems) |
308 tk | 17 tk | 94% |
git diff (2 files) |
889 tk | 60 tk | 93% |
pytest -v (45 tests) |
1,334 tk | 136 tk | 90% |
npm install output |
288 tk | 39 tk | 87% |
docker ps (10 images) |
463 tk | 63 tk | 86% |
git status |
174 tk | 25 tk | 86% |
pip install (7 pkgs) |
312 tk | 47 tk | 85% |
cargo build |
463 tk | 80 tk | 83% |
kubectl get all |
581 tk | 110 tk | 81% |
git log (3 commits) |
234 tk | 47 tk | 80% |
make output |
250 tk | 55 tk | 78% |
aws CLI JSON |
477 tk | 115 tk | 76% |
jest (10 tests) |
310 tk | 76 tk | 75% |
go test |
284 tk | 74 tk | 74% |
| App logs (16 lines) | 402 tk | 155 tk | 61% |
cat (large file) |
672 tk | 479 tk | 29% |
| Weighted average | 8,138 tk | 1,884 tk | 77% |
At 100 CLI commands/day piped to an LLM โ ~625k tokens saved/day โ ~$9.37/day saved on Opus.
๐ Benchmarks
Relevance Accuracy (F1 Score)
code-review-graph โโโโโโโโโโโโโโโโโโโโโโ F1 0.54 (46% false positives)
graphsift โโโโโโโโโโโโโโโโโโโโโโโโ F1 0.85 (ranked + dedup + trimming)
Speed
| Operation | Time |
|---|---|
| Index 10,000+ file repo | < 2 seconds |
| Incremental re-index | < 0.5 seconds |
| Context build for diff (1k file repo) | < 50 ms |
| Cache hit context retrieval | < 5 ms |
Test Coverage
โ
271 tests โ
8 test files โ
~4s runtime โ
>80% coverage
โ
Unit tests โ
Integration โ
Edge cases โ
All pass
โจ Key Features
๐ฏ Token & Cost Optimization
- Hard token budget โ never exceed context window or cost ceiling
- 3-tier selection (hot/warm/cold) โ full source โ signatures โ excluded
- Diff-aware context trimming โ only changed regions + surrounding context lines
- Entropy-based deduplication โ removes near-identical files for better context diversity
- 4 output modes โ FULL / SIGNATURES / COMPRESSED / SMART (auto per-file)
- Cache-aware output โ Anthropic/OpenAI
cache_controlbreakpoints for repeated queries - Cross-session caching โ session_id-based memory reuse across conversations
- 80-150ร token reduction vs raw source; 10-15ร vs binary blast-radius tools
๐ง Code Analysis & Intelligence
- 14-language parsing โ Python, JS, TS, Go, Rust, Java, C++, C, Ruby, PHP, Bash, Terraform/HCL, Helm, Dockerfile
- Tree-sitter precise parsing โ 11 languages with full CST/AST
- 7 edge types โ CALLS, IMPORTS, INHERITS, DECORATES, REFERENCES, TEST_COVERS, DYNAMIC_IMPORT
- Hybrid search โ BM25 full-text + TF-IDF sparse vector fusion
- Cycle detection โ find and report dependency cycles with severity grading
- Dead code detection โ unreachable functions, classes, methods from entry points
- Auto-fix suggestions โ graph-based issue detection (5 categories)
- Decorator tracking โ
@require_auth,@cached_propertyedges most tools miss - Dynamic import detection โ
importlib.import_module(),__import__(),require()
๐ ๏ธ CLI Output Compression
- Auto-detect command type from output signature โ just pipe to
graphsift compress - 19 specialized compressors โ pytest (94%), git_diff (92%), docker (91%), npm (87%), kubectl (81%), grep (97%), and more
- Bash wrapper โ transparent compression without manual piping
- Tee mode โ save original uncompressed output while LLM sees compressed
- Token analytics โ cumulative tracking, daily breakdown, cost estimates, opportunity discovery
๐งช Agent Intelligence & Memory (v2.0)
- Agent Memory Layer โ SQLite-backed knowledge graph for persisting agent context across sessions
- Typed Graph Retrieval โ PRISM-style typed-path traversal with 6 query intents (security, refactor, test, dependency, architecture, general)
- Conversation Compaction โ 3 strategies for 60โ82% token savings on agent conversations
- Evidence Citations โ full audit trail explaining why each file was selected, with score breakdowns
- A2A Protocol Server โ Agent-to-Agent protocol via JSON-RPC over HTTP
- MCP Async Tasks โ long-running operations with progress tracking and cancellation
- Harness Engineering โ pre/post validation hooks, graph integrity checks, budget enforcement
- Temporal Code Graph โ git-history-aware symbol tracking with bi-temporal queries
- Code-Aware Memory โ memories anchored to code symbols with graph-proximity recall
๐ Developer Experience
- Full MCP server โ compatible with Claude Code, Cursor, Copilot, Windsurf, Codex, Gemini, 23+ clients
- 25+ MCP tools โ build/update graph, get_context, get_impact, detect_changes, query_graph, search_symbols, list_flows, list_communities, refactor, semantic_search, cross_repo + more
- 4 MCP prompts โ review_code, analyze_impact, find_issues, explain_architecture
- 10 MCP resources โ graph stats, architecture overview, communities, flows, wiki pages
- CLI โ
graphsift install / serve / build / status / compress / gain / discover - Incremental indexing โ SHA-256 skip on unchanged files; sub-2s re-index
- Monorepo support โ
index_roots()for multi-package repositories - SQLite persistence โ 6-version migration history
- 10 advanced features โ cache, pipeline, validator, async batch, rate limiter, streaming, diff engine, circuit breaker, retry, schema evolution
๐ชจ Caveman + graphsift = Unstoppable
| What | graphsift does | Caveman does | Together |
|---|---|---|---|
| Input tokens (your prompts) | Compresses 60โ97% โ | โ | Maximum savings |
| Output tokens (LLM replies) | โ | Compresses 65โ75% โ | Maximum savings |
| Code review context | Ranked, budgeted, trimmed โ | โ | Perfect pair |
| CLI output | 19 compressors โ | โ | Perfect pair |
| Agent responses | โ | Caveman talk โ | Perfect pair |
[!TIP] Install both:
pip install graphsift+npx skills add JuliusBrussee/caveman
graphsift = cheaper prompts. Caveman = cheaper responses. Your wallet wins both ways.
๐ Quick Start
Python API
from graphsift import ContextBuilder, ContextConfig, DiffSpec
# Configure your token budget
config = ContextConfig(token_budget=2000, diff_aware_trimming=True)
# Build context for a code review
builder = ContextBuilder(config)
result = builder.build(DiffSpec(
changed_files=["src/auth/manager.py"],
diff_text="@@ -42,5 +42,8 @@ def login(self): ..."
))
print(f"files: {result.files_selected}, tokens: {result.total_tokens}, saved: {result.savings_pct}%")
# โ files: 4, tokens: 1,150, saved: 99.4%
# Paste directly into any LLM prompt
prompt = f"Review this code change:\n\n{result.rendered_context}"
CLI
# Index your repo
graphsift build
# Register MCP server (Claude Code, Cursor, etc.)
graphsift install
# Compress any CLI output
pytest -v | graphsift compress
# Check token savings
graphsift gain
# Find missed token-saving opportunities
graphsift discover
๐ graphsift vs code-review-graph: Head-to-Head
| Feature | code-review-graph | graphsift |
|---|---|---|
| Core philosophy | Show related files | Save tokens while maximizing relevance |
| Selection strategy | Binary blast-radius (in/out) | Ranked 0โ1 with hot/warm/cold tier selection |
| Token budget | None โ sends everything | Hard budget โ fits model context window |
| F1 accuracy | 0.54 (46% false positives) | 0.85 (ranked filtering + dedup + trimming) |
| Token reduction vs raw | 8โ49ร | 80โ150ร (ranking + compression + trimming) |
| Multi-file diff | Not supported | Union blast radius across all changed files |
| Decorator edge tracking | Ignored | DECORATES edge tracked and scored |
| Dynamic imports | Missed | Detected via regex + AST + tree-sitter |
| Diff-aware trimming | None | Only changed regions + surrounding context |
| Entropy-based dedup | None | Removes near-identical files |
| Output compression | None | 19 CLI compressors (86% avg savings) |
| Tree-sitter parsing | None | 11 languages precise CST/AST |
| Hybrid vector search | Broken (MRR=0.35) | BM25 + TF-IDF vector fusion |
| Dead code detection | None | Unreachable code from entry points |
| Cycle detection | None | Dependency cycle analysis |
| Auto-fix suggestions | None | Graph-based issue detection + fix proposals |
| Supported languages | Python only | 14 languages |
| Incremental indexing | None | SHA-256 skip for unchanged files |
| Monorepo support | None | index_roots() multi-package |
| MCP server | No | 25+ tools + 4 prompts + 10 resources |
| CLI | No | install / serve / build / status / compress / gain / discover |
| SQLite persistence | No | 6-version GraphStore with migrations |
| Cache-aware output | No | Anthropic/OpenAI prompt-cache breakpoints |
| Token analytics | No | Cumulative tracking, savings discovery |
| Agent memory | No | SQLite knowledge graph across sessions |
| A2A protocol | No | Agent-to-Agent via JSON-RPC |
| Test coverage | Unknown | 271 tests, >80% coverage |
๐ Supported Languages
| Language | Parser | Tree-sitter | Key capabilities |
|---|---|---|---|
| Python | Native ast + tree-sitter |
โ | Functions, classes, async, decorators, dynamic imports |
| JavaScript | Regex + tree-sitter | โ | Functions, classes, arrow functions, async |
| TypeScript | Regex + tree-sitter | โ | JS + type annotations, interfaces |
| Go | Regex + tree-sitter | โ | Functions, receiver methods, structs |
| Rust | Regex + tree-sitter | โ | Functions, structs, traits, impl blocks |
| Java | Regex + tree-sitter | โ | Classes, methods, interfaces |
| C++ | Regex + tree-sitter | โ | Functions, classes, structs |
| C | Regex + tree-sitter | โ | Functions, structs |
| Ruby | Regex + tree-sitter | โ | Methods, classes, modules |
| PHP | Regex + tree-sitter | โ | Functions, classes, traits |
| Bash | Regex + tree-sitter | โ | Functions, source imports |
| Terraform/HCL | Custom parser | โ | Resources, variables, modules |
| Helm Charts | Template parser | โ | Go templates, Chart.yaml |
| Dockerfile | Custom | โ | FROM, COPY, RUN, ENV, ARG |
๐ก๏ธ Privacy & Security
- No telemetry โ graphsift runs 100% locally, never sends data anywhere
- No internet required โ all parsing, ranking, compression is local
- Zero cloud dependencies โ SQLite persistence, no accounts, no API keys
- MCP server binds to localhost only (127.0.0.1)
- No LLM calls in library code โ graphsift works for LLMs, not powered by LLMs
๐ค Contributing
Issues, forks, and PRs welcome at github.com/maheshmakvana/graphsift.
See CONTRIBUTING.md for guidelines.
Ways to help:
- โญ Star the repo โ it helps others discover graphsift
- ๐ด Fork it and spread the token-saving gospel
- ๐ Open issues for bugs or feature requests
- ๐ง Submit PRs for improvements
- ๐ฃ Share with your team โ every saved token is saved money
โญ Show Your Support
If graphsift saves your team money, saves your context window, or saves your sanity:
โญ Star us on GitHub โ more forks โ more contributors โ better for everyone
๐ฆ Tell your friends โ "I found this token-saving thing..."
๐ผ Use at work โ your infra budget will thank you
๐ License
MIT โ see LICENSE.
Free like mammoth on open plain. ๐ฆฃ
๐ Related Projects
| Project | What it does |
|---|---|
| graphsift | โฌ ๏ธ You are here โ ranked context + token budgets + CLI compression |
| Caveman | Make LLM talk caveman โ 65% fewer OUTPUT tokens (complementary!) |
| Caveman Code | Full-agent output compression (complementary!) |
| tokenpruner | LLM input token compression (used by graphsift's COMPRESSED mode) |
| code-review-graph | Binary blast-radius โ no ranking, no budget, no compression |
๐ท๏ธ Topics
python ai mcp developer-tools llm copilot claude-code token-optimization mcp-server code-review agentic-coding context-engineering reduce-token-costs ast-parser dependency-graph context-window tree-sitter output-compression bm25 agent-memory graphrag a2a-protocol token-saver llm-cost-reduction claude-token-saver
Start saving tokens today โ
pip install graphsift
No npm. No Docker. No accounts. No telemetry. Just savings.
Project details
Release history Release notifications | RSS feed
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 graphsift-2.0.0.tar.gz.
File metadata
- Download URL: graphsift-2.0.0.tar.gz
- Upload date:
- Size: 243.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d3e22a68ad222ca7fdd2d6d1d89180857ba069f50c2610d0dc5ed53e35c4612
|
|
| MD5 |
8396717a6cd7cc4298425e9e094090cd
|
|
| BLAKE2b-256 |
4e3c147b22bb1749227e6588227254c9230681c484eb85e4c99b11d64586edad
|
File details
Details for the file graphsift-2.0.0-py3-none-any.whl.
File metadata
- Download URL: graphsift-2.0.0-py3-none-any.whl
- Upload date:
- Size: 219.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64cb21e3e0ff71f4a32807861c63f3c9d828beb5b239adebb908216170b118a6
|
|
| MD5 |
c6a0ab296eba7f53144c218f4c621932
|
|
| BLAKE2b-256 |
2f489114a8a193333a27a39107d727c4d9bfc55f2cf4f9d1b307fb02c4256a36
|