Index of every page on this site: llms.txt
All skills
Run it yourself

Break large files into focused, single-responsibility pieces. Use when a file exceeds size thresholds (~250 LOC frontend, ~400 LOC backend) or mixes multiple responsibilities.

Requires /deslop
Use this Skill: https://skilld.dev/gh/theta-tech-ai/llm-public-utils/shatter

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈46 tokens for metadata: the name and description. ≈1.2k when used: this file.

Description uses 2.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈185 characters, or 2.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Shatter: Break Large Files Into Focused, Single-Responsibility Pieces

We hate large files. A file that crosses the size threshold or holds more than one responsibility is a refactor target. /shatter [file-or-directory] finds the biggest offenders and splits them — safely, behavior-preserving, verified.

This is a focused companion to /deslop. Deslop covers all code-quality principles; shatter is the single-minded "make this file small" pass.

Thresholds

Kind Soft limit Hard target
Frontend .tsx / .ts ~250 lines one responsibility per file
Backend .py ~400 lines one service responsibility per module
Hook one hook per file —
Test file mirrors its source 1:1 —

A file over the soft limit is a candidate, not automatically a violation: a large file that merely composes sub-components (mostly imports + wiring) is acceptable. The real target is the file that mixes responsibilities — a page that is also a state machine that is also five presentational components.

Process

  1. Find the offenders. Rank by size, excluding any read-only upstream submodule, generated data files, caches, and node_modules:

    git ls-files '*.tsx' '*.ts' '*.py' | grep -v <submodule-dir> \
      | xargs wc -l 2>/dev/null | sort -rn | head -40

    For files that live upstream (inside the submodule), shatter them in your canonical upstream checkout and smelt up — never edit the submodule directly.

  2. Read the file and name its responsibilities. List every distinct thing it does: page layout, a state machine, CRUD handlers, presentational leaf components, helpers. Each cluster is a potential extraction.

  3. Pick extraction boundaries that minimize coupling and swap risk, in order of preference (safest first):

    • Pure leaf components / helpers → sibling *Parts.tsx or a shared components/common/ file. Zero behavior risk (pure function moves).
    • Self-contained state machines → a custom hook (useXxx.ts). Hooks take a named deps object and return a named handlers object — far less prone to same-typed argument swaps than a positional prop bag.
    • Conditionally-rendered modal/panel clusters → a XxxModals.tsx component. Pass props by name matching the originals.
    • The main render body → a XxxWorkspace.tsx — last, because it usually needs the widest prop surface (highest swap risk).
    • A single-use hook/component that exists ONLY to satisfy the line count is over-abstraction — don't extract it (a hook with one consumer is cosplay).
  4. Respect in-code refactor warnings. If a comment says "do NOT collapse these / refactoring this broke X" (e.g. two audit-trail render paths that must stay distinct), you may extract the block but must NOT merge the distinct paths.

  5. Verify every split — extraction is only safe if all of these pass:

    • npx tsc -b clean (proves all prop/closure wiring types).
    • The file's tests pass. If there is no behavior test, add a render/mount smoke test FIRST (mock the hooks/stores; assert it mounts and renders a key element). Validate the smoke test against the current file before you touch it, so it's a real baseline.
    • npx vite build (frontend) / the service's pytest (backend) succeeds.
  6. Commit per logical extraction, smelt up if upstream, bump the submodule.

What "shatter" produces

Before: one 800-line page that is layout + state + handlers + modals + leaves.

After: a ~250-line orchestrator that wires hooks and composes components, plus useXxxActions.ts (handlers), XxxModals.tsx (modals), XxxParts.tsx / XxxWorkspace.tsx (render), each under threshold and single-responsibility. Readers fan out via go-to-definition instead of scrolling. The tradeoff — more import lines at the top of each file — is a net win.

Anti-patterns (don't do these)

  • Collapsing distinct logic to save lines (merging two render paths that write different audit events, deduping two functions that only look alike).
  • Single-use abstraction created solely to drop a line count.
  • Unverified extraction. tsc-green is necessary but not sufficient for a prop bag — a render/mount test catches same-typed swaps tsc can't.
  • Editing the read-only submodule directly. Shatter upstream files in your canonical upstream checkout, then smelt + bump.

Output

For each offender: its responsibilities, the proposed file split (new file → what moves into it), and the verification result (tsc / tests / build). Then ask the user whether to apply, or apply directly if running under a standing "shatter" goal.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides instructions for refactoring large code files into smaller, single-responsibility components. It uses standard development tools like git, TypeScript, Vite, and Pytest to identify candidates for refactoring and verify the integrity of the code after changes. No malicious patterns or security risks were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 89b4878. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 5 months ago

README badge

README badge for theta-tech-ai/llm-public-utils/shatter