/code-structure:code-structurefrom code-structure
Rules for where code goes and how it is shaped so humans can follow it - layer separation, package and file ownership and growth, function shape, helper granularity, and control flow and state a reader can trace. Use before writing code (plan), before committing (self-check), and when reviewing a change (review).
Ships in code-structure. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Optimize for how fast a new reader can tell what the code does and where to change it, not for line count. Where the repository's conventions are stricter, follow them.
Read references/examples.md before applying the rules: it shows bad, better, and not-a-finding cases for each.
A function over 30 lines (not counting error checks), or any function branching on business rules, is exactly one of:
Mixing I/O with multi-branch business logic is a finding. Fix: extract the policy and leave an orchestrator that reads as a list of steps.
util, helpers, common, shared, or misc is a finding.rg for an existing one. A near-duplicate is a finding; cite the existing path:line.device_auth*, mcp_*, transform*, upstream_*) or number more than ~15. Adding a new group to it, or 150+ non-test lines to one group, is a finding. Fix: that group moves to its own package named after its concept, in a first commit that changes no behavior, and the old package calls it through one or two functions. State that only the group reads moves with it, off the shared struct.analytics.go, is a finding. Move it to a file named after what it does, or rename the file.mail., billing., or accounts. call) against the name of the file it was added to. An orchestrator file (account.go, auth.go) may call secondary concerns like analytics or mail; a file named after one concern (analytics.go) must only do that concern.get, find, check, is, and validate functions don't write, send, or mutate.Each helper costs the reader a jump.
Replace nested ternaries with if/switch or a lookup, repeated conditions with one named predicate, and generic names (data, result, tmp) with domain names. Delete commented-out code. Don't compress a readable block into a dense one-liner.
For each event (exit, error, cancel, timeout, retry) and each piece of mutable state the change adds or reroutes, trace where it is created, which functions it passes through, and where it is used. A reader should answer "what happens when X?" by opening one function.
let x; const f = () => x; x = make(f)) marks one of the above. Find which.An R7 finding states the trace (reset is defined in A, passed to B, stored in a set, called from C) and the smaller shape. If you can't name a shape with fewer hops, it is not a finding.
Before editing: list the files you'll touch with wc -l, and for each new function or type name its layer (R1) and package (R2). Decide up front where new code goes when a file or package is over the R2 or R3 thresholds, and where each new piece of state lives (R7).
On git diff HEAD before committing: re-run wc -l on touched files and apply R3, then check every new or changed function against R1, R4, R5, and R7, and the changed lines against R6. Don't refactor untouched code. Run the tests after structural changes.
Read touched files in full and list every touched package (ls, wc -l) at base and head. Check R7 and R2's overloaded-package rule first: neither shows in a diff read hunk by hunk. A finding must be caused or worsened by the change: a file or package that was already large is context, growing it past the R2 or R3 thresholds is a finding. Never ask a change to split code it doesn't touch.
Format: path:line Level (rule): the problem in at most two sentences, then the concrete move (what to extract, where it goes, what to inline). With no findings, say so in one line.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub dvcrn/skills --plugin code-structure