Lightning-fast context engine for LLMs. Pack your entire codebase into LLM-ready context in milliseconds.
$ ctx pack ./my-project --budget 200k --model claude-sonnet
ctx pack complete
Tokens [████████████████████████████████████████] 99.2%
198.4k / 200.0k
Files 265 packed (386 skipped, 651 scanned)
Model Claude Sonnet
Cost $0.5953 per request
Time 0.1s
Output stdout
Every developer working with LLMs needs to feed code context into prompts. Existing tools are slow (Node.js/Python overhead), lack budget awareness, and don't prioritize files intelligently.
ctx is a single Rust binary that:
- Packs 651 files / 1.4M tokens in 0.1s (parallel tokenization via rayon)
- Smart budget packing — automatically selects the most important files to fit your token budget
- Multi-model cost estimation — know exactly what each request will cost before sending it
- Zero dependencies — single binary, no runtime required
cargo install --path .Or build from source:
git clone https://github.com/sebasnallar/ctx.git
cd ctx
cargo build --release
# Binary at ./target/release/ctx# Pack current directory (outputs markdown to stdout)
ctx pack .
# Pack with a token budget
ctx pack ./src --budget 100k
# Pack for a specific model with cost estimation
ctx pack . --model gpt4o --budget 200k
# Output as XML (Repomix-compatible)
ctx pack . --format xml
# Write to file
ctx pack . --output context.md
# Copy to clipboard
ctx pack . --clipboard
# Pipe-friendly (no progress output)
ctx pack . --quiet | pbcopySee which files are eating your token budget:
$ ctx count ./src --model claude-sonnet
>> Token count for Claude Sonnet (42 files in 0.1s)
File Tokens %
src/main.rs 2669 32.0%
src/cli.rs 1355 16.2%
src/output.rs 1250 15.0%
src/packer.rs 981 11.7%
...
Total: 8.4k total tokens | Est. cost: $0.0251# Pack files changed since main branch
ctx diff
# Pack files changed since a specific branch
ctx diff --base develop
# Pack only staged files
ctx diff --stagedWhen you set a --budget, ctx doesn't just grab files randomly. It uses a priority system:
| Priority | File Type | Examples |
|---|---|---|
| 0 (highest) | Project config | Cargo.toml, package.json, pyproject.toml |
| 1 | README | README.md |
| 2 | Entry points | main.rs, index.ts, app.tsx |
| 3 | Types/schemas | types.ts, *.d.ts, *.proto, *.graphql |
| 4-7 | Source code | By nesting depth (shallower = higher priority) |
| 8 | Config files | *.yaml, *.toml, *.json |
| 9 | Tests | Files containing test or spec |
| 10 | Docs | *.md, *.txt, *.rst |
- Markdown (default) — Code blocks with language detection, file index
- XML — Repomix-compatible format with CDATA sections
- Plain — Simple text with file separators
Create a .ctx.toml in your project root:
budget = 100000
include = ["src/**/*.rs", "Cargo.toml"]
exclude = ["**/generated/**", "**/vendor/**"]Or a global config at ~/.config/ctx/config.toml.
| Model | Tokenizer | Cost/1M input tokens |
|---|---|---|
claude-opus |
cl100k_base | $15.00 |
claude-sonnet (default) |
cl100k_base | $3.00 |
claude-haiku |
cl100k_base | $1.00 |
gpt4o |
o200k_base | $2.50 |
gpt4-1 |
o200k_base | $2.00 |
gpt4-1-mini |
o200k_base | $0.40 |
gemini-pro |
cl100k_base* | $1.25 |
gemini-flash |
cl100k_base* | $0.15 |
generic |
cl100k_base | $3.00 |
*Gemini uses its own tokenizer; cl100k_base is used as an approximation.
ctx respects .gitignore by default. For additional exclusions, create a .ctxignore file:
# .ctxignore
node_modules/
*.generated.ts
dist/
coverage/
MIT