When agent A spawns agent B via the task tool, the session layer already tracks the relationship — Session.create() sets parentID: ctx.sessionID in task.ts. But this parent identity never reaches the plugin hooks.
Plugins using tool.execute.before, tool.execute.after, or shell.env can see agent (the current agent) but have no way to know who delegated the work. This blocks any plugin doing delegation-aware policy, audit trails, or permission scoping.
The data is already there in task.ts — ctx.agent is the parent, agent.name is the child. It just needs to be passed through:
// task.ts — the relationship already exists
const session = await Session.create({
parentID: ctx.sessionID, // ← session knows its parent
...
})
await SessionPrompt.prompt({
agent: agent.name, // ← child agent
// parentAgent: ctx.agent ← missing, this is all that's needed
})
Proposal: add an optional parentAgent field to the three hook inputs:
// top-level agent
{ agent: "coder" }
// subagent spawned by coder
{ agent: "scout", parentAgent: "coder" }
Optional field, fully backwards compatible — no existing plugin breaks. Related to #6527, #12566.
When agent A spawns agent B via the task tool, the session layer already tracks the relationship —
Session.create()setsparentID: ctx.sessionIDintask.ts. But this parent identity never reaches the plugin hooks.Plugins using
tool.execute.before,tool.execute.after, orshell.envcan seeagent(the current agent) but have no way to know who delegated the work. This blocks any plugin doing delegation-aware policy, audit trails, or permission scoping.The data is already there in
task.ts—ctx.agentis the parent,agent.nameis the child. It just needs to be passed through:Proposal: add an optional
parentAgentfield to the three hook inputs:Optional field, fully backwards compatible — no existing plugin breaks. Related to #6527, #12566.