---
name: shatter
description: 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.
title: shatter
canonical_url: https://skilld.dev/gh/theta-tech-ai/llm-public-utils/shatter
last_updated: 2026-09-21T16:22:10.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install theta-tech-ai/llm-public-utils/shatter`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/shatter`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/theta-tech-ai/llm-public-utils/shatter) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/shatter`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/shatter --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/shatter --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 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`:
   ```bash
   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.
