R270 · AI-built software and its verification › Test oracles for agent-written code

shrink-anything: delete dead code, keep the cut only if your tests still pass

Read the original

toolingopen-sourcetest-oracleagent-coding

Source: the EL4CTEO/shrink-anything README, surfaced by a practitioner post the same day. MIT licensed, npm and crates.io, early repo. Benchmark numbers are the project's own.

The problem it names

Coding agents write code faster than anyone deletes it. Functions nothing calls, files nothing imports, packages nothing uses, assets nothing shows: the agent reads all of it on the next task, CI builds it, users download it. The framing that makes this more than a lint rule is the token one — every line removed is a line the agent stops reading. The README claims 46% fewer tokens to read on its demo app.

The mechanism

One command: shrink-anything go --agent claude -- npm test, where the part after -- is any command of yours that fails when the app is broken. Or step by step: scan (changes nothing), cut -- <check>, task --agent <cli> for the judgment calls, weigh dist, verify, undo, report, doctor.

The safety design is the interesting part, and it is the same shape as record-and-replay porting tools:

The README's own demo is the honest case: a test reaches a function through a name read from a data file, nothing in the code mentions it, the cut broke the test, and that one cut was put back.

Detection by counting names, not call graphs

WhatHow it decidesScope
Dead codeevery mention of the name is inside its own definition; any other mention anywhere — another file, a string, a template, a config — keeps it19 languages
Dead filesno other file names itPython, JS/TS, PHP, Ruby, Dart, Lua
Unused dependenciesnothing imports it or runs its commandsnpm, pnpm, yarn, bun, Cargo, pip, Go modules
Dead weightan image, font or sound no code, config or README names; duplicate filesany project
Duplicatesthe same code twice, however named or laid out19 languages, merged by the agent

The design choice: counting mentions instead of building a call graph. A count can only miss dead code, never invent it, and it behaves the same in every language. Every text file — HTML, Vue, Svelte, YAML, SQL, templates — is read for mentions, so a function used only from a template survives. Adding a language is one table entry describing comments, strings, block ends and definitions: about twenty lines.

This is a deliberate trade of recall for soundness, which is the right direction when the action is deletion. It also means the tool is weakest exactly where dynamic dispatch is heaviest — reflection, string-built names, dependency-injection containers — and that is where the test gate is doing all the work.

Reported results

ProjectBeforeAfter
TypeScript cart106 lines, 5 files, 3 deps58 lines, 3 files, 1 dep (−45%)
Python shop142 lines, 8 files86 lines, 7 files (−39%)
Go store89 lines55 lines (−38%)
Static site build output913 KB398 KB (−56%)

These are demo projects with planted dead code, which the README says, and it adds that real projects should expect less per run and more over time. Treat them as a demonstration that the loop works, not as an expected reduction.

Failure modes to plan for

Review checklist before running it on a real repo

  1. Is the suite green and non-flaky right now? Run it twice.

  2. Does the check fail when the app is actually broken — not just when it fails to compile?

  3. Is this a library? If so, is --lib set, and are public exports the contract you think they are?

  4. Start with scan and read the list. Anything surprising on it is a sign the mention-counting missed a dynamic path.

  5. Keep --aggressive off for the first pass, and treat its output as a reviewed list rather than a commit.

  6. Review the resulting diff as a human change. "Tests passed" is the floor, not the review.

Integration

A Claude Code plugin, a built-in MCP server exposing eight tools (shrink_scan, shrink_cut, shrink_task, shrink_verify, shrink_undo, shrink_report, shrink_weigh, shrink_status), and a skill that teaches any agent the loop. --agent accepts any command that reads a prompt on stdin, and without it the task file is handed to whatever you use — a reasonable hedge against tying a build step to one vendor's CLI.

Connections

See R270 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.