Deterministic local-first CLI for inspecting, linting, and compacting prompt/context files.
ctxc compact --text "You are helpful. You are helpful."Expected compacted result:
You are helpful.
No model calls. No semantic rewriting. Only explicit deterministic transforms.
npm install -g context-compiler-cliPrimary command:
ctxc --helpCompatibility alias:
context-compiler --help# Preview deterministic compaction (no file writes)
ctxc compact --text "You are helpful. You are helpful."
# Analyze structure/tokens/warnings
ctxc analyze --text "You are helpful. You are helpful."
# Lint deterministic prompt debt
ctxc lint --text "You are helpful. You are helpful."
# Optimize pipeline preview
ctxc optimize --text "You are helpful. You are helpful." --dry-run --diffPath and directory shortcuts:
ctxc @prompt.md
ctxc @prompts/
cat prompt.md | ctxc| Command | Purpose | Writes files by default |
|---|---|---|
ctxc compact |
Front door: preview deterministic compaction and see resulting text | No (preview-only) |
ctxc analyze |
Inspect structure, token counts, and warnings | No |
ctxc lint |
Detect prompt/context debt with deterministic rules | No |
ctxc optimize |
Advanced pipeline workflow (--write, --check, transform controls) |
No (--write required) |
compact supports file, directory, --text, and --stdin like other commands.
ctxc compact examples/basic-prompt.md
ctxc compact examples --diff
ctxc compact --text "You are helpful. You are helpful."
echo "You are helpful. You are helpful." | ctxc compact --stdincompact reuses optimize results and JSON shape; it does not introduce a separate output schema.
optimize is intentionally more operational than compact. Use compact for quick preview and readability; use optimize when you need pipeline controls, check mode, and explicit write workflows.
Default tokenizer is char. Optional real model-family tokenizer: o200k_base.
Use CLI override (highest precedence):
ctxc compact --text "You are helpful. You are helpful." --tokenizer o200k_base
ctxc analyze examples/basic-prompt.md --tokenizer charOr use the built-in command to set it without editing JSON:
ctxc config set tokenizer.default o200k_base
ctxc config set tokenizer.default charThis creates or updates context-compiler.config.json in the current directory. Existing config keys are preserved. Use --config <path> to target a specific config file.
Or set it manually in config:
{
"tokenizer": {
"default": "o200k_base"
}
}Precedence (highest to lowest):
--tokenizerCLI flagtokenizer.defaultincontext-compiler.config.json- Built-in default (
char)
Notes:
charis stable and lightweight.o200k_baseis more faithful for its model family than char fallback.- Neither option is a universal tokenizer for every model/runtime.
Inputs are explicit:
- positional path => file or directory
- raw text =>
--text "..." - stdin =>
--stdin
No guessing between path and raw text.
Current optimize/compact transforms:
remove-exact-duplicatescollapse-repeated-sentencescollapse-formatting-rulestruncate-tool-outputtrim-oversized-examples
Protected blocks are preserved exactly:
<!-- context-compiler: protect:start -->
Do not modify this section.
<!-- context-compiler: protect:end -->By default, config is loaded from context-compiler.config.json in the current directory.
ctxc analyze examples/basic-prompt.md --config examples/context-compiler.config.json
ctxc compact examples/basic-prompt.md --config examples/context-compiler.config.jsonUnknown lint rule IDs and unknown transform IDs fail clearly.
Use when you need:
- deterministic, local prompt/context cleanup
- explainable token savings
- CI-friendly checks (
--fail-on,--check,--max-tokens)
Do not use when you need:
- semantic rewriting/paraphrasing
- model-in-the-loop prompt generation
- plugin/integration workflows
pnpm test
pnpm typecheck
pnpm build
pnpm benchmarkOr:
pnpm verifyBenchmark is local fixture-based measurement. Use it for same-machine comparisons, not universal performance claims.
git clone https://github.com/4l1n/context-compiler.git
cd context-compiler
pnpm install
pnpm build
pnpm cc compact --text "You are helpful. You are helpful."pnpm cc is an in-repo alias. Outside the repo, use installed ctxc.
MIT