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

Resolved 💬 3 comments Opened May 17, 2026 by michaeltyson Closed Aug 6, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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 ↗

3 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #22925

Powered by Codex Action

ASTXRTYS · 3 months ago

Yes, this would be huge. Being able to spawn subagents directly in the directory they are intended for would be excellent. Currently I am not able to prevent subagents from seeing the same skills descriptions and agents.md as the parent due to this.

SanjoSolutions · 2 months ago

Implemented in https://github.com/SanjoSolutions/codex/tree/feature/worktree-backed-subagent-spawns

Usage prompt:

Do:

* Task A
* Task B
* Task C

in parallel using subagents. Spawn one subagent per task with `git_worktree`, each on a unique `agent/...` branch and sibling worktree. After they finish, review and merge their branches back into this workspace, resolving conflicts and running tests.

Or with this skill:

$do * Task A
* Task B
* Task C