Shrink a prompt with compression

When a repo is too large for your budget, compression strips the heavy parts of your Rust source โ€” function bodies, test modules, doc comments โ€” while keeping the structure a model needs: signatures, types, and the shape of each file. Because it runs per file before token counting, the counts gnaw reports already reflect the compressed size, so you can see the saving immediately.

Pick a level

--compress takes one of three presets, ordered by how much they remove. The names describe aggressiveness, not quality.

LevelRemovesKeeps
light#[cfg(test)] modulesEverything else
moderate+ function and method bodies (โ†’ { /* ... */ })Signatures, types, doc comments
full+ doc commentsSignatures and types
gnaw . --compress moderate
gnaw . --compress full -O context.md

A stripped body becomes { /* ... */ }; a stripped test module becomes a // [test module stripped] marker, so the output stays valid-looking and obviously elided.

Fine-tune with --compress-strip

--compress-strip takes a comma-separated list of toggles that apply on top of the preset (or on their own, with no preset). Prefix any token with no- to turn it off.

TokenEffect
testsStrip #[cfg(test)] modules
fn-bodiesStrip all function/method bodies
doc-commentsStrip /// and /** */ doc comments
private-bodiesStrip bodies of non-pub functions only, keeping public ones
# Full, but keep the doc comments
gnaw . --compress full --compress-strip no-doc-comments

# No preset โ€” just drop tests and private bodies
gnaw . --compress-strip tests,private-bodies

Unknown tokens are rejected with a suggestion rather than ignored โ€” a silent typo would quietly misreport your token budget, so gnaw fails loudly instead.

Make it the default

Set compression once in .gnawconfig (in the working directory, or globally at ~/.config/gnaw/.gnawconfig) and every run picks it up:

[compression]
strip_test_modules = true
strip_fn_bodies = true
strip_doc_comments = false
strip_private_bodies = false

Precedence is --compress preset โ†’ config [compression] โ†’ none, with any --compress-strip toggles layered on top of whichever base applies. So a preset on the command line overrides the config file for that run, and --compress-strip can still adjust the result.

Check the saving

Pair compression with the token map to see where the tokens went, or just read the per-run total โ€” since compression happens before counting, the number you see is the compressed cost.