Skip to content

borghei/occam

Repository files navigation

occam, manage both ends of the token loop

Fewer tokens in. Fewer tokens out. Same quality.

Every agent turn spends tokens twice. The input it reads back is test logs, install spam and build noise. The output it writes is your code. Most tools trim one side and self-report the win. occam trims both, a deterministic engine on the input and an always-on rule on the output, with a real ledger and a reproducible benchmark behind every number.

License: MIT Claude Code plugin Works with

What you get, measured

occam trims both ends of the token loop: about 83% fewer input tokens before the model reads them, with 100% of the signal kept, and about 49% fewer output tokens from the always-on rule, at the same quality.
  • Input: 83% fewer tokens, 100% of the signal kept. Test, install and build noise gets compacted before the model reads it. Every line that matters lives through the trim, each failure, warning and summary. A failing run is never cut.
  • Output: about half the tokens, same correctness. In an A/B on real tasks (same model, rule on vs off) the rule cut output by 49% at identical test results. The benchmark scores a careless one-liner 0.833, it fails a trap, against a right-sized solution at 1.000.
  • 12/12 reliability gates green. Reproduce every number yourself: node benchmark/in.mjs and npm test.

Install (one line)

Claude Code (recommended, wires both ends for you):

/plugin marketplace add borghei/occam
/plugin install occam@occam

Every other agent. Install the CLI once, then turn the rule on per agent:

npm i -g github:borghei/occam       # gives you the `occam` command

occam init codex                    # Codex / OpenAI
occam init cursor                   # Cursor
occam init copilot                  # GitHub Copilot
occam init windsurf                 # Windsurf
occam init cline                    # Cline / Roo
occam init claude                   # Claude Code (rule only)

The output rule is on right away. occam init also tells the agent to run noisy commands through occam run, so the input side compacts too:

occam run npm test

On Codex, occam init codex goes further and wires a PreToolUse hook that does the wrapping for you. Trust it once in Codex with /hooks.

How it works

Output, an always-on rule. One short paragraph, injected every turn, that makes the agent write the right amount of code. Reach for stdlib or the native feature first, collapse boilerplate, add nothing nobody asked for. But never cut validation, error handling, security or accessibility. One source (RULES.md) generates every agent's format, so the rule can't drift. scripts/generate.mjs --check guards it in CI.

Input, a deterministic engine. A pure compactor trims noisy output before the model reads it. Strip ANSI, drop the PASS/ noise, dedupe repeats, truncate while keeping head and tail. It knows a test run from an npm install, and on a non-zero exit it hands back the full output untouched. On Claude Code this runs on every command automatically (the plugin's PostToolUse hook). Codex gets a PreToolUse hook from occam init codex that rewrites noisy commands to occam run. Other hosts can't rewrite output or commands from a hook, so the installed rule tells the agent to use occam run <cmd> itself. Same engine, same trim.

After install you also get /occam:review to shrink what you just wrote, plus /occam:audit, /occam:debt and occam gain for your running total.

Safe to leave on

  • Failures pass through whole. Debugging never loses the trace.
  • Exit codes preserved. Your &&, || and CI gates still behave.
  • Idempotent, labeled and lazy. It never double-trims, tags every result and skips the trim when it wouldn't save tokens.

Prove it yourself

npm test                  # 12/12 reliability gates
node benchmark/in.mjs     # input: tokens removed + signal retained (colorized)
node benchmark/chart.mjs  # regenerate the chart above from those live numbers
cd benchmark && node score.mjs tasks/csv-sum examples/csv-sum.naive.mjs      examples/usage.naive.json
                node score.mjs tasks/csv-sum examples/csv-sum.rightsized.mjs examples/usage.rightsized.json

The naive answer is shorter and cheaper, yet it scores lower, 0.833 vs 1.000, because it breaks on a quoted comma. Less code is good. Wrong code isn't. Correctness counts for half the score, so you can't win by cutting corners.

License

MIT © borghei. Issues and PRs welcome. Edit RULES.md, never the generated files, then run node scripts/generate.mjs.

About

Less tokens, fast coding, from the laziest coder. An always-on right-sizing ruleset for AI coding agents.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors