[Bug] Task tool missing agent ID in completed agent responses
Bug Description
The Task tool does not return the agent ID in the tool result when agents complete successfully. The agent ID is only included for async/background agents, but not for regular completed agents.
Impact
Without the agent ID, Claude cannot resume agents because the resume parameter requires the agent ID:
Task({resume: "agent-id-here", prompt: "Continue where we left off..."})
Currently, the only workaround is to manually search the filesystem for agent JSONL files.
Expected Behavior
The tool result should include the agent ID after the agent's response:
Hello! How can I help you?
Agent completed successfully.
agentId: fad96168
This matches the behavior of async agents, which do include the agent ID in their responses.
Actual Behavior
The tool result only returns the agent's text response without the agent ID:
Hello! How can I help you?
The agent ID is missing, making it impossible to resume the agent later.
Root Cause
File: cli.js
Location: Task tool definition, in the mapToolResultToToolResultBlockParam method
The method that converts internal agent results to Claude-visible tool results strips out the agent ID for completed agents:
if (A.status === "completed")
return {
tool_use_id: B,
type: "tool_result",
content: A.content // Only returns content array, agentId stripped
};
The Fix
Replace the content line to include the agent ID:
// Before:
if (A.status === "completed")
return {tool_use_id: B, type: "tool_result", content: A.content};
// After:
if (A.status === "completed")
return {
tool_use_id: B,
type: "tool_result",
content: [
...A.content,
{type: "text", text: `\nAgent completed successfully.\nagentId: ${A.agentId}`}
]
};
This appends the agent ID to the end of the response, allowing Claude to see and use it for resume operations.
Status
Fixed and verified with curiosity and care 🐾
Working in Claude Code 2.0.31.
Environment Info
- Platform: linux
- Terminal: ghostty
- Version: 2.0.31
- Feedback ID: 99b18f95-51da-45a1-9b6b-c0a16cfa8ca9
9 Comments
I'm on 2.0.33 on Windows and this isn't working. Frustrating. No agentId
Come on!!Fix it!!!!!Fix it!!!!!Fix it!!!!!
Resumption is a key feature for making subagents useful, I'm on 2.0.51 and encountering this on Linux (WSL2). Please escalate the priority of this.
---
A very hacky work-around that shouldn't be needed (Linux, but if you get the idea you could re-create):
---
Resume Agents
Agent Session Tracking
Always track agent invocations:
.claude/sessions.md.What to record:
Getting agentId
CRITICAL Capture timing matters: Capture immediately after invocation. Once you invoke a second agent, the first agent's ID becomes difficult to retrieve.
Project command over-ride: Project CLAUDE.md commands over-ride these generic instructions and provide the full path without having to find the {project-hash}.
Capture Patterns
Generic command (replace {project-hash} with actual folder):
Single agent
Multi agent
Example output:
Resumption: Agent targeted by ID, {name} not needed.
For anyone looking to enable agent resumption via claude-code (requires
jq):your
.claude/settings.json:Added
agentIdto the model prompt (and it should already be part of the cli UI):<img width="708" height="252" alt="Image" src="https://github.com/user-attachments/assets/b54f143f-cb5a-4d0f-8abc-7bb67d639cd9" />
<img width="798" height="114" alt="Image" src="https://github.com/user-attachments/assets/9f478f75-25ac-4c57-920e-b17be0b8d13e" />
Might take a day or two to deploy to npm.
It has been 5 days. I’ve checked the changelog and tried the latest version, but there’s still no update.
<img width="896" height="948" alt="Image" src="https://github.com/user-attachments/assets/0d43d6cd-de69-4d19-9fbe-5a9d8a84a971" />
I don't know if there's an update on this bug. I tested the latest version and it seems that the agentid is only displayed when the agent is reused. Shouldn't it be displayed every time the agent is used?
@timgu0
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.