Find and remove duplication in a branch's new code: fields that carry the same information twice, helpers that already exist elsewhere in the repo, and hooks or handlers that repeat one pattern. Use after a feature lands and before the PR is marked ready, when asked to "clean up", "dedupe", "simplify" or "is anything duplicated", or on any PR over ~1,000 lines.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Code Clean Up?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/markbase-team-code-clean-up)
---
name: code-clean-up
description: Find and remove duplication in a branch's new code: fields that carry the same information twice, helpers that already exist elsewhere in the repo, and hooks or handlers that repeat one pattern. Use after a feature lands and before the PR is marked ready, when asked to "clean up", "dedupe", "simplify" or "is anything duplicated", or on any PR over ~1,000 lines.
---
# Code clean-up
A pass over what a branch added, asking two questions of every new thing:
does something already say this, and does something already do this. The
answer is a ranked list first, then one commit that applies it.
## 1. List what the branch added
```bash
git diff --stat origin/main...HEAD -- packages apps supabase | tail -1
git diff origin/main...HEAD --name-only -- packages/*/src packages/features/*/src apps/*/src | grep -v test
```
For each new or changed source file, note its exported types with their
fields, and its functions (`grep -n "^export \(function\|interface\|type\|const\)"`).
That list is what the rest of the pass walks.
## 2. Fields that say the same thing twice
For every field of every new type, ask:
- **Same value in two places.** The same thing set on the type and inside a
nested `fields` object, or kept on an input shape and copied to an output
shape unchanged (`IncomingEvent.service` next to `fields.service`). Keep the
one the consumer reads.
- **A subset of another type.** A type that is another type minus a field or
two (`LastCheck` = `Pick<TimelineConfirmation, …>`). Drop it and use the
wider type, or `Omit<>`/`Pick<>` from one definition.
- **Derivable.** A count or flag the consumer could compute from a list it
already has. Keep it only when it is an API convenience for agents, and then
never recompute it client-side.
- **Two names across layers.** `link_reason` in the row and `link.reason` in
the API is fine (storage vs. shape); `files` meaning "all changed files" on
input and "the covered ones" on output is not. Name the narrowing.
## 3. Functions that already exist
Search by behaviour, not by name. The repo keeps growing copies of the same
small helpers; AGENTS.md's "one definition" table lists the ones with a home.
For each new helper, run the grep for its family:
| Family | Grep | Where the one copy belongs |
| --- | --- | --- |
| Line splitting, block walking | `-P "function (linesOf\|blocksOf\|splitLines)\("` | `packages/shared/src/docs/markdown.ts` |
| JSON record guards | `-P "function (isRecord\|isObject\|isJsonObject\|objectOf\|asRecord)\("` | one exported guard in `packages/shared` |
| Constant-time secret compare | `timingSafeEqual` | `packages/platform/server` |
| Time and date text | `-P "function \w*(ago\|Relative\|Time\|Date)\w*\("` | `packages/platform/ui/src/relative-time.tsx` |
| Globs | `-P "function (pathsMatch\|\w*[gG]lob\w*)\("` | `packages/shared/src/docs/views.ts` |
| Who did it (people, agents, tools) | `-P "function (agentLabel\|toolName\|nameOf\|\w*DisplayName)\("` | `packages/shared/src/attribution.ts` |
| Front-matter field parsing | `readCoreFields`, `propertiesJson` | `packages/shared/src/docs/doc-status.ts`, `properties.ts` |
| Fetch-on-change hooks | `const asked = useRef` , `cancelled = true` | one hook over `useLiveDoc` |
Run each as `git grep -n <pattern> -- packages apps | grep -v test/`. Two
exports with the same name in one package (`agentLabel` in `attribution.ts`
and `versions.ts`) is a finding on its own: rename the narrower one.
Not every lookalike is a duplicate. Two formatters that answer different
questions ("Today 08:55" vs. "44 minutes ago") stay, ideally in one file so
the next reader finds both. Say so in the report under "not duplicates, on
inspection", so nobody re-checks them.
## 4. Report, then apply
Report before changing anything: findings ranked by how much they simplify,
one line each, with the file and the replacement. Then, on a yes, apply as
one commit:
- Move, don't copy: the surviving definition gains the callers, the copies go.
- Add a row to AGENTS.md's table for any helper that now has one home, and a
check in `packages/shared/test/package-boundary.test.ts` when a copy could
come back.
- Keep every changed line covered (the branch's coverage rule) and run the
suites of every package touched.
- Record it on the PR like any other verification: what was merged into what.