Allow spawn_agent to start subagents in a specified workspace/worktree directory

Open 💬 3 comments Opened May 17, 2026 by michaeltyson

What variant of Codex are you using?

App/CLI

What feature would you like to see?

I’d like spawn_agent to support an explicit workspace directory, for example a cwd, workdir, or workspace_path parameter.

Context:

I use Codex to coordinate autonomous multi-agent work across a Git repository with multiple isolated Git worktrees. A coordinator agent creates one worktree per task, then spawns worker agents that are supposed to make code changes only inside their assigned worktree. This pattern is useful for parallel implementation because it keeps branches isolated, avoids cross-task contamination, and lets a coordinator review/integrate each worker branch independently.

Today, spawn_agent does not appear to expose a way to set the spawned agent’s working directory. The coordinator can tell the worker, in prose, to work in /path/to/assigned/worktree, but the worker is still effectively born in the coordinator’s current workspace/context. In practice, that is fragile: workers often search, edit, or apply patches relative to the coordinator’s worktree before correcting themselves, which creates noisy diffs and sometimes lands edits in the wrong tree.

Requested behavior:

Add a workspace_path/cwd/workdir option to spawn_agent, so a coordinator can launch a worker directly inside the intended worktree:

{
  "agent_type": "worker",
  "workspace_path": "/Users/me/project-worktrees/task-123",
  "message": "Work only on the assigned Todoist item..."
}

Desired semantics:

  • The spawned agent’s default shell/tool working directory should be the provided path.
  • File search, reads, writes, apply_patch, and git commands should naturally operate relative to that workspace.
  • The agent should perceive that directory as its primary workspace root.
  • If the path is invalid or not accessible, spawn_agent should fail immediately rather than falling back to the coordinator workspace.
  • Ideally the spawned agent’s context should include an explicit note like: “Your workspace root is <workspace_path>.”

Why this matters:

This would make multi-agent workflows much safer and lower-friction. It would allow coordinator agents to create isolated worktrees and spawn workers into them directly, instead of relying on prose instructions and start-gate checks to prevent wrong-worktree edits. It would reduce accidental edits in the coordinator worktree, avoid noisy cleanup, and make parallel agent work much more reliable.

This is especially important for workflows where:

  • each worker owns a separate Git worktree/branch,
  • commits must remain isolated and reviewable,
  • the coordinator must not have worker edits in its own worktree,
  • multiple agents are running in parallel,
  • correctness depends on file operations happening in the assigned workspace by default.

Additional information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