Tidy

From melodic-software/claude-code-plugins · View interactive version

Tidy is an AI agent skill from the GitHub repository melodic-software/claude-code-plugins. When the bundled simplify skill resolves in this session, prefer it for the current diff; this skill for proactive lane hunts. Hunts one rotated lane for Beck tidyings and ships one structure-only PR. Use when: 'tidy', 'tidy up', 'boy scout', 'polish', 'small refactors', 'improve gradually', 'clean

How to use this skill

Skill file

Repository context. Gather first

<!-- BEGIN GENERATED: gather-block. Edit docs/conventions/gather-block/block.md, then run scripts/sync-gather-block.py -->

Run each command below as its own Bash call, all sent together in one message (worktree isolation).

Keep any bound in the command's own pipe (output limits).

Unless this section says otherwise, treat a failure (not a repository, git unavailable) as an unknown value and carry on. Keep these as body calls, never ## Pre-computed context lines (gather-block convention).

<!-- END GENERATED: gather-block -->

Pre-computed context

Open chore/tidy-* PRs: !${CLAUDE_SKILL_DIR}/scripts/open-pr-count.sh 2>/dev/null | grep -E '^(Open tidy|Throttle)' || echo unknown

Comment settings (team then personal layer, one line per key): !${CLAUDE_SKILL_DIR}/scripts/comment-settings.sh 2>/dev/null | grep -E '^comment_(posture|keep_list)' || echo "(settings unavailable)"

Variables

Arguments: $ARGUMENTS

HARD path exclusions: ${user_config.hard_exclusions} (unexpanded, empty, or any value outside enforce and advisory means enforce).

Comment posture: comment_posture resolves through four layers, lowest first, a later one winning:

the default auto, userConfig (${user_config.comment_posture}), the team file

<home>/code-tidying.yaml and the personal override <home>/code-tidying.local.yaml (<home> the

repository's bound convention home, else docs/conventions), the last two from the settings line

above (${CLAUDE_SKILL_DIR}/scripts/comment-settings.sh). auto means necessary; strict, balanced and conservative read as explanatory, aggressive as

necessary. An unexpanded or empty userConfig value is unset, and any other value outside auto,

none, necessary, explanatory is named with its layer and dropped. The posture decides what

tidyings Beck 14 and P-5 may add (reference/tidyings.md).

Purpose

Tidy is the proactive Boy Scout loop: what small structural improvements can one slice of the codebase safely take today, shipped as one tight PR that never mixes structural and behavioral change? It applies Kent Beck's Tidy First? tidyings, separated from behavioral changes by commit and by PR ("Always one or the other, never both at the same time."), under the Boy Scout Rule, and keeps to structure-only work because autonomous agents introduce defects measurably more often in unhealthy code (Tornhill / CodeScene). Its value is rotated lane discipline, a scope budget, structure-only commits, and research before editing.

Not: /simplify, which tightens the conversation's recent diff, while tidy hunts a lane independent of recent activity; batch-simplify, which sweeps a time window, a branch, or the repository in waves (on docs it owns factual staleness across the whole doc set in one pass, while tidy's docs-prose lane owns incremental structural prose work under a scope budget); issue-tracker work, since tidy never starts from a filed item and files its overflow as deferred items; a docs fact-checker, since tidy improves structure, not factual accuracy.

Action Router

Parse $ARGUMENTS to determine the action. The argument hint shows dry-run without its

[<lane>|<glob>...] to stay within its length budget; the table below lists every form.

| Argument | Action | Use case |

|----------|--------|----------|

| (empty) | Smart default | Infer the most appropriate lane from current branch / recent commits / git status. If the inference is ambiguous, pause and ask the user. Otherwise proceed as if <lane> was passed. |

| <lane> (from the catalog below) | Targeted lane run | Load the lane file, run the full Workflow on that lane's scope. |

| <glob>... | Ad hoc scope | No lane covers the files. Run the full Workflow on those globs per Ad hoc scope when no lane fits below. Combines with dry-run. |

