Skip to content

Support cwd for spawn_agent #18969

Open
Open

Description

@gndk

What variant of Codex are you using?

CLI

What feature would you like to see?

Add an optional cwd parameter to spawn_agent, including the MultiAgentV2 tool surface.

Parallel subagent workflows often need one worker per isolated checkout or worktree. Today a spawned
subagent inherits the parent session cwd, so callers must rely on prompt instructions such as “work in
this directory.” That is not a reliable boundary for tool execution, hooks, sandboxing, or git-root
checks.

A per-spawn cwd would let the orchestrator start each subagent in the checkout it owns.

Proposed API:

{
  "task_name": "worker_a",
  "message": "Implement the assigned slice.",
  "cwd": "/absolute/path/to/worktree"
}

Suggested semantics:

  • absolute paths are used as-is
  • relative paths resolve from the parent agent cwd
  • the child session starts with the requested cwd
  • reject a requested cwd that would grant access outside the parent’s sandbox
  • recompute the child file-system sandbox policy relative to the requested cwd when applicable

Additional information

Spawned agents are already created from a child Config, and session/tool execution already has a
cwd. This request is to expose a per-spawn cwd override on spawn_agent and validate/apply it before
the child session starts.

Activity

  1. added
    enhancement
    on Apr 22, 2026
  2. added
    CLI
    subagent
    sandbox
    on Apr 22, 2026
  3. PratikRai0101 commented on Apr 22, 2026

    @PratikRai0101

    Hey, I would like to work on this, I will open a draft PR for this.

  4. removed
    sandbox
    CLI
    on Apr 22, 2026
  5. JJLiebig commented on May 2, 2026

    @JJLiebig

    That would be really useful for multi agent orchestration to not step on each other's toes!

  6. wcy1231 commented on May 7, 2026

    @wcy1231

    Why this matters

    cwd is often the subagent's ownership boundary, not just a shell convenience.

    In multi-agent workflows, a parent/orchestrator agent may delegate work to workers that each own a different package, checkout, or worktree. Those locations can have different:

    • AGENTS.md instructions
    • skill discovery
    • repo-local config
    • hooks
    • git roots
    • sandbox assumptions

    If the spawned agent only inherits the parent cwd, then prompt instructions like "work in this directory" are not a reliable substitute for actually starting the child session there.

    Worker/reviewer use case

    This becomes especially important when subagents are used as real workers or reviewers, rather than short one-off helpers.

    The orchestrator should be able to keep high-level context while starting each worker in the environment that defines its actual task boundary.

    Suggested behavior

    I agree with the proposed semantics:

    • add an optional per-spawn cwd
    • resolve relative paths from the parent cwd
    • validate the requested cwd against the parent sandbox
    • apply the cwd before the child session starts

    This would make multi-agent workflows much more robust and would align instruction discovery, skill discovery, hooks, shell tools, and git behavior with the subagent's intended scope.

  7. SanjoSolutions commented on Jun 9, 2026

    @SanjoSolutions

    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
    
  8. gmatev commented on Sep 24, 2026

    @gmatev

    This would be a fantastic enhancement for aidlc orchestration in more complex enterprise environments with tasks spanning multiple repos. Today one needs to externally orchestrate harness launches in the right root in order to get execution to pickup agents.md and skills for other repos.

  9. unknowntruthtarot commented on Nov 16, 2026

    @unknowntruthtarot

    Adding a Windows use case for an explicit cwd on child-agent launch. On Nov 11, 2026, a child agent assigned to work in a different project started in its parent’s working directory and needed explicit steps to load the intended project instructions. Running a command after changing directories does not show that the agent started in the right project or automatically read its instructions. Please expose a way to specify the child’s starting directory and verify which project instructions were loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions