tx

tx claim

Claim a task with a lease to prevent parallel collisions

Purpose

tx claim marks a task as being actively worked on by a specific worker. This prevents multiple agents from picking the same task and duplicating work. Claims use a lease-based model with automatic expiry.

Commands

CommandDescription
tx claim <task-id> <worker-id>Claim a task with a lease
tx claim:release <task-id> <worker-id>Release a claim
tx claim:renew <task-id> <worker-id>Renew the lease on a claim

tx claim

Claim a task for a worker, preventing other workers from claiming it.

Usage

tx claim <task-id> <worker-id> [options]

Arguments

ArgumentRequiredDescription
<task-id>YesTask ID (e.g., tx-a1b2c3d4)
<worker-id>YesWorker ID (e.g., worker-abc12345)

Options

OptionDescription
--lease <m>Lease duration in minutes (default: 30)
--jsonOutput as JSON
--helpShow help

Examples

# Claim with default 30-minute lease
tx claim tx-abc123 worker-def456

# Claim with 60-minute lease
tx claim tx-abc123 worker-def456 --lease 60

# JSON output
tx claim tx-abc123 worker-def456 --json

tx claim:release

Release a worker's claim on a task, allowing other workers to claim it.

Usage

tx claim:release <task-id> <worker-id> [options]

Arguments

ArgumentRequiredDescription
<task-id>YesTask ID
<worker-id>YesWorker ID that holds the claim

Options

OptionDescription
--jsonOutput as JSON
--helpShow help

Examples

tx claim:release tx-abc123 worker-def456

tx claim:renew

Extend the lease on an existing claim. Use this for long-running tasks to prevent the claim from expiring.

Usage

tx claim:renew <task-id> <worker-id> [options]

Arguments

ArgumentRequiredDescription
<task-id>YesTask ID
<worker-id>YesWorker ID that holds the claim

Options

OptionDescription
--jsonOutput as JSON
--helpShow help

Limits

  • Maximum 10 renewals per claim
  • Fails if the lease has already expired
  • Fails if no active claim exists for this task and worker

Examples

tx claim:renew tx-abc123 worker-def456

Use Case: Parallel Agent Execution

Without claims, parallel agents might pick the same task:

# Problem: Both agents pick the same task
Agent1: tx ready --limit 1 tx-abc123
Agent2: tx ready --limit 1 tx-abc123  # Same task!

With claims:

# Solution: Claims prevent collision
Agent1: tx claim tx-abc123 worker-1   # Success
Agent2: tx claim tx-abc123 worker-2   # Fails - already claimed

Parallel Agent Loop

#!/bin/bash
WORKER_ID="worker-$$"

while true; do
  TASK=$(tx ready --json --limit 1 | jq -r '.[0].id // empty')
  [ -z "$TASK" ] && break

  # Try to claim - skip if another worker got it
  tx claim "$TASK" "$WORKER_ID" || continue

  # Work on the task
  claude "Your task is $TASK. Run 'tx show $TASK' for details."

  # Complete and release
  tx done "$TASK"
done

Behavior

  1. Claiming creates a lease with an expiry time
  2. Expired leases allow other workers to claim the task
  3. Completing a task (tx done) does not require releasing the claim first
  4. Long tasks should periodically renew with tx claim:renew

On this page