@grundy40/contextslice
Zero-dependency multi-language structural code parser & 1-Tool MCP server for AI coding agents.
ContextSlice builds a lightweight local call graph of your repository, keeps focal target functions complete, folds direct 1-hop / 2-hop neighbors into signature-only skeletons, and drops unrelated noise — cutting token costs dramatically with zero runtime dependencies.
- Zero runtime
dependencies: Uses only Node.js built-ins + an embedded web-tree-sitter WASM runtime with lazy grammar caching (~/.contextslice/parsers/) and automatic offline state-machine fallback.
- Multi-Language Structural Parsing, HTML Inline
<script> & Single-File Slicing: Supports TypeScript/JavaScript, Python (including method-level ClassName.methodName extraction & structural class skeletons), Go, Rust, Java, Kotlin, C#, C/C++, Swift, PHP, Ruby, SQL, HTML (landmark sections + inline <script> symbols + oversized <style>/section windowing), and plain-text configs (.json, .yaml, .yml, .toml, .ini, .cfg, .conf, .xml, .properties, .txt) with automatic ±40-line local window truncation for configs over 200 lines. Supports directory repositories and single-file targets via MCP subPath/projectPath or CLI --root/--sub.
- Definition-First Priority, Query Intent Detection (
intent="symbol" | "text"), Near-Duplicate <stub> Folding & Per-Call --exclude: Classifies query tokens against structural parser symbol tables so symbol queries prioritize actual defining files over prose mentions, collapses near-duplicate pages (Jaccard >= 0.7) into single-line <stub> entries, prioritizes direct-hit source <focal> implementations ahead of docs/** and tests/**, supports --exclude / MCP exclude glob filters, deduplicates Markdown rendering, emits file_tree_empty_query / file_tree_zero_matches / single-file-slice modes with <file total_lines="..." shown_lines="..."> tags, and safely filters conversational stopwords.
- 32K Benchmark Proven (
32,768 Default Budget): Evaluated on Hono (TS), HTTPX (Py), and Gin (Go) open-source repos with 85.1% token savings and 100% refactoring pass rate at the unified 32K default budget.
Quick Usage via npx
1. Run CLI Slicer Directly
Slice the current repository in one command without installing anything permanently:
npx @grundy40/contextslice "login token validation" --budget 32768
Slice a specific repository path or exclude noisy docs/duplicates:
npx @grundy40/contextslice "checkout discount" --root ./my-project --budget 32768
npx @grundy40/contextslice "runTest PRESET_ENDPOINTS" --exclude "*.md,*_enhanced.html" --budget 32768
Check version or CLI options:
npx @grundy40/contextslice --version
npx @grundy40/contextslice --help
Or install globally (npm install -g @grundy40/contextslice) if you prefer short commands (contextslice, ctxslice, and ctxslice-mcp):
npm install -g @grundy40/contextslice
contextslice "retry queue" --budget 32768
Prefer a visual browser UI? Try the Live Demo at https://grundy40.github.io/ContextSlice/.
Connect 1-Tool MCP to AI Coding Agents
@grundy40/contextslice exposes two MCP tools inside a single ultra-lean stdio server (ctxslice-mcp):
get_context_slice — Primary code-reading tool (Tree-sitter WASM / state-machine structural parser + True Call Graph + TF-IDF).
expand_skeleton_cluster — On-demand symbol expander for folded skeleton hubs.
Claude Code (npx Zero-Setup)
claude mcp add --scope user context-slice -- npx -y -p @grundy40/contextslice ctxslice-mcp
Add to ~/.claude/CLAUDE.md so Claude always slices first before reading raw files:
When inspecting, debugging, or modifying code in any project folder, ALWAYS call the `get_context_slice` MCP tool first (passing `projectPath` and `query`) BEFORE reading raw files.
Full Documentation & Benchmark Report
For complete setup guides, dual-state File Tree behavior, and benchmark results, see the Full GitHub Repository README.
Environment Variables
CTXSLICE_DISABLE_WASM_FETCH=1: Skip downloading .wasm language parsers and run purely on the built-in zero-network state-machine structural parser.
License
MIT