| dry-run [<lane>] | Plan + present, no edits | Run Phases A-D (triage, explore, research, hunt). Present the prioritized findings table and the proposed PR scope. No edits, no branch, no push, no tracker items. The user reviews and decides whether to proceed. |

| self-update | Maintainer lane | Shorthand for <lane>=self-update. Operates on this plugin's own files. Valid only in a working-tree checkout of the plugin (marketplace clone or --plugin-dir), never an installed copy. Manual-merge always. |

| help | Print this Action Router + lane catalog | Diagnostic / orientation. |

| override (flag, combines with any row above) | Lift the GLOBAL HARD path list for this run, behind an enumeration gate | The user wants this lane's tidyings to reach a path the HARD list would otherwise drop (agent config, a CI workflow, lint config). Strip the token before reading the rest of $ARGUMENTS; match it whole, never as a substring, and treat ./override as a path. Because a lane is a glob set rather than a named file, Phase D enumerates the specific HARD paths it intends to touch and takes a go-ahead on that list before Phase E edits any of them; non-interactive, the run reports the list and proceeds without those edits (reference/exclusions.md section 4). dry-run override produces the enumeration alone. Path entries only: the behavioral guards, the work-tracking entries, SELF-UPDATE EXTRA HARD, and the override machinery itself hold regardless. Every lifted path is named in Phase H's report with the channel that lifted it. |

| in-place or in-place=commit (flag, combines with the smart default, <lane>, and override) | Run on the current branch, no branch, no PR | A caller already holds the branch and PR (a repo-sweep playbook, a feature branch). Strip the token before reading the rest of $ARGUMENTS, matched whole like override. Phase B stays on the current branch and refuses the default branch; Phase E stages tidyings without committing; Phase H opens no PR and posts no comment, and prints its report to the user instead. in-place leaves the changes staged; in-place=commit makes one commit of them. The backlog throttle does not apply; every other gate (exclusions, scope budget, verification, self-review) still runs, measured on the staged diff. |

| --repo <repo> (and the other target forms; combines with any row above but in-place and help) | The run once per repository | Strip the target-form tokens before reading the rest of $ARGUMENTS, then run per Over several repositories below. |

Over several repositories

With no target form, the run covers this checkout, as it always has. A target form (--repo,

--repos-from, --owner, --fleet, --skip, or the same request in words) selects several

repositories, which resolve, count, fan out and merge as

CODE0 "Target

forms", "Resolving repositories", "Fan-out" and "Merging findings" say. Each repository runs the

whole Workflow, Phases A to H, with its root anchored. What differs here:

.claude/tidy-lanes/ over the bundled lane. A named lane neither layer defines there is reported

skipped. With no lane, the smart default infers it from that repository's recent commits at

origin/HEAD; where the inference is ambiguous, ask once with every such repository listed, or,

non-interactive, report that repository skipped. self-update runs only in a repository that is

this plugin's working-tree checkout; every other is reported skipped.

chore/tidy-<lane>- PR in that repository, and the backlog throttle counts that repository's

open chore/tidy-* PRs, so one repository's backlog never stops another's run. The pre-computed

lines describe this checkout only: the per-repository subagent runs open-pr-count.sh and

comment-settings.sh with that repository's root as its working directory, and reads that

repository's .claude/code-tidying/exclusion-overrides.md.

Phase H PR and follow-up comment are that repository's, made one repository at a time, as

target-scope.md "Writes stay per repository" says: for a repository other than the session's

own, in a worktree that repository's convention creates, never its main checkout. The scope

budget and the overflow filing hold per repository, each item filed in its own repository's

tracker. in-place names the session's current branch, so it does not combine with a target

form.

that ships lists each repository's PR, or the reason it opened none.

Lane catalog

A lane is a glob-scoped slice of the repo, defined in a lane file that specifies scope globs, watch-for tidyings, lane-specific exclusions, verification commands, default Conventional Commits type, and preferred research sources.

