---
title: "How to keep AI coding agents from duplicating each other's work · Cork"
description: "Stop parallel AI coding agents fixing the same bug twice or writing the same helper: claim work, share a task list, publish findings, check before starting."
canonical: "https://corkcli.com/blog/stop-ai-coding-agents-duplicating-work"
last_updated: "2026-11-14"
published: "2026-10-03"
author: "Kevin Vera"
---

# How to keep AI coding agents from duplicating each other's work

Stop parallel AI coding agents fixing the same bug twice or writing the same helper: claim work, share a task list, publish findings, check before starting.

By Kevin Vera · October 3, 2026 · [Guides](https://corkcli.com/blog/c/guides) · 7 min read

To keep AI coding agents from duplicating each other's work, make every unit of work claimable in one shared place, have each agent check that place (and the code that already landed) before it starts, and give agents a way to publish what they found so the next one does not rediscover it. Duplication happens because each agent starts with a fresh context and no idea what the others are doing. The fix is less about the agents and more about the shared state you give them.

## Why agents duplicate work

Three patterns cause almost all of it:

- **Same task, two agents.** Two people each ask an agent to "fix the flaky checkout test." Both succeed, in different ways, and the second merge fights the first.
- **Same helper, two agents.** Agent A writes `formatCurrency` in `utils/money.ts`. Agent B, in another worktree, needs the same thing, cannot see A's uncommitted file, and writes `formatPrice` in `lib/format.ts`.
- **Same investigation, two agents.** Each agent spends its first twenty tool calls learning how auth works, because the first agent's findings lived and died in its own context window.

Claude Code's docs are explicit that this is the default: "Each new session starts with a fresh context window, without the conversation history from previous sessions." Worktrees make it worse in one specific way: they isolate files so well that agents cannot see each other's in-progress code at all.

## Step 1: make work claimable in one place

Pick one source of truth for "who is doing what" and make starting work mean claiming it there.

**If you use [Claude Code agent teams](https://corkcli.com/blog/cork-vs-claude-code-agent-teams)**, the shared task list does this for you. Tasks are pending, in progress, or completed, can depend on other tasks, and "task claiming uses file locking to prevent race conditions when multiple teammates try to claim the same task simultaneously." Agent teams are experimental and off by default; enable them with:

```json
{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
  }
}
```

**If agents run in separate sessions or tools**, use your issue tracker as the claim. A one-line instruction in `CLAUDE.md` or `AGENTS.md` makes agents follow it:

```markdown
## Before starting any task
- Run `gh issue list --assignee @me --state open` and `gh pr list --state open`.
- If an open PR or another assignee already covers this task, stop and report it.
- Otherwise assign the issue to yourself before editing code.
```

Codex reads `AGENTS.md` from the repository root down to the working directory; Claude Code reads `CLAUDE.md` and can read an `AGENTS.md`. One file, checked in, means every agent gets the rule.

## Step 2: check what already landed before writing anything new

Most duplicate helpers are written by an agent that never looked. Make looking cheap and explicit:

```bash
git fetch origin
git log origin/main --oneline --since="1 day ago"
git grep -n -E "formatCurrency|formatPrice|toMoney" origin/main -- src/
```

And put the rule where agents read it:

```markdown
## Shared utilities
- Search `src/utils/` and `src/lib/` before adding any helper.
- Never add a second function that does what an existing one does; extend the existing one.
```

For Claude Code, a code intelligence plugin helps here too: finding an existing symbol by name through a language server is faster and more accurate than text search across candidate files.

## Step 3: publish findings so the next agent starts ahead

When one agent learns something expensive (how the payment retry works, why a test is flaky, which module owns a config value), write it where the next agent will read it:

- **Durable rules** go in `CLAUDE.md` or `AGENTS.md`. Keep them short; Codex stops adding instruction files at 32 KiB by default, and Claude Code's docs suggest keeping `CLAUDE.md` under 200 lines.
- **Live findings** go to the agents that need them now. Claude Code's cross-session messaging lets one session send plain text to your other sessions on the same machine, and the docs describe exactly this use: "When one session settles a question another is blocked on, Claude can send the answer across."

```text
Tell @payments-worker that retry backoff lives in src/billing/retry.ts and is already exponential
```

- **Decisions** go in the PR description, so humans and agents reviewing later see the reasoning.

## Step 4: split work so overlap is impossible by construction

The cheapest duplicate is the one that cannot happen. When you plan parallel work, divide it by files or modules, not by vague goals. Claude Code's agent teams docs recommend 5 to 6 tasks per teammate and warn that "two teammates editing the same file leads to overwrites." The same split prevents duplication: if only one agent owns `src/utils/`, only one agent writes utilities.

A quick check before launching agents: list each agent's task and the directories it will touch. Any directory on two lists is where duplication or conflict will come from.

## Where these steps fall short

Claims, conventions, and messages all rely on an agent choosing to check or choosing to tell. Claude Code's docs say Claude sends a message on its own "when it sees the need," which means a finding gets shared only if the agent that found it recognizes another agent needs it. Issue claims cover planned work, not the helper an agent decides to write halfway through a task. And messaging stops at your own account: cross-session messaging reaches your own sessions (on other machines too, through Remote Control), not a teammate's.

## How Cork helps

Cork makes the shared state automatic, so agents learn what others did without anyone choosing to tell them. Cork is the [coordination layer](https://corkcli.com/blog/coordination-layer-ai-coding-agents) for multiplayer coding agents: it keeps Claude Code, Codex and Cursor agents, on one machine or across a team's machines, from overwriting each other on one codebase, and hands each agent what the others already learned.

For this problem specifically:

- **Briefing:** when an agent starts or gets a prompt, it is handed the exact signatures, callers and recent changes of the code it is about to touch, including work other agents just did.
- **Live awareness:** when another agent changes code yours depends on, your agent hears it on its next step.
- **Agent messaging:** any agent can message the others in the repo, one agent, or whoever is working on a given function.
- **`remember` and `recall`:** durable notes anchored to code, so a finding about `retry.ts` is there for the next agent that touches it.

Cork Free covers one machine with no account; the paid plan adds teammates' machines and shared knowledge. Install it once for every repo on the machine:

```bash
curl -fsSL https://corkcli.com/install.sh | sh
```

## Frequently asked questions

### Why do my AI agents keep writing the same function twice?

Each agent starts with a fresh context and, in separate worktrees, cannot see the others' uncommitted files. Unless something tells it the helper exists, it writes its own.

### Do Claude Code agent teams prevent duplicate work?

They help for tasks on the shared task list, which uses file locking so two teammates cannot claim the same task. They do not stop two teammates from writing overlapping code inside different tasks, and they do not cover sessions outside the team.

### Should agents use the issue tracker to claim work?

Yes, if your agents run in separate sessions or tools. A checked-in instruction to check open PRs and assign the issue before editing is simple and works with every agent that reads `CLAUDE.md` or `AGENTS.md`.

### How do I share what one agent learned with the others?

Put durable rules in `CLAUDE.md` or `AGENTS.md`, send live findings with cross-session messaging, or use a coordination layer that briefs each agent on recent changes and [anchored notes](https://corkcli.com/blog/shared-memory-coding-agents-anchored-notes) automatically.

## Sources

- <https://code.claude.com/docs/en/agent-teams>
- <https://code.claude.com/docs/en/how-claude-code-works>
- <https://code.claude.com/docs/en/cross-session-messaging>
- <https://code.claude.com/docs/en/costs>
- <https://code.claude.com/docs/en/plugins/code-intelligence>
- <https://learn.chatgpt.com/docs/agent-configuration/agents-md>

## Related reading

- [Cork vs GitButler: sorting agents' changes, or keeping agents from colliding](https://corkcli.com/blog/cork-vs-gitbutler): Cork vs GitButler for parallel AI coding agents: GitButler sorts each agent's work into branches, Cork keeps agents from overwriting each other's code.
- [Cork vs Multica: assigning agent work vs keeping it from colliding](https://corkcli.com/blog/cork-vs-multica): Cork vs Multica: Multica assigns issues to AI coding agents on a shared board. Cork keeps parallel agents from overwriting each other's code.
- [Cork vs Herdr: where agents live vs how they share a codebase](https://corkcli.com/blog/cork-vs-herdr): Cork vs Herdr: Herdr keeps AI coding agents running in persistent terminal panes. Cork keeps those parallel agents from overwriting each other's code.
- [Parallel AI coding agents: running several agents on one codebase at once](https://corkcli.com/blog/parallel-ai-coding-agents): Parallel AI coding agents are several coding agents working on one repository at the same time, each on its own task, to finish more work in less time.

[All articles](https://corkcli.com/blog.md) · [Cork in Markdown](https://corkcli.com/index.md) · [llms.txt](https://corkcli.com/llms.txt)

This page in HTML: https://corkcli.com/blog/stop-ai-coding-agents-duplicating-work
