Skip to content

td init should write .td-root in git worktrees for multi-agent development #184

@pjsvis

Description

@pjsvis

Context

Running multiple AI coding agents in parallel on the same repo is a common pattern (one agent per epic, isolated via git worktrees). Each agent needs its own td session, but they should share the same task database so work done in one worktree is immediately visible to all others.

Currently td walks up from CWD to find .todos/, which means an agent in a worktree either finds the shared .todos/ at repo root (if .td-root is written manually) or creates a separate .todos/ in the worktree (isolated, confusing).

Solution

When td init runs inside a git worktree (detected via git rev-parse --is-inside-work-tree), it should write a .td-root file in the worktree root pointing to the parent repo root.

This makes the shared-database model work automatically, without any new commands or flags.

Example

# Create worktree
git worktree add ../TradingAgents-feature-x -b feature-x

# Inside worktree — td init writes .td-root automatically
cd ../TradingAgents-feature-x
td init
# → Created: .td-root → /path/to/repo-root

# Now td in worktree resolves to shared .todos/ at repo root
td whoami      # new session
td list        # sees all tasks from all worktrees

Evidence

Full E2E test results documented in our repo:
https://github.com/pjsvis/TradingAgents/blob/main/briefs/2026-05-11-td-worktree-test-results.md

E2E verification:

  • Worktree creates task → main sees it immediately
  • Main creates task → worktree sees it immediately
  • Same issue count from both locations
  • Cleanup works cleanly (delete worktree, .td-root goes with it)

Related

Scope

Single change: td init detects worktree context → writes .td-root. All other td behavior unchanged. No new commands needed.

Note on terminology

Multi-agent, not multi-user: td + worktrees enable one person running multiple agents in parallel on the same repo. Each agent gets its own td session but they cooperate via the shared database. No database sync or merge step needed — worktrees share one .todos/ at repo root.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions