code-health
Skill0 starsChanged 15 days agoMITView on GitHub
Use when reviewing a diff or a PR, before adding code to a file over ~800 lines or a function over ~80, when the user says a file is huge, spaghetti, copy-pasted, unmaintainable or needs splitting / refactoring / cleanup, when a project has no .code-health.json yet, or when setting up ./check.sh. Structural review rules, a ratchet gate (no file, function or copied block may be new over a limit or grow) and a safe recipe for splitting giant files. Script: scripts/code_health.py (uv, lizard).
10 other projects use a version of this.
Adopted by
Most recently taken up by
- TDesktop-x64/tdesktoptheir own version, first seen Nov 9, 2026
- jocarrd/crux-agentstheir own version, first seen Nov 8, 2026
- outcast1000/viboplrtheir own version, first seen Nov 8, 2026
- khoralabs/skillstheir own version, first seen Nov 1, 2026
- kukuruzka165/materialgramtheir own version, first seen Oct 17, 2026
- telegramdesktop/tdesktoptheir own version, first seen Oct 17, 2026
Used with
Projects with it also use dependency-watch, perform-task and 3 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
telegramdesktopSkilldependency-watch
Audit Telegram Desktop dependencies on freshly fetched origin/dev for releases and security fixes, including upstream lag and backport candidates in patched forks. Use for the scheduled dependency monitor or an explicitly requested dependency report.
Also in 3 projects that use this
telegramdesktopSkillperform-task
Resolve, start or resume, implement, review, test, and publish exactly one existing ai-tdesktop task by short slug or full dated id, including rare blocked retries and split-required results. Use when the user invokes $perform-task or /perform-task with a known task name, or when the continue scheduler delegates one selected task. Runs standard review lenses with fast applicability bailouts and selects task-specific domain and evidence instruments without selecting additional work.
Also in 3 projects that use this
JerovinoSkillprocess-inbox
Processes tasks.md inbox items by triaging each one to its proper location in the vault
Also in 3 projects that use this
Trejon-888Skillcontinue
Load project context, alignment audit, status check, suggest next action. Auto-invoke at session start, after context switches, or when user says 'continue', 'pick up where we left off', 'resume', 'what's next', 'status check', 'what now'.
Also in 3 projects that use this
raineSkillrebase
Rebase the current branch with smart conflict resolution.
Also in 3 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- telegramdesktop/tdesktop★ 33ksame name
- TDesktop-x64/tdesktop★ 3ksame name
- kukuruzka165/materialgram★ 1.2ksame name
- ramboz/jig★ 7same name
- outcast1000/viboplr★ 6same name
- jocarrd/crux-agents★ 4same name
- khoralabs/skills★ 1same name
- lepinkainen/skills★ 1same name
- mcabreradev/hermes-sdd-agency★ 1same name
- PrairieAster-Ai/quality-butler★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- apps-configSkill
- architect-flowSkill
- bootstrap-aiSkill
- csharp-toolsSkill
- headless-ui-smokeSkill
- launch-and-deploySkill
- macos-local-codesignSkill
- mobile-webSkill
- portable-projectSkill
- review-sweepSkill
- tech-researchSkill
- test-tiersSkill
- threat-modelingSkill
- ui-craftSkill
- ui-doctorSkill
- ui-motionSkill
- ui-stress-testSkill
- ui-variantsSkill
- web-accessibilitySkill
- web-art-directionSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 51
Add to ./check.sh (and the same guard to check.ps1), so every agent and the verifier subagent run it:
- Distinctive: line 63
Size: No new file over 800 lines, function over 80, complexity over 20.
- Very specific: line 89
Never as a drive-by in a feature task.
- Distinctive: line 107
Stop and ask when a split forces an API change other code (or another repo) depends on.
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code health
AI-written code rots in one direction: everything gets appended to the file that already works, and the second feature that needs the same logic gets a copy. Nobody notices until a file is 15 000 lines and one function 4 000. This skill stops the growth (a gate every agent runs) and pays the debt down (a refactor recipe), one project at a time.
The script
scripts/code_health.py, next to this file — the same on every machine (a link on macOS /
Linux, a copy refreshed at session start on Windows). Needs only uv.
CH=~/.agents/skills/code-health/scripts/code_health.py # same file under ~/.claude/skills
uv run -q "$CH" report # hotspots, worst first: files, functions, complexity, copies
uv run -q "$CH" check # gate: exit 1 on a new or grown offender
uv run -q "$CH" baseline # 1st run: grandfather today's debt; later: lock gains in
uv run -q "$CH" baseline --accept # also record new/grown ones — only with the user's okPowerShell: uv run -q "$HOME\.agents\skills\code-health\scripts\code_health.py" check.
It scans tracked and untracked-not-ignored source files (minified, vendored, generated and
lock files skipped; add globs under "exclude"). Limits, overridable under "limits" in the
project's .code-health.json:
| Metric | Limit | Means |
file_lines | 800 | physical lines of one source file |
function_lines | 80 | lines of one function, nested functions included (lizard) |
function_ccn | 20 | cyclomatic complexity of one function |
duplicate_lines | 10 | a block of 10+ significant lines found at two places is a copy |
The ratchet. .code-health.json records every offender with its current size. check
fails when an offender is new or grew; existing debt passes. When one shrinks, run
baseline and commit: the record only ever goes down. A renamed giant file reads as new —
that is a baseline --accept, said in the commit message. No .code-health.json yet → check
compares with HEAD: the rule holds in every project before anyone adopts it.
Claude Code also gets a PostToolUse hint (project .claude/settings.json): an edit that
leaves a source file over the limit and longer than at HEAD prints one line to the agent.
Adopt it in a project (once)
- On a clean tree:
uv run -q "$CH" baseline, commitchore(code-health): baseline. - Add to
./check.sh(and the same guard tocheck.ps1), so every agent and theverifiersubagent run it:CH="$HOME/.agents/skills/code-health/scripts/code_health.py" if [ -f "$CH" ]; then uv run -q "$CH" check; else echo "code-health: skill not installed, skipped"; fi - Note the giant files in
PROJECT_STATE.mdlimitations only if a refactor is planned.
Review rules (apply to every diff — yours, a subagent's, a PR)
A finding of rule 1-3 is blocking: fix it before the commit, don't list it as a nit.
- Size. No new file over 800 lines, function over 80, complexity over 20; a recorded offender never grows. Need to touch a giant function? Extract the part you change first.
- No copy. Logic that exists elsewhere is imported, not pasted. Second copy of 10+ lines → extract a shared module now, at two, not at three.
- New feature, new module. Code goes where its name says: a feature gets its own file
(route group, view, connector), never one more block at the bottom of
app.js/app.py. - No god factory.
create_app()wires things; it doesn't define 50 handlers as closures. Routes live in per-area modules (FastAPIAPIRouter, FlaskBlueprint) with explicit deps. - Front-end in modules. One ES module per view or component, a shared state/api module; browser-extension pages (popup, side panel) import the same files instead of copying them.
- Delete, don't comment out. Dead code, unused exports and old variants go; git keeps them.
- Move ≠ change. A refactor commit moves code without changing behavior; behavior changes go in their own commit, so a review can trust "pure move" diffs.
- Names carry the design. A file or function whose honest name needs "and" or "utils" does two things — split it.
- Comments earn their place. Two lines at most, one block. A comment states only what the
code cannot: a unit or encoding the type does not carry; ownership, lifetime or thread
affinity; a precondition a caller can break unseen; a gotcha where the code looks wrong and
is right; an invariant whose violation is silent; an external pointer (spec, bug id). Never
about other code (callers, "see foo.py", "mirrors X"), never a restatement or a narration
of the body, never about the edit (task ids, plan refs, "was previously", commented-out
code). Density check on a diff: added comment lines ≥ 1 in 10 added non-blank lines is too
many. A project convention (
AGENTS.md) wins on shape, not on these bans. Fix = delete.
Paying the debt down — splitting a giant file
Never as a drive-by in a feature task; propose it, then work it as its own task
(architect-flow for anything past one extraction).
- Pick the target:
report, crossed with churn (git log --since=6.months --format= --name-only | sort | uniq -c | sort -rn | head) — a giant file nobody edits can wait; the one every feature touches cannot. - Safety net first: tests through public entry points must cover the area. Missing → add
characterization tests (record today's behavior, even if odd); for UI, a smoke with the
headless-ui-smokeskill before and after. - One cohesive area per commit: a route group, a view, a connector. Move it to its own
module, keep the old call sites working (re-export if needed), run
./check.sh, commitrefactor(scope): move <area> out of <file>, thenbaselineand commit the lower record. - Then deduplicate: for each copy pair in
report, extract the shared module and point both sides at it; check behavior on both sides. - Delegate the mechanics: each extraction is a precise subtask (source lines, target module, public names to keep) — a subagent or helper can do it; you review the diff, check it is a pure move, and run the gate.
Stop and ask when a split forces an API change other code (or another repo) depends on.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

