[Bug] Task tool missing agent ID in completed agent responses

Status Fixed / completed
Maintainer reply None cached
Activity 9 comments · opened Nov 2, 2025 · closed Dec 7, 2025

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

View original on GitHub ↗

9 Comments

michael-budnik · 9 months ago

I'm on 2.0.33 on Windows and this isn't working. Frustrating. No agentId

wengqizun · 9 months ago

Come on!!Fix it!!!!!Fix it!!!!!Fix it!!!!!

markwallaert · 9 months ago

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:

  • What: name, agentId, brief task description.
  • Where: .claude/sessions.md.

What to record:

  • Name: Elliot, Jet, Morty, Rick
  • ID: 8-char hex
  • Context: Brief description of agent task/prompt

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
ls -t ~/.claude/projects/{project-hash}/agent-*.jsonl | head -1 | xargs jq -r '.agentId' | uniq
Multi agent
  1. Invoke N agents in parallel with {name}: prefixes:
  • "Rick: Perform code review: X"
  • "Morty: design schema for Y"
  1. IMMEDIATELY get names and agentIds with:
for id in $(ls -t ~/.claude/projects/{project-hash}/agent-*.jsonl | head -{number-of-agents} | xargs jq -r '.agentId' | uniq); do
  echo -n "$id: "
  jq -r ".message.content" ~/.claude/projects/{project-hash}/agent-${id}.jsonl | head -1 | cut -d: -f1
done

Example output:

20b05857: Rick
3a22e872: Morty

Resumption: Agent targeted by ID, {name} not needed.

Resume agent-{agentId}: "Continue to next phase."
attiasr · 9 months ago

For anyone looking to enable agent resumption via claude-code (requires jq):

# post-task.sh
#!/usr/bin/env bash
# PostToolUse hook for agentId tracking
# Injects active agent information into Claude's context after Task tool invocations

set -euo pipefail

# Determine plugin root directory (same as session-start.sh)
# CLAUDE_PLUGIN_ROOT is provided by Claude Code, but we compute it as fallback
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "${SCRIPT_DIR}/.." && pwd)}"

# Read hook data from stdin
HOOK_DATA=$(cat)

# Only process Task tool invocations
TOOL_NAME=$(echo "$HOOK_DATA" | jq -r '.tool_name')
if [[ "$TOOL_NAME" != "Task" ]]; then
  exit 0
fi

# Extract agent information
AGENT_ID=$(echo "$HOOK_DATA" | jq -r '.tool_response.agentId // null')
SUBAGENT_TYPE=$(echo "$HOOK_DATA" | jq -r '.tool_input.subagent_type')
RESUME=$(echo "$HOOK_DATA" | jq -r '.tool_input.resume // null')

# Only process if we have a valid agentId
if [[ "$AGENT_ID" != "null" && -n "$AGENT_ID" ]]; then

  # === Context Injection ===
  # Determine if this is a new agent or resumed agent
  if [[ "$RESUME" == "null" ]]; then
    MSG="Active agent: $AGENT_ID ($SUBAGENT_TYPE)"
  else
    MSG="Resumed agent: $AGENT_ID ($SUBAGENT_TYPE)"
  fi

  # Inject context into Claude's conversation
  jq -n --arg msg "$MSG" '{
    hookSpecificOutput: {
      hookEventName: "PostToolUse",
      additionalContext: ("<system-reminder>\($msg)</system-reminder>")
    }
  }'
fi

exit 0

your .claude/settings.json:

{
...
  "hooks": {
...
    "PostToolUse": [
      {
        "matcher": "Task",
        "hooks": [
          {
            "type": "command",
            "command": "<path-to-script>/post-task.sh"
          }
        ]
      }
    ]
  }
}
timgu0 · 8 months ago

Added agentId to 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.

wengqizun · 8 months ago
Added agentId to the model prompt (and it should already be part of the cli UI): <img alt="Image" width="708" height="252" src="https://private-user-images.githubusercontent.com/213701943/523482002-b54f143f-cb5a-4d0f-8abc-7bb67d639cd9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjU1NDAxMjcsIm5iZiI6MTc2NTUzOTgyNywicGF0aCI6Ii8yMTM3MDE5NDMvNTIzNDgyMDAyL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YTU0MTNmMDYzNTlhOTg5ZTdmNzY5N2RlYWE3M2NmNTQ3ZmViMTU3MDUzODI5OTRlYTFiYTg4NTA0YmE5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9._ZGqeA-Mbid0bLBfkv2CHz6KfJf2ppORyln5MD8pHXA"> 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.

wengqizun · 8 months ago

<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?

wengqizun · 8 months ago
<img alt="Image" width="896" height="948" src="https://private-user-images.githubusercontent.com/6283862/526186374-0d43d6cd-de69-4d19-9fbe-5a9d8a84a971.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjU2MjgxMzYsIm5iZiI6MTc2NTYyNzgzNiwicGF0aCI6Ii82MjgzODYyLzUyNjE4NjM3NC0wZDQzZDZjZC1kZTY5LTRkMTktOWZiZS01YTlkOGE4NGE5NzEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MTIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTEyMTNUMTIxMDM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjgwZDE3MTg1NjM0YzJhZDk2MTAzYzJiZjMxNjg5Y2RmZmViNjM4M2E2ZTA2NmQwNDIzNDAzNjM1ZGJmYmRjMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.HfNh1ljlWxga_g0YgkhLDjt5F5MRtwOFqeYBRDeCsMk"> 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

github-actions[bot] · 8 months ago

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.