Code written for human reading carries massive overhead that serves neither the machine executing it nor an LLM reasoning about it. We demonstrate 5 levels of compression, each preserving 100% functionality.
Human code has 4 types of waste:
| Type | Example | % of Click | Machine value |
|---|---|---|---|
| Ceremonial | Docstrings, Sphinx markup, version notes | 23% | Zero |
| Structural | Blank lines, import repetition across files | 19% | Zero |
| Syntactic | Verbose conditionals, redundant names | ~10% | Near-zero |
| Architectural | 16 files Γ 16 import blocks, scattered related code | ~5% | Negative (harder to reason about) |
Total non-logic overhead: ~47% of lines, ~40% of tokens.
Rule: Remove everything that isn't executed.
Techniques:
- Strip all docstrings (""" blocks inside functions/classes/modules)
- Strip all comments (# lines)
- Collapse multiple blank lines to single separators
- Remove trailing whitespace
- Keep all code, all imports, all type hints exactly as-is
What stays: Every executable line, every import, every type annotation. What goes: Docstrings, comments, excessive blank lines. Verification: AST comparison (identical minus Expr(Constant(str)) nodes).
Rule: Same behavior, fewer tokens.
Techniques:
- Merge single-use helper functions inline
- Simplify conditional chains (if/elif β dict lookup where applicable)
- Use comprehensions instead of loop-append patterns
- Deduplicate repeated patterns (e.g., Click has many "process params" loops)
- Remove platform-specific code that's dead on the target platform (but we keep _winconsole.py as it IS part of Click β note its size)
- Merge trivial one-liner methods into callers where called once
- Use walrus operator (:=) where it eliminates duplicate calls
- Combine related assignments
What stays: All public API, all behavior, all edge cases. What goes: Verbose patterns that can be expressed more densely. Verification: Full Click test suite must pass.
Rule: Related logic lives together. Imports amortized. Machine-first headers.
Techniques:
- Merge 16 files β 4-6 shards by logical domain:
_shard_core.pyβ Context, Command, Group, Parameter, Option, Argument_shard_types.pyβ ParamType hierarchy, type conversion_shard_ui.pyβ terminal UI, progress bars, pager, prompt, style_shard_completion.pyβ shell completion (Bash/Zsh/Fish)_shard_util.pyβ helpers, compat, testing, formatting
- Each shard gets
# AX: TAG | SUM: one-line summaryheader - Shared imports declared once per shard (saves ~200 tokens per eliminated file)
__init__.pywith lazy loading for public API compatibility- Logically cohesive: related classes/functions stay together regardless of LOC
What stays: All public API, all behavior, all internal structure. What goes: File boundaries that scattered related code, redundant imports. Verification: Full Click test suite + import compatibility.
Rule: Replace human docs with machine-queryable metadata.
Techniques:
# SYM:headers mapping abbreviated names to semantics# CALLS: fn1, fn2/# CALLED_BY: fn3dependency annotations- Contract signatures:
# CONTRACT: (str, int) -> Command | raises UsageError - Section markers:
# --- PARAMETER PROCESSING ---for rapid navigation - This ADDS tokens vs L3, but replaces the NEED for docstrings entirely
What stays: Everything from L3 + navigation metadata. What goes: Nothing removed vs L3 (this level adds navigability). Verification: Full Click test suite + metadata accuracy.
- 200K context β 150K usable tokens
- Original Click: 82K tokens = uses 55% of context for ONE library
- L3 compressed: ~30K tokens = uses 20% of context
- An LLM can now hold Click + 2 other libraries simultaneously
- Docstrings served Sphinx docs generation. In 2026, LLMs generate docs on demand.
- Comments explained "why" β but code that needs explaining is code that needs rewriting.
- The shard system groups related code, making navigation EASIER not harder.
- 82K β 30K tokens = 63% fewer input tokens per API call
- At $3/MTok (Claude), that's $0.16 saved per full-library read
- Over 1000 reads in a research mission: $160 saved on ONE library
The M2M benchmark tested DATA format compression (human prose vs structured M2M). This benchmark introduces CODE compression β fundamentally different:
- Architectural compression β merging files eliminates import overhead
- Logic compression β rewriting algorithms, not just reformatting
- Navigation metadata β Cortex-style annotations replace docstrings
- Verification via test suite β not Q&A scoring but real execution
- Public reproducibility β anyone can pip install click, run tests, verify
-
"You just removed docs" β L1 alone IS just removing docs. L2-L4 go far beyond. Counter: We measure tokens, not just LOC. L2 logic changes compress pure code too.
-
"Click tests might not cover everything" β True. Counter: We run the official test suite. If Click trusts it, so can we.
-
"Compressed code is unreadable" β For humans, yes (L2+). That's the point. Counter: L4 adds machine navigation. LLMs read L3 BETTER than L0 (proven in M2M benchmark).
-
"This only works for Click" β Single project, might not generalize. Counter: We plan Flask and Bottle as follow-ups. Different architectures, same techniques.
-
"Import amortization is trivial" β Each file saves ~10-20 tokens of imports. Counter: 16 files Γ 15 tokens = 240 tokens. Not huge, but compounds with other savings.