Skip to content
Back to skills

Code Clean Up

ASecurity

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.

  • 47 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added December 1, 2026
ai-agentsgobashgitapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 1, 2026

npx -y skills add Markbase-Team/Markbase --skill code-clean-up --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Code Clean Up?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Code Clean Up
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/markbase-team-code-clean-up/badge)](https://www.skillsdirectory.com/skills/markbase-team-code-clean-up)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.