/bonsai:auditfrom bonsai
Prunes CLAUDE.md files to the lines a fresh session cannot derive, every cut backed by evidence. Run when the files have grown without review.
Ships in bonsai. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Judge every line of every in-scope CLAUDE.md against one question: what mistake does a session make without it? If the answer is "none", the line is inventory. The goal is a file where every line changes behavior, however long the file ends up.
Throughout the audit, "cut" means recording a cut verdict in the report. No file changes before approval, no exceptions.
Default scope is the current project: its root CLAUDE.md, nested CLAUDE.md files, and the rule files they point to. User-level and ancestor-directory files load in every project, so include them only when the user asks, and evaluate them against a session in an arbitrary project (codebase greps and CI checks do not apply to them). Exclude vendored code, build output, and worktree copies everywhere: from the inventory and from every grep.
Not everything called "referenced" is deferred. Classify each file by its load class before judging it: read ${CLAUDE_PLUGIN_ROOT}/references/load-model.md. Judge a scope-triggered line against a fresh session working in its scope, and count no saving for a move behind an @path import. Read ${CLAUDE_PLUGIN_ROOT}/references/delivery.md too: a kept line goes to the strongest rung that holds it.
Check every line against this list before anything else. A match is a KEEP and skips the rest of the audit, with two exceptions. Step 1's claim check still runs on it, since a protected line can name a deleted path or a stale value: a wrong claim is fixed in place and the line stays. And a rule a committed check holds may still fall in step 3, because the tool guarantees it. A safety prohibition stays whatever enforces it.
${CLAUDE_PLUGIN_ROOT}/references/load-model.md defines them ("never force-push", "never run the seeder against a shared database")A file under about 40 lines gets a single pass: read it whole, check its claims (step 1), apply steps 2 through 8 line by line, and present the result as one round when it fits the budget in ${CLAUDE_PLUGIN_ROOT}/references/rounds.md. Probes and the panel still decide what the steps route to them. A small file only means few candidates reach them. Above that, the steps below run as written, and every probe counts against the budget in ${CLAUDE_PLUGIN_ROOT}/references/probe.md.
First read the repository's agents setting (${CLAUDE_PLUGIN_ROOT}/references/decision-memory.md). When it is missing, or holds [] while the repository has a root AGENTS.md, ask whether the repository serves agents other than Claude Code (Codex reads only AGENTS.md, from the root down to where it starts), and store the answer. A --headless run asks nothing: it counts a root AGENTS.md as Codex served, cuts no pointer that rests on the answer, and says so in the PR body. Step 6 and every move read it.
List each in-scope file with its load class and est. token cost (label every figure "est."). Include equivalent rule files other agents consume (.cursor/rules, AGENTS.md and the like) in the inventory and the dedup pass, even though edits target CLAUDE.md files. Migrating a foreign-format rule file into the project's native format is never part of an audit apply: record it as a proposal and act only on explicit user approval.
Then show the load map: for a few common tasks (an edit in each scoped area, a new file in one, a command run from the root), the files that load and their est. tokens. Count a path-scoped rule whose globs match a large share of the repository's files (about a third or more) as resident, labeled "broad globs", since nearly every task loads it. When ~/.claude/bonsai/loads/<owner>/<repo>.jsonl exists, an optional hook logged real loads there: count which files load from it instead of estimating, as ${CLAUDE_PLUGIN_ROOT}/references/load-model.md says, and label those counts "measured". Tokens stay estimates from each file's size. A fork clone without an upstream remote logs under the fork's <owner>/<repo>, so read that log too.
Then check every concrete claim, since a stale fact in a line the audit keeps survives every later step. Skip the lines a step 2 class cuts on sight: they go whatever their facts say. From every other line, extract each checkable claim: a path, a class, method or function name and signature, a command and its flags, a config key or value, an enum case or status value, a count, a named test, a default. Verify each against the repository with a read or a grep, never from memory, and record the evidence. A wrong claim becomes a change:
fix that corrects the fact in place.fix that cuts the clause.Each is a false or stale claim, routed as "Report delivery" says. The check is mechanical, so batch it: one fresh low-effort agent per group of files, handed the files and the claim list above, or the auditor's own greps on a small scope. It sits outside the probe cap (${CLAUDE_PLUGIN_ROOT}/references/probe.md). Report the totals with the inventory, so the user sees the coverage: 412 claims checked, 9 wrong.
Cut what a fresh session reconstructs with a few tool calls:
composer install, npm install) and standard CLI usage, discovery commands included (php artisan list, <command> --help, npm run) on an entry point a session finds on its own. A hint that names a project-specific executable a session would not find stays. A step that requires a command at a given moment ("list the commands before adding one, so you never add a duplicate") is a workflow rule, judged like any other line## Models section restating what ls of the directory shows). A class earns a mention only where the line carries a constraint the code cannot show at a glance, and that line lives with the behavior it governsTest: delete the line and name the mistake a session in the file's scope now makes. No mistake, no line. A line that fails the test but matters in one identifiable situation moves instead of dying (see "Move to the rung that holds it").
The six classes above cut on sight. A cut for any other derivability claim needs a derivability probe first, run as ${CLAUDE_PLUGIN_ROOT}/references/probe.md prescribes: one fresh low-effort agent gets a task the line governs, in the file's scope, without the line, and whether it derives the fact or makes the mistake is the verdict. The loaded auditor has read the line and cannot un-read it, so its own guess is not evidence. A line in an always-resident file never probes clean: record that and send the candidate to the capability-floor panel instead.
Evidence must hold everywhere the file is read. A pointer that fails only where the audit runs (a tool the auditor's settings deny, a skill the auditor lacks, a URL the auditor cannot open) may work for every other consumer of the file: record it as an open question for the user.
Never trust a claim (yours or the file's) that "the linter handles this". Inspect every enforcement surface: formatter and linter configs, static analysis, architecture or convention tests, git hooks, CI workflows, and the project's committed .claude/settings.json. Record which surfaces you checked per rule. Then judge each rule's check against ${CLAUDE_PLUGIN_ROOT}/references/enforcement.md:
/bonsai:bake, which closes the gap or adds the check./bonsai:bake in next, for a test of the allowed transitions. Only /bonsai:guard proposes the state machine, from a review finding (${CLAUDE_PLUGIN_ROOT}/references/delivery.md, "Domain redesigns"), so audit proposes no refactor.Expect surprises in both directions: rules believed enforced that are not, and rules believed prose-only that a formatter already fixes.
The codebase teaches conventions whether or not the doc repeats them. Grep before judging, scoped to the subtree the audited file governs and to first-party code only, and report numerator, denominator, and the exclusions used:
A rule that names nothing greppable (commit style, PR flow, shell habits) is path-free: skip this step and send it straight to step 5.
Judge for the weakest model that reads the docs: the model auditing them is usually stronger. A borderline block is a heading section or standalone bullet that steps 3 and 4 left undecided. Panel only those.
Spawn three independent low-effort agents per block. Each gets the repo path, the verbatim block, and one concrete task the block would govern, and answers: "Would this block change what you produce for this task? KEEP or CUT, one reason." Majority wins, ties are KEEP, the verdict is final.
Tell each panelist to answer the verdict only and never perform the task: a floor model handed a block will otherwise start executing it.
Resolve every pointer's target first and flag the broken ones. Then judge the phrasing: a pointer carries exactly two things, the trigger (when to read) and the path. Never a content summary. Summarizing the target loads its vocabulary into every session, which defeats the deferral. Record these as rewrites.
Discriminator: does this phrase help decide WHEN to read the file (routing key, keep) or does it describe what you WILL LEARN there (content summary, cut)?
<!-- Cut: content summary, the target's contents leak into every session -->
See docs/payments.md for the retry flow, webhook signatures, refund windows, and the idempotency-key format.
<!-- Keep: trigger + path -->
Read docs/payments.md before touching payment or refund code.
Exception: a fact stays in the pointer when the session needs it to pick WHICH target applies. A discriminator routes, so it stays.
Two pointer shapes go on sight, because an agent reads every CLAUDE.md and rule file and nobody clicks in them:
../README.md in docs/CLAUDE.md becomes README.md). The link spells the path twice, and one whose text and target differ names two files. A link to a heading in the same file becomes the heading's name, and one to a heading in another file names both ("the Modals section of resources/CLAUDE.md"). An @path import is a load directive and stays bare. Record it as a rewrite.${CLAUDE_PLUGIN_ROOT}/references/load-model.md). A pointer stays for work that starts with a command or acts outside the files (running a migration, a deploy, a git operation). A root pointer also stays when the stored agents setting names an agent that reads it there (${CLAUDE_PLUGIN_ROOT}/references/load-model.md, "Other agents"). A pointer that stays is a path in backticks.<!-- Cut: the link and the discovery command. The nested file loads on the first file touch in that directory -->
Internal utilities live under [`app/Console/Commands/Acme/`](app/Console/Commands/Acme/CLAUDE.md); run `php artisan list acme` to see them all.
<!-- After -->
Internal utilities live under `app/Console/Commands/Acme/`.
When the repository's CLAUDE.md lint already bans path links, a path link is a violation of that check: say so on the rewrite. Otherwise record a /bonsai:bake candidate that adds the ban, so the rewrite cannot regress.
A pointer between two scoped files is a placement smell. Flag two shapes: a nested CLAUDE.md whose directory holds no other first-party file, since it never loads on its own and sessions reach it only through pointers, and two scoped files that point at each other. Find the first with the orphan check of ${CLAUDE_PLUGIN_ROOT}/skills/split/SKILL.md (step 4, "The other direction"). Record each as a call, asked as a question that offers a merge into one file or a new scope covering both, and add /bonsai:split to next: split makes the move, with its load-path check.
The same rule governs skill frontmatter descriptions: triggers and routing keywords stay, mechanics and step lists move to the body. Safety and precedence clauses stay in the description ("never mutates remote state", "OVERRIDES the global skill") because they change the invocation decision itself.
State each fact once, at the smallest scope that covers its readers. When a rule repeats across files, keep the copy closest to where it applies, keep the load-bearing identifier resident (the helper name, the command), and defer the rationale to one referenced doc.
The auditor wrote every rewrite and judges it with the same blind spots. Before the report, run a meaning check (${CLAUDE_PLUGIN_ROOT}/references/probe.md) over every rewrite, move and extract: a fresh agent gets the current text, the proposed text and the stated reason, verifies against the repository, and answers "same" or "drift" per change. On a drift, revise the change once to address the finding and check it again. A change that still drifts goes to the user as a call, with the finding on its card.
Phrasing gets judged only after a line earns its keep, against the standard in ${CLAUDE_PLUGIN_ROOT}/references/rule-writing.md. Every specific detail in a kept line (a class inventory, an enumerated list, a count) is either load-bearing, meaning generalizing it would change what a session does, or a liability that drifts as the code moves. When a kept line carries non-load-bearing specifics, record a rewrite: drop those specifics, keep the load-bearing identifiers verbatim, and change nothing else. A rewrite never widens scope, weakens the boundary, or adds advice, and every identifier it keeps gets verified against the codebase like any claim in step 1.
Two senses of "generic" live in this skill. Step 2 cuts generic best practices because they pin no boundary. Generic here means phrased at the pattern level while still pinning one. When dropping the driftable specifics would leave nothing a session cannot derive, the line was inventory all along: cut it. Precision earns the keep, genericity makes it last.
<!-- Rewrite: the inventory drifts as validators are added, the boundary does not -->
Our validators are EmailValidator, PhoneValidator, and VatValidator. Never write a new validator for a rule one of these already covers.
<!-- After: same boundary, load-bearing path kept, inventory dropped -->
Never write a new validator for a rule one in app/Validators already covers.
A kept line that another rung of ${CLAUDE_PLUGIN_ROOT}/references/delivery.md holds better moves there verbatim, as a move change whose destination names the rung (${CLAUDE_PLUGIN_ROOT}/renderer/README.md):
scoped-file: a rule that governs one area, placed by split's grep and load-path check (${CLAUDE_PLUGIN_ROOT}/skills/split/SKILL.md, steps 2 and 3).code: knowledge a session needs at one file or command, as a docblock, a command description or --help, or a check's message.skill: a procedure walked start to finish, placed by the skill rung in ${CLAUDE_PLUGIN_ROOT}/references/delivery.md.html-comment: a "why" only a reviewer needs, kept in a CLAUDE.md (${CLAUDE_PLUGIN_ROOT}/references/rule-writing.md).deferred-doc: content one situation needs. See below.root: a scoped line that governs the whole project.A move to code, skill or html-comment edits code or settings, or hides the line from sessions, so it is always a call. When the agents setting names an agent that reads only the root file, a move to scoped-file or skill also leaves a one-line path pointer where that agent reads it (${CLAUDE_PLUGIN_ROOT}/references/load-model.md, "Other agents").
Content needed only in a specific situation moves verbatim to a referenced file, leaving a one-line read-trigger behind ("read X before doing Y"). A move must beat the pointer it leaves behind: content no longer than its read-trigger stays resident. Reuse the project's existing referenced-doc location (detect it from current pointers) instead of inventing a new one. Deletion is only for content that fails step 2 outright.
Environment-conditional content is its own extract class: sentences that bind only in some execution environments (a cloud sandbox, CI, containerized local dev). No load mechanism triggers on environment, so path scoping cannot help, and a hook that adds context fails the bar in ${CLAUDE_PLUGIN_ROOT}/references/delivery.md (R6) unless a missed line leads to an action that cannot be undone. Only then flag a hook, as a call. The pattern is one resident discriminator line per environment naming the trigger and the doc ("cloud session? read X before running anything"), with everything conditional moved to that doc verbatim. Classifying each sentence by the environments it governs is judgement the loaded auditor shortcuts: run a classification probe (${CLAUDE_PLUGIN_ROOT}/references/probe.md) with the single question "which execution environments does each sentence govern", and treat every section with mixed answers as an extract candidate.
Read ${CLAUDE_PLUGIN_ROOT}/references/decision-memory.md before routing, then pick the delivery as ${CLAUDE_PLUGIN_ROOT}/references/decision-artifact.md prescribes under "Delivery". For the page, build it with the renderer that reference names. Each cut, rewrite, move or extract verdict is one change. Route it:
/bonsai:bake in next, and a placement smell /bonsai:split.kept, with nothing to decide.On a first run the order is audit, then bake, then split. So until the repository has a finished bake run (${CLAUDE_PLUGIN_ROOT}/references/rounds.md, "Continue a run"), next holds /bonsai:bake, and until it has a finished split run, /bonsai:split after it.
Keep the audit a single pass: verification is the expensive part, and findings interact (a false-claim fix changes the same lines a later trim rewrites). Present the decisions in rounds as ${CLAUDE_PLUGIN_ROOT}/references/rounds.md prescribes. A correctness fix edits only the affected lines, leaving structure and wording untouched, so no diff mixes a factual fix with a taste rewrite. An open question rides in the round whose changes it gates.
Present each round in full before editing anything. Per change: the verdict, the exact text affected, and the evidence (surfaces checked, grep ratio, panel vote, second check). Approval arrives as the decisions message from the page, or as the user's reply in plain text. Only edit after approval, and apply as ${CLAUDE_PLUGIN_ROOT}/references/rounds.md prescribes: one commit per cause on a branch, with a PR, when the user ships as a PR.
After applying, re-resolve every pointer you touched. Close the report with before and after est. token totals per file, listing deferred (moved) tokens separately from deleted ones.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub publicala/claude-plugins --plugin bonsai6 skills in this plugin
/bakeConverts CLAUDE.md rules and recurring review findings into automated checks, and removes the prose once a check holds the rule. Run once enough rules have accumulated to be worth automating./feedTurns recurring corrections (conversation, intake entries, recent commits) into CLAUDE.md rules. Run after a working session or a review round./guardTurns review findings into guardrails, one pull request per check, cut from the default branch. Run with PR numbers or URLs after a review round, or once over every PR of a finished run, while the PRs are open or after they merged. A follow-up pass over review threads hands its PRs here before replying. Opens pull requests and replies on review threads.