Skip to content

sessions_spawn(agentId) should respect agent's configured workspace instead of always inheriting parent #40825

@riskatcher

Description

@riskatcher

Feature Request

When spawning a sub-agent via sessions_spawn(agentId="X"), the sub-agent's workspace context files (AGENTS.md, SOUL.md, USER.md, etc.) are always injected from the parent agent's workspace, not from agent X's configured workspace.

Key Finding: cwd ≠ workspace context injection

Setting cwd in sessions_spawn only affects the working directory for exec commands. It does NOT change which workspace files are injected into the system prompt.

This means:

  • cwd parameter → controls exec working directory ✅
  • Workspace context injection (AGENTS.md, SOUL.md, etc.) → always uses parent's workspace ❌

The sub-agent itself confirmed this behavior:

"My working directory is /home/user/clawd/agents/ct-manager, but the project context files injected at session start were from /home/user/clawd/ (the parent root). The runtime uses different paths for workspace vs injected base context files."

Current Behavior

# Config:
# agents.list[0] = { id: "main", workspace: "/home/user/clawd" }
# agents.list[1] = { id: "ct-manager", workspace: "/home/user/clawd/agents/ct-manager" }

# From main agent:
sessions_spawn(agentId="ct-manager", cwd="/home/user/clawd/agents/ct-manager", task="...")

# Result:
# - exec cwd = /home/user/clawd/agents/ct-manager  ← correct
# - System prompt AGENTS.md = /home/user/clawd/AGENTS.md  ← WRONG (parent's)
# - System prompt SOUL.md = /home/user/clawd/SOUL.md  ← WRONG (parent's)
# - ct-manager's own AGENTS.md at agents/ct-manager/AGENTS.md = IGNORED

Desired Behavior

When agentId is specified in sessions_spawn, and that agent has an explicit workspace configured:

  1. Use the agent's configured workspace for both exec cwd and workspace context file injection
  2. Inject AGENTS.md, SOUL.md, USER.md, etc. from the agent's own workspace directory
  3. Fall back to parent's workspace only if the target agent has no explicit workspace configured

Impact

This makes per-agent identity completely broken for sub-agent scenarios:

  • Agent-specific AGENTS.md instructions are ignored
  • Agent-specific SOUL.md identity is ignored
  • Agent-specific skills (referenced by relative paths) don't resolve correctly
  • Any customization in the agent's own workspace files has zero effect
  • The sub-agent operates with the parent's identity and instructions

In our case, we spent significant effort adding guardrails to ct-manager's AGENTS.md (skill loading order, API key enforcement, tool restrictions), only to discover none of it was being read because the parent's AGENTS.md was always injected instead.

Workaround

None currently. Setting cwd does not fix the workspace context injection. The only workaround would be duplicating all agent-specific instructions into the task prompt, which defeats the purpose of per-agent workspace configuration.

Environment

  • OpenClaw 2026.3.7 (42a1394)
  • Linux (WSL2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions