A semantic context pre-processor that gives coding agents only the code they need.
Prune your codebase to only what's relevant before the LLM sees it.
Inspired by MiniMax M3's MSA architecture — sparse attention with pre-filtering.
Instead of attending to everything, identify which blocks matter and drop the rest.
ContextSlice is a sparse context compiler for AI coding agents.
-
Before: Your coding agent sees 80 files and guesses what matters.
-
After: ctxslice emits 12 relevant files/chunks under a 40K token budget.
Cursor dumps your whole codebase into context. Most of it is noise for any given task.
ctxslice runs before you open Cursor. It:
- Chunks your codebase at AST level (function/class granularity, not file-level)
- Embeds chunks into a persistent local vector index
- Scores each chunk across three signals:
- Semantic similarity to your task description
- Whether the chunk is in the import graph of your active file
- Whether the chunk overlaps with your current git diff
- Packs the highest-scoring chunks into a token budget
- Outputs a
.ctxslice.mdfile — drag it into Cursor as@context
pip install -e .ctxslice run "add pagination to UserList"ctxslice run "add pagination to UserList" \
--file src/components/UserList.tsx \
--tokens 40000ctxslice run "fix auth token refresh" \
--file src/auth/TokenService.java \
--output context/auth-task.mdctxslice indexctxslice statsctxslice index --forcectxslice clearFull documentation — installation, step-by-step usage with Cursor, Claude, and GitHub Copilot, CLI reference, and troubleshooting: ContextSlice-UserDocumentation.md
Release notes — see RELEASE_NOTES.md for changes by version.
- Run
ctxslice run "your task" --file your-active-file.ts - Open Cursor
- In the chat, type
@and select.ctxslice.md - Ask your question — Cursor now has only the relevant parts of your codebase
Or add to .cursorrules:
Always read @.ctxslice.md for context on the current task.
| Signal | Weight | What it captures |
|---|---|---|
| Semantic similarity | 55% | Cosine distance between task prompt and chunk embedding |
| Import graph | 25% | Is this file a direct import of your active file? |
| Git diff | 20% | Does this chunk overlap with your current changes? |
Composite score thresholds:
-
= 0.60 -> HIGH — included, full content
-
= 0.35 -> MEDIUM — included, full content
- < 0.35 -> DROPPED — not emitted
Files in the import graph that didn't make either tier appear in the DEPENDENCY SURFACE section (collapsed, for type/interface correctness).
ctxslice is written in Python but works on any language codebase — the language of your project has nothing to do with the tool's runtime.
AST-level chunking (function/class granularity) is supported for:
TypeScript, JavaScript, Java, Python, Go, Rust, Kotlin, Swift, C/C++, C#, Ruby
Files with other extensions are not skipped — they fall back to whole-file chunks and still contribute to context, just without method-level splitting.
- First run: index build takes 1–3 minutes for a large repo (embedding model downloads ~22MB)
- Subsequent runs: incremental — only changed files are re-embedded, typically 2–5s
- Deleted files are automatically purged from the index on each run; no manual cleanup needed
- Index stored at
<repo>/.ctxslice/index/— add to.gitignore --tokensminimum is 1000; default is 40000
.ctxslice/
.ctxslice.md
ctxslice/
├── chunker.py # AST-level splitting via tree-sitter
├── index.py # Persistent ChromaDB vector index + sentence-transformers
├── signals.py # Git diff signal + import graph signal
├── scorer.py # Composite scoring + token-budget packing
├── renderer.py # .ctxslice.md output formatter
└── cli.py # Typer CLI (run / index / stats / clear)
If you find ContextSlice useful, you can support the project:
👉 https://buymeacoffee.com/nishchya
It helps keep the project alive and growing.
MIT — see LICENSE.