Skip to content

Learn

How do you keep two agents from doing the same task?

Let the agents take tasks from a shared list where only one agent can hold a task at a time. The agent that takes a task marks it as taken in the same step, and the next agent that tries gets a refusal and picks another task.

Last reviewed on .

How Claude Code does it

In Claude Code's agent teams, the work is coordinated through a shared task list. Tasks have three states: pending, in progress and completed.

According to the documentation, file locking is used when a task is claimed, to prevent several teammates from claiming the same task at the same time.

The documentation also covers file conflicts: two teammates editing the same file overwrite each other, and the work should be split so that each teammate owns its own files.

How AgentRoots does it

Tasks are changed with task_update and one of these actions:

  • claim: takes the task. Only one session can hold the task.
  • release: releases the task.
  • block: marks the task as blocked, with a note on why.
  • done: finishes the task.
  • cancel: cancels the task.

A task can be reserved for a specific session when it is created, with the field to in task_create. The operation task_list shows open, claimed and blocked tasks, so that a session sees what others already hold.

Search before the work starts

Duplicate work also happens when something was already solved in an earlier session. In AgentRoots a session searches roots and nuggets with search before it solves something that may have been solved before.