ratchet
A code-size budget for your repo that only goes down.
A real run on pallets/click; the bloated change is a scripted patch standing in for an agent. Full commands and output: docs/examples.md.
Try it in 30 seconds (nothing is enforced until you wire up a hook or CI):
pip install ratchet-size
ratchet init # records today's size as the ceiling
ratchet check # passes now; refuses once code grows past it
Why
Coding agents are good at adding code and bad at deciding not to. Ratchet gives the repo a line budget that can only shrink. When a change would go over it, the agent is refused in plain words: it trims the code, or stops and asks you, since only a human can raise the budget.
Quickstart
Remove it any time: uninstall.
- Install:
pip install ratchet-size(orpipx install ratchet-size) - Baseline: run
ratchet initanywhere in the repo, and commit the.ratchet.jsonit writes. - Wire up your agent: tell it: "Set up ratchet in /path/to/repo
by following
https://raw.githubusercontent.com/krishansubudhi/ratchet/main/SETUP-FOR-AGENTS.md"
Or install the agent plugin, which adds the hooks and
/ratchet:setup. In Claude Code, run these two commands:/plugin marketplace add krishansubudhi/ratchet, then/plugin install ratchet@ratchet. In Gemini CLI:gemini extensions install https://github.com/krishansubudhi/ratchet.
A real Gemini CLI run after step 3, sped up: refused, it asks for a grant instead of cutting code, declines "commit it", and commits once granted (cast).
Only code files count, split into source and tests groups; docs never
do. Your own commits are not blocked.
Gate pull requests (optional): copy
integrations/github/ratchet.yml to
.github/workflows/ratchet.yml; it runs uses: krishansubudhi/ratchet@v0.
Using it? Add the badge:
[](https://github.com/krishansubudhi/ratchet)
Strict mode (optional): to block your own commits too, install the git pre-commit hook.
Badge (optional): ratchet badge writes .ratchet/badge.json; commit it
(rerun to refresh) and paste the snippet from ratchet badge --print-markdown
into your README.
What a refusal looks like
A real headless Claude Code run, replayed: the commit is blocked by 1 line, the agent stops and asks instead of cutting code, and commits once a human grants it (docs/agent-demo.sh).
ratchet: refused -- source grew 56 lines past its limit (556 / 500)
app/api.py +40
app/store.py +16
Fix it one of two ways:
1. remove 56 lines of code (dead code, duplicates), or
2. stop and ask a human to allow the growth (humans only -- never run this yourself):
ratchet grant +56 --group source --reason "why"
Do not edit .ratchet.json or .ratchet-grants.jsonl to get past this.
Refused again on the same change? Stop here: report these numbers to a human instead of cutting more and resubmitting.
Humans see the same facts with "allow the growth" instead of "ask a human". Other wordings: How it works.
Count tokens, not lines
A line budget has a loophole: squeezing code onto fewer lines makes it look
smaller without removing anything, and an agent pushed against the ceiling
will find that. A token budget closes it. Running a formatter, joining
lines or splitting them barely moves the count, so the only way back under
is to actually remove code. On one real 35,000-line Python repo,
ruff format added 34% to the line count and 0.1% to the token count.
Turn it on when you create the baseline:
ratchet init --unit tokens
That writes "unit": "tokens" into .ratchet.json, and every ceiling,
per-file limit and grant is then counted in tokens. From a real run
(trimmed; init also writes the groups and file_ceilings):
{
"version": 1,
"unit": "tokens",
"max_file_lines": 2400,
"ceilings": {"source": 26, "tests": 21}
}
A refusal then reads source grew 16 tokens past its limit (42 / 26) and
says roughly how many lines that is in your repo. Words, numbers and
punctuation are a token each, whitespace is free, and strings and comments
cost one token per five characters. Details:
Configuration.
Lines stay the default. A config with no "unit" key counts lines exactly
as before, so existing setups keep working unchanged.
More
- Code growth, 2023 to 2026: line counts for 24 open-source repos; mature projects grew faster in 2026 than in 2023 to 2025.
- How it works / FAQ: what counts, the four rules,
ratchet budget, grants, refusal wording, exit codes, requirements - Configuration:
.ratchet.json, groups, slack - Integrations: Claude Code plugin, Cursor, Codex, aider, pre-commit, GitHub Actions, strict mode, CI
- Uninstall
License
Apache-2.0. Copyright 2026 Krishan Subudhi.
Metadata
Release files for ratchet-size 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ratchet_size-0.3.0.tar.gz | 29.3 kB | With provenance | Details for ratchet_size-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ratchet_size-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ratchet_size-0.3.0-py3-none-any.whl |
Total release size: 54.3 kB
Release files / ratchet_size-0.3.0.tar.gz
| Download URL | ratchet_size-0.3.0.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18f2d9ee674ec522f94d09e8034213a45bcd17d18ec2272d4af5c2c0a2f49eec
|
|
BLAKE2b-256 checksum How to use checksums |
3622a5d75f200d6f0f4e92a24673bbe3c1a73cfc3a5446b73c763bb5a266afa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / ratchet_size-0.3.0-py3-none-any.whl
| Download URL | ratchet_size-0.3.0-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
494ea4b6c7872c548644da2d59a7958ec9abaacd36d28933d7786a15c456bf4c
|
|
BLAKE2b-256 checksum How to use checksums |
6f300a55b7b947f67747d8eb7f4a0bd42cb2c55a7cea42c2a15033a2ec14937c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for ratchet-size 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ratchet_size-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.