Lane resolution. A lane named <lane> has up to two layers:

  1. ${CLAUDE_PROJECT_DIR}/.claude/tidy-lanes/<lane>.md, the consuming project's own lane definition, if present
  2. ${CLAUDE_PLUGIN_ROOT}/skills/tidy/lanes/<lane>.md, the bundled generic lane

With no project layer, the bundled lane resolves alone. With one, the project layer's own ## Merge semantics section governs (per the config-cascade contract):

Bundled lanes cover surfaces that look the same in most repos; templates scaffold the ones that do not. To define a project lane, copy the closest template from ${CLAUDE_PLUGIN_ROOT}/skills/tidy/templates/ into .claude/tidy-lanes/<lane>.md and fill in the scope globs and watch-for patterns. The catalog is the union of both locations: list .claude/tidy-lanes/*.md (if the directory exists) plus the bundled lanes when printing help.

Declared deviation: no user-global layer or *.local.* personal override. Unlike the config-cascade contract, this surface resolves only the team layer (.claude/tidy-lanes/<lane>.md) over the bundled lane, because lane globs, verification commands, and watch-for patterns are anchored to this repo's layout, CI, and stack, and the bundled lane is already the portable baseline. Personal variation is limited to lane names the team does not track: keep an uncommitted .claude/tidy-lanes/<lane>.md (never added to the index), not a *.local.* sibling, so rotation and catalog discovery stay on one filename per lane. Gitignoring a path the team already tracks does not make it personal; setup documents that escape hatch and its limits. Merge granularity within the team+bundled pair is unchanged.

Bundled lanes:

| Lane | File | Covers |

|------|------|--------|

| shell-tooling | lanes/shell-tooling.md | Shell/PowerShell scripts under the project's tooling directories |

| docs-prose | lanes/docs-prose.md | Markdown prose: skill bodies, docs |

| self-update | lanes/self-update.md | This plugin's own files (maintainer checkout only) |

Bundled templates (copy + adapt into .claude/tidy-lanes/):

| Universal pattern | Template |

|------|------|

| Framework/library core that downstream code depends on | templates/dependency-root-lane.template.md |

| Hosting infrastructure, logging, registration, service defaults | templates/host-wiring-lane.template.md |

| User-facing applications + their tests | templates/apps-lane.template.md |

| Non-primary-language services / MCP servers / sidecars | templates/polyglot-services-lane.template.md |

Read the resolved lane file in full at Phase A entry; do not infer scope from this table.

Ad hoc scope when no lane fits

When no bundled or project lane covers the target files, pass globs in place of a lane name: dry-run <glob>... to plan, <glob>... to run. An argument that names no catalog lane and contains / or a glob character is ad hoc scope. The run then:

Workflow (8 phases)

Run in order. Each phase has one job, and every phase runs whatever the tidying's size.

Phase A. Triage

  1. Resolve the lane from $ARGUMENTS per the Action Router.
  2. Load the lane per Lane resolution and read the full file(s), merging both layers when the project lane declares ## Merge semantics. The resolved lane owns scope globs, watch-for list, lane-specific exclusions, verification commands, Conventional Commits type, and preferred research sources.
  3. Resolve the HARD-path override channels per reference/exclusions.md section 4 (the override argument, .claude/code-tidying/exclusion-overrides.md, then hard_exclusions) and write down the lifted set with the channel that lifted each entry. Empty is the normal answer.
  4. Backlog throttle (skipped under in-place): if the pre-computed context above reports Throttle active: yes (open chore/tidy-* PRs at the upkeep_max_open limit, reference/config.md), stop, surface a one-line note, and exit cleanly. It is a stop signal, not a warning: reviews are backed up, so do not queue one more.
  5. Find the anchor commit: the most recent merged chore/tidy-<lane>- PR for this lane (or git log --grep if none merged yet), the "what has drifted since the last sweep" baseline.

Phase B. Branch

git checkout -b chore/tidy-<lane>-YYYY-MM-DD origin/<default-branch>. The date suffix disambiguates daily reruns. Never commit tidyings directly on the default branch; a feature-prefixed branch keeps the structure-only PR reviewable and revertable.

in-place: create no branch; stay on the current one. If it is the default branch, or the index already holds staged changes, stop and tell the user: the staged set this run hands back (or commits under in-place=commit) must be the tidyings alone.

Phase C. Explore + research

Understand before changing; this holds even for a one-line tidying, since rework from skipped research costs more than the research.

  1. Explore the lane's scope globs: if the discovery plugin is enabled, invoke /discovery:explore (if enabled) via the Skill tool on the lane scope; otherwise read 5-10 representative files in the lane to understand current patterns, conventions, and existing tidyings.
  2. Research current best practice for the lane's stack: if the discovery plugin is enabled, invoke /discovery:research (if enabled) via the Skill tool using the lane file's preferred-source list; otherwise do a focused inline research pass (official docs + the lane's preferred sources) before editing.

Phase D. Hunt + prioritize + scope-budget enforce

  1. Read reference/tidyings.md for the full taxonomy (Beck 15 + Fowler 5 + prose tidyings P-1..P-6 = 26 entries).
  2. Hunt: walk the lane's scope globs for instances of the lane's watch-for tidyings. Classify each candidate: tidying type, file, line range, estimated LOC delta, confidence.
  3. Build a prioritized findings table. Each row carries a Basis:, verified with the file:line, tool output, or Phase C source URL it rests on, or judgment (never for a consequential change: cross-repo, shared infrastructure, irreversible, or security; one that cannot be verified is withheld and routed to the overflow list as an open question naming the evidence that would settle it). Contract: CODE4; full convention: recommendation-basis.
  4. Apply the scope budget: the target and hard cap in CODE0, with tidy's priority order and greedy selection in reference/scope-budget.md (spokes write the plugin directory as <plugin-root>, which is ${CLAUDE_PLUGIN_ROOT}). Take the highest-priority subset that fits.
  5. Override enumeration gate, only for paths lifted by the override argument. List those specific HARD paths the surviving candidates would touch, each with its tidying, and take a go-ahead on that list before Phase E. Interactive: the user answers. Non-interactive: report the list and continue with those argument-lifted candidates dropped, since a blanket token is not a decision about paths nobody has seen yet. Paths lifted by hard_exclusions=advisory or by .claude/code-tidying/exclusion-overrides.md skip this gate: those channels already are a standing decision, and a non-interactive run must honor them. A dry-run presents the argument-lifted enumeration and stops there. An argument-lifted path that no candidate touches never reaches this gate.
  6. Overflow → file one work item per deferred candidate using the template in reference/scope-budget.md: invoke /work-items:track add (if enabled) via the Skill tool, else read the house style (${CLAUDE_PLUGIN_ROOT}/reference/issue-house-style.md), apply it, and run gh issue create (or present the list to the user when no tracker is reachable). In dry-run mode, present the overflow list instead. Dry-run never files tracker items or causes any other external side effect.

Zero applicable improvements: clean exit with a one-line note and no PR. Do not produce empty-PR churn.

Phase E. Implement

  1. Use the Edit tool, never sed -i: a tidying must be structure-only, and an Edit replaces one exact string in a file you have read, where a sed pattern can rewrite a match you never looked at.
  2. One commit per logical tidying. Atomic, structure-only. Beck: "Each commit should fit comfortably in your head, on your screen, and in the team's review pipeline."
  3. git add <path> only, never -A or .: WIP from a parallel session can sneak in, even on a tidy branch.
  4. Pre-flight every file with git diff <path> before staging. After staging, use git diff --cached <path> to confirm only the tidying went in.
  5. Commit messages follow Conventional Commits with the lane's default type (e.g., refactor: for code lanes, docs: for prose lanes, chore: for tooling).
  6. in-place: stage each tidying per steps 3-4 but do not commit; Phase H handles it.

Phase F. Verify

Tidying is behavior-preserving, so verification confirms exactly that: run the project's build + tests + linters for the affected ecosystem (the lane file's verification commands; the consuming project's own CLAUDE.md / rules may name canonical commands). Red branch → fix or abort cleanly. Never push red. A tidying that broke a test or build was secretly behavioral: back it out; it belongs in a different PR with proper test coverage.

Phase G. Self-review + simplify

  1. Review the full diff yourself (git diff origin/<default-branch>...HEAD; under in-place, git diff --cached) hunting for accidental behavior change, scope creep, and convention violations. Drive real findings to zero before push.
  2. Simplify the touched files yourself, and only files already edited: reuse, simplification and efficiency cleanups that stay structure-only. Do not invoke the bundled /simplify (see "Mutation gate" below). Rebuild and re-verify after these edits. Under in-place, stage what changed and re-review git diff --cached so Phase H ships it.

Self-review by the producing context is enough here: a fresh-context verifier is the rule where a verdict is subjective, and Phase F is an objective build/test/lint pass/fail. A change that turns out behavioral fails Phase F and is backed out, never verdict-reviewed into acceptance.

Phase H. Ship

in-place: open no PR and post no comment. in-place leaves the tidyings staged; in-place=commit makes one commit of them, titled per the format below (via /source-control:commit (if enabled)). Print to the user the title, the body content /source-control:pull-request create (if enabled) would write, and the audit-trail sections below that would have gone to the PR, then stop.

Otherwise, never call git commit or gh pr create directly. Phase E already committed the tidyings, so what is left is PR creation, and that has a canonical gate (issue-linkage resolution, injection-safe body assembly, a pre-create check for a valid closing keyword or explicit opt-out) that a bare gh pr create skips.

If the source-control plugin is enabled, invoke /source-control:pull-request create (if enabled) via the Skill tool. Its stage-and-commit step is a no-op here (the tree is clean from Phase E), so it goes straight to rebase-check, issue-linkage resolution, and gated PR creation. Supply it this PR's title and the facts the body needs (lane, tidyings, anchor commit, verification commands run and their results); it writes the body from the repo's configured sections. Tidy's own audit trail goes in a follow-up comment (below), not the PR body:

Title:

<lane-default-type>(<lane-area>): <what was tidied>

Examples:

Body facts to supply:

/source-control:pull-request create (if enabled) reports the created <pr_number>. Immediately post one follow-up comment on that PR with tidy's audit trail:

gh pr comment <pr_number> --body-file - <<'EOF'
## Tidyings applied

<table: tidying type, no bare `#` → file → line range → LOC delta>

## Deferred items

<links to filed issue numbers, if the scope budget capped the run>

## Lifted HARD exclusions

<table: path → channel that lifted it (override argument | overrides file | hard_exclusions=advisory)>
EOF

The comment is never optional when a PR was created, and "Tidyings applied" is never empty then (no PR is created when there is nothing to tidy). Omit "Deferred items" when nothing was deferred and "Lifted HARD exclusions" when nothing was lifted; never post either as an empty table. A run that lifted a path and cannot post that table has not met the override contract; back the lifted edits out rather than shipping them unnamed.

If source-control is not enabled, apply the same invariants inline: resolve issue-linkage before writing a closing keyword (Closes #N only after confirming issue #N exists in this repo, e.g. gh issue view N; otherwise state No related issue: <reason>), assemble the body via a quoted heredoc (<<'EOF') plus parameter-expansion concat rather than an unquoted <<EOF (which would execute any $(...) embedded in prompt-derived text), and refuse to call gh pr create until the assembled body contains a valid closing keyword or the opt-out marker. In this fallback path only, the Tidyings-applied / Deferred-items / Lifted-HARD-exclusions sections stay in the PR body itself.

Then monitor checks (gh pr checks <n> --watch) until green. Address review-bot findings: verify each against the current code, fix the correct ones, rebut the incorrect ones with evidence. This skill never merges: the repository's merge lane, where it has one, or a person does.

Global HARD/SOFT exclusions

Three exclusion tiers gate every lane. The full lists live in reference/exclusions.md; read it at the start of every run. This summary is orientation only.

  1. GLOBAL HARD: paths not touched by default, regardless of lane, and lifted only through the override channels below: agent/CI/hook configuration (.claude/** in full, any script wired as a hook command in .claude/settings.json or .claude/settings.local.json wherever it lives, .github/workflows/**, git-hook manager config, .mcp.json, lint configs like .editorconfig) plus every path the consuming project's own rules declare protected.
  2. GLOBAL SOFT: areas an autonomous run cannot verify safely (browser-rendered UI, interactive auth flows, DB migrations against real instances, IDE-only flows, and areas the project marks unverifiable). Routed to the deferred-items list in Phase D unless an interactive user explicitly overrides.
  3. SELF-UPDATE EXTRA HARD: added when <lane>=self-update. Protects the skill's contract surface: frontmatter, the Action Router / Workflow / Lane-catalog sections, lane-file ## Scope / ## Watch-for patterns / ## Lane-specific extra exclusions blocks, and ${CLAUDE_PLUGIN_ROOT}/reference/pr-scope-budget.md, a generated copy of the shared convention whose numbers change only there. It is the only thing between an autonomous self-update run and this skill's own contract surface.

Behavioral exclusions apply whatever path an edit targets: DB migrations against real instances (safe only against an ephemeral test DB), breaking API changes, HTTP route signature changes, MCP tool schema changes, branch-protection or security-workflow rule changes, and work-tracking exclusions (items another agent claimed, items with an open linked PR, items labeled blocked/deferred). A candidate that would alter any of these is behavioral: file an issue instead.

Overriding the HARD path list. Every tier-1 path entry is overridable through three channels: the override argument (this run), the hard_exclusions userConfig option (this operator), and a tracked .claude/code-tidying/exclusion-overrides.md of root-relative globs (this repository). Precedence per path: argument, then repository file, then userConfig, then enforced. Full contract, file shape, and collision rules: reference/exclusions.md section 4. Nothing outside the tier-1 path entries is reachable: the behavioral guards, the work-tracking entries, tier 2 SOFT, and tier 3 EXTRA HARD hold at every setting. Lifting is not silent: a run that lifted anything names every lifted path and its channel in the Phase H report; a run that cannot produce that line enforces instead.

Enforcement across phases: Phase A seeds path-validation from the HARD list and resolves the three override channels into a lifted set. Phase D classifies candidates against HARD (drop unless lifted) and SOFT (defer). Phase E validates every Edit / Write target path against the HARD list minus the lifted set. The self-update lane additionally applies the EXTRA HARD list during Phases D and E, and the override channels do not reach it.

Deferred items contract

Full template: reference/scope-budget.md. Every item the scope budget cuts becomes one filed work item, titled per the house style, whose body carries rationale, file list, scope estimate (LOC + files), and a link to the parent tidy PR (under in-place, the branch name). Phase H's "Deferred items" follow-up comment (or, without source-control, the PR body's own section; under in-place, the printed report) links every filed item by number.

Boundary with the bundled `simplify` skill

simplify cleans up code and applies its fixes; for what it reviews and the targets it takes, read the /simplify row in All commands. This skill hunts unfiled structural drift across a rotated, glob-scoped lane regardless of recent activity, under a scope budget, and ships one structure-only PR. When simplify resolves, prefer it for refining a diff that exists (what you just wrote, a path, a PR); prefer this skill when nothing has changed yet and the question is what small structural improvement one slice can take today. batch-simplify owns the same cleanup at sweep scale.

Mutation gate. simplify edits the working tree. This skill makes its own scope-budgeted edits and commits them as tidyings, so never chain into a simplify run on this skill's behalf; the two anchors differ and their diffs would mix.

Bundled surfaces are gated by settings, environment, plan, and host; this section states what to do when one resolves, never that it is present. The four-part records live in reference/bundled-simplify.md.

Next

/source-control:babysit-prs

It carries the opened tidy PR through CI and review findings; the merge is the repository's merge lane's or a person's.

Gotchas

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.