Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

llcortex/ContextSlice

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctxslice

License: MIT

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.


Concept

Cursor dumps your whole codebase into context. Most of it is noise for any given task.

ctxslice runs before you open Cursor. It:

  1. Chunks your codebase at AST level (function/class granularity, not file-level)
  2. Embeds chunks into a persistent local vector index
  3. 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
  4. Packs the highest-scoring chunks into a token budget
  5. Outputs a .ctxslice.md file — drag it into Cursor as @context

Install

pip install -e .

Usage

Basic run

ctxslice run "add pagination to UserList"

With active file and token budget

ctxslice run "add pagination to UserList" \
  --file src/components/UserList.tsx \
  --tokens 40000

Custom output path

ctxslice run "fix auth token refresh" \
  --file src/auth/TokenService.java \
  --output context/auth-task.md

Pre-build the index (first run in a new repo)

ctxslice index

Check index status

ctxslice stats

Force full re-index

ctxslice index --force

Wipe index

ctxslice clear

Full 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.


Using the output in Cursor

  1. Run ctxslice run "your task" --file your-active-file.ts
  2. Open Cursor
  3. In the chat, type @ and select .ctxslice.md
  4. 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.

Signals & scoring

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).


Supported languages

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.


Performance

  • 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
  • --tokens minimum is 1000; default is 40000

.gitignore

.ctxslice/
.ctxslice.md

Architecture

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)

☕ Support

If you find ContextSlice useful, you can support the project:

👉 https://buymeacoffee.com/nishchya

It helps keep the project alive and growing.


License

MIT — see LICENSE.

About

Semantic context pre-processor. Prune your codebase to only what's relevant before the LLM sees it.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.