# Pull one duplicated block into one place

Pull one duplicated block into one place: Point at the same logic copied into more than one place, and get it merged into one shared version.

Source: https://codeherder.com/starter-briefs/pull-duplicated-code-into-one-place/

Starter briefs

Point at the same logic copied into more than one place, and get it merged into one shared version.

[Request access →](https://codeherder.com/get-started/#request-access) [Part of: Pay down a refactor →](https://codeherder.com/use-cases/pay-down-a-refactor/)

## The brief

Copy this text as it is, or change the specifics to match your own case, then file it as a task.

Copy this and file it as a task

Copy brief

```
The same block of logic is duplicated in more than one place in this codebase, and they've started to drift slightly apart. Pull it into one shared place, update every call site to use the shared version instead of its own copy, and make sure nothing that depended on a small difference between the copies breaks.
```

## Why this works

It names a specific duplication rather than "reduce duplication" in general, so the scope is fixed: one shared version, every call site updated to use it. The existing tests at each call site are the check that nothing broke in the merge.

How it runs

## Plan, code, review, merge, verify

1. plan Compares every copy of the duplicated logic to find which differences are intentional and which are just drift.
2. code Extracts one shared version that covers every real requirement, and updates each call site to use it.
3. review Checks each call site's own tests still pass against the shared version, exercising every caller in turn.
4. merge Opens a pull request that resolves only this one duplication.
5. verify Confirms every former call site still behaves the way its own tests expect.

## What you need on hand

- Where the duplicated logic lives, in every place it's copied
- Whether the small differences between the copies are intentional or drift
- A person to review the merged version against each original call site

## Done when

- Only one copy of the logic exists
- Every former call site uses the shared version
- Each call site's own existing tests still pass

## Proof, not a promise

No real task in examples.ts matches this brief's exact shape yet. What's real is the mechanism: an agent compares every copy of the duplicated logic before merging it, so an intentional difference doesn't get silently erased along with the accidental drift.

Keep going

## Related briefs

[One thing has two names; give it one Name the two terms that mean the same thing, and get the whole codebase moved to one of them.](https://codeherder.com/starter-briefs/give-one-thing-one-name/) [Add a filter to a list we already have Name the list and what you want to narrow it by, and get a working filter control for it.](https://codeherder.com/starter-briefs/add-a-filter-to-a-list/) [Cover the one file nobody has tests for Name a file with no test coverage, and get a real test suite for what it actually does.](https://codeherder.com/starter-briefs/cover-the-untested-file/)

[← See every brief](https://codeherder.com/starter-briefs)
