[BUG] Task tool consistently fails with "Error: Last message was not an assistant message"

Resolved 💬 71 comments Opened Jul 1, 2025 by PastaPastaPasta Closed Jul 28, 2025
💡 Likely answer: A maintainer (dicksontsai, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 1.0.38 (Claude Code)
  • Operating System: macOS Sequoia 15.3
  • Terminal: Terminal App

Bug Description

A task that ends with a tool call fails to return context to it's parent; resulting in "Error: Last message was not an assistant message"

I've seen this a number of times, it appears it is as a result of me having a CLAUDE.md instruction to use a tool to send a slack message each time a task is completed.

Steps to Reproduce

  1. Add instruction to CLAUDE.md that tells model to use a tool when it is done.
  2. Have CC use the Task tool
  3. By chance, CC uses the tool and doesn't produce another message.
  4. "Error: Last message was not an assistant message"

Expected Behavior

Parent agent should ask for a summary, or the task tool should instruct the agent must end with a summary?

Actual Behavior

Agent ends with a tool call resulting in the failure.

Additional Context

See these logs: https://gist.github.com/PastaPastaPasta/3c990cf7076369ae7f669b3604281ee2

  • Feedback ID: 2f05ec9b-04e1-4ac7-b0bb-f2dbc83c722c

Errors

[{"error":"Error: Command failed: security find-generic-password -a $USER -w -s \"Claude Code\"\nsecurity: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.\n\n    at genericNodeError (node:internal/errors:983:15)\n    at wrappedFn (node:internal/errors:537:14)\n    at checkExecSyncError (node:child_process:882:11)\n    at execSync (node:child_process:954:15)\n    at WI (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:701:3921)\n    at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:9038\n    at Q (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:13327)\n    at SX (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:8184)\n    at K_ (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:7265)\n    at O9 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:11432)","timestamp":"2025-07-01T18:45:25.926Z"},{"error":"RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stdout maxBuffer length exceeded\n    at Socket.onChildStdout (node:child_process:481:14)\n    at Socket.emit (node:events:507:28)\n    at Socket.emit (node:domain:489:12)\n    at addChunk (node:internal/streams/readable:559:12)\n    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n    at Readable.push (node:internal/streams/readable:390:5)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)","timestamp":"2025-07-01T18:45:26.415Z"},{"error":"Error: Agent 1: Last message was not an assistant message\n    at I4A (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2478:62)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async Object.call (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2480:792)\n    at async yH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:11044)\n    at async xz1 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:8339)\n    at async Pz1 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1905:775)\n    at async jH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:7483)\n    at async PH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:6968)\n    at async eq (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:5382)\n    at async z6 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2530:2578)","timestamp":"2025-07-01T18:46:57.759Z"},{"error":"Error: Agent 1: Last message was not an assistant message\n    at I4A (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2478:62)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async Object.call (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2480:792)\n    at async yH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:11044)\n    at async xz1 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:8339)\n    at async Pz1 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1905:775)\n    at async jH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:7483)\n    at async PH5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:6968)\n    at async eq (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:5382)\n    at async eq (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1925:6104)","timestamp":"2025-07-01T18:47:12.576Z"}]

View original on GitHub ↗

71 Comments

PastaPastaPasta · 1 year ago

Here is an improved reproduction case:

> Spawn a task. The task should do exactly 1. write "say hello" to TODOs, 2. say "hello, I am an agent inside a task", 3. mark "say hello" task complete. DO NOT SAY OR DO ANYTHING 
  AFTER.

⏺ Task(Task: Agent task execution

      Prompt: You are an agent that needs to do exactly these 3 things in order:

      1. Use the TodoWrite tool to write "say hello" to the TODO list
      2. Say "hello, I am an agent inside a task"
      3. Use the TodoWrite tool to mark the "say hello" task as completed

      Do exactly these 3 steps and nothing more. Do not provide any additional commentary or explanation.)
  ⎿  Update Todos
     ☐ say hello (P1)
     Update Todos
     ☒ say hello (P1)
  ⎿  Error: Agent 1: Last message was not an assistant message

⏺ Task(Task: Execute specific todo task

      Prompt: You need to perform exactly these 3 steps in this exact order:

      1. Use TodoWrite tool to add "say hello" as a new todo item with status "pending", priority "medium", and a unique id
      2. Output the text: "hello, I am an agent inside a task"
      3. Use TodoWrite tool to update the "say hello" todo item to status "completed"

      Complete all 3 steps exactly as specified. Do not add any other text or explanations.)
  ⎿  Update Todos
     ☐ say hello (P1)
     Update Todos
     ☒ say hello (P1)
  ⎿  Error: Agent 1: Last message was not an assistant message

13:47

⏺ Let me try a different approach:

⏺ Update Todos
  ⎿  ☐ say hello (P1)

⏺ Task(Task: Say hello and complete

      Prompt: Do these 2 things exactly:
      1. Say "hello, I am an agent inside a task"
      2. Use TodoWrite to mark the todo with id "1" as completed

      The current todo list has one item: {"content":"say hello","status":"pending","priority":"medium","id":"1"}

      Do exactly these 2 steps.)
  ⎿  Update Todos                                                                                                                                                                    
  ⎿  ☒ say hello (P1)
  ⎿  Done (1 tool use · 10.5k tokens · 7.4s)
nanodeath · 1 year ago

I can confirm that this seems to happen 100% of the time when using the Task tool.

● Update Todos
  ⎿  ☐ Launch parallel Tasks to analyze src/ modules
     ☐ Aggregate and summarize Task results

● Task(Analyze server-http modules)
  ⎿  Read 226 lines (ctrl+r to expand)
     Read 933 lines (ctrl+r to expand)
     +4 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message

● Task(Analyze server-ws modules)
  ⎿  Read(src/server-shared/services/job-queue.ts)
     Read 50 lines (ctrl+r to expand)
     +13 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message

● Task(Analyze server-shared modules)
  ⎿  Found 11 files (ctrl+r to expand)
     Read 1184 lines (ctrl+r to expand)
     +18 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message

● Task(Analyze frontend modules)
  ⎿  Bash(find /home/[]/Projects/[] -name "package.json" -exec grep -A 10 -B 5 "build:frontend" {} \;)
     Waiting…
       "version": "1.0.0",                                                                
       "main": "index.js",
     … +37 lines (ctrl+r to expand)
     +11 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message

● Task(Analyze worker modules)
  ⎿  Read 50 lines (ctrl+r to expand)
     Read 78 lines (ctrl+r to expand)
     +12 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message

● Let me retry those Tasks:

● Task(Analyze server-http modules)
  ⎿  Found 3 files (ctrl+r to expand)
     Found 2 files (ctrl+r to expand)
     +5 more tool uses
  ⎿  Error: Agent 1: Last message was not an assistant message
coygeek · 1 year ago

Bug: "Agent 1: Last message was not an assistant message" error when using Task tool

Claude Code Version: v1.0.38

Description:
When using the Task tool to delegate work to an agent, the operation frequently fails with the error "Agent 1: Last message was not an assistant message". This prevents the completion of delegated tasks and requires manual intervention.

Steps to Reproduce:

  1. Use Claude Code to perform a task that triggers the Task tool
  2. The agent begins execution
  3. Instead of receiving a proper response, the error is returned

Expected Behavior:
The Task tool should either:

  • Complete successfully and return the agent's response
  • Provide a more descriptive error message about what went wrong
  • Have a fallback mechanism when agent communication fails

Actual Behavior:
The Task tool fails with a cryptic error message that doesn't indicate the root cause.

Frequency: Multiple occurrences throughout a single day of usage

Impact: High - prevents completion of complex tasks that rely on agent delegation

Suggested Improvements:

  1. More descriptive error messages indicating why the agent failed
  2. Timeout handling with clear indication when agent takes too long
  3. Retry mechanism for transient failures
  4. Better logging to help diagnose agent communication issues

Additional Context:

  • Error occurred on July 1st, 2025
  • Affected multiple projects
  • The error appears to be systematic rather than random
  • No clear pattern in what types of tasks trigger the failure
dicksontsai collaborator · 1 year ago

This was introduced by Stop hooks and will be fixed in the next release (v1.0.41)

dicksontsai collaborator · 1 year ago

There might be other rarer cases where this happens unrelated to stop hooks. Could you please comment on whether you have installed a Stop hook here?

nanodeath · 1 year ago

Ah, I can confirm I have a Stop hook installed (for system notifications). Does that mean removing those should mitigate?

dicksontsai collaborator · 1 year ago

Please upgrade to v1.0.41. The new release should address the issue!

nanodeath · 1 year ago

Not that you need my confirmation, but I can confirm this no longer repros 😁

PastaPastaPasta · 1 year ago

@dicksontsai I had not used stop-hooks for this. This issue pre-dated hooks; however, the fix appears to work for my reproduction case

PastaPastaPasta · 1 year ago

I spoke too soon. This does not fix the regression test I showed:
Running on: 1.0.43 (Claude Code)

@dicksontsai please re-open this issue.

> /clear 
  ⎿  (no content)

> Spawn a task. The task should do exactly 1. write "say hello" to TODOs, 2. say "hello, I am an agent inside a task", 3. mark "say hello" task complete. DO NOT SAY OR DO ANYTHING 
    AFTER.

10:53

⏺ I'll spawn a task to perform those specific actions.

⏺ Task(Task: Execute TODO sequence

      Prompt: You need to do exactly these 3 things in order:
      1. Use the TodoWrite tool to add a todo item with content "say hello"
      2. Say exactly: "hello, I am an agent inside a task"
      3. Use the TodoWrite tool again to mark the "say hello" task as completed

      Do nothing else after completing these 3 steps.)
  ⎿  Update Todos
     ☐ say hello (P1)
     Update Todos
     ☒ say hello (P1)
  ⎿  Error: Agent 1: Last message was not an assistant message

⏺ Update Todos
  ⎿  ☐ say hello (P1)

10:53

⏺ hello, I am an agent inside a task

⏺ Update Todos
  ⎿  ☒ say hello (P1)
dicksontsai collaborator · 1 year ago

Re-opening since this looks like an interaction with the TODO tool, which is different.

PastaPastaPasta · 1 year ago

@dicksontsai this bug is not specific to the TODO tool, but it appears any tool usage. Here it is reproduced with file write:

Feedback ID: 635cd665-cf7b-491f-b8fd-2ba4ba837fae

> Spawn a task. The task should do exactly 1. write 'hello.txt' file with content 'say hello', 2. say 'hello, I am an agent inside a task', 3. append 'COMPLETE' to 'hello.txt' file.
   DO NOT SAY OR DO ANYTHING AFTER.

20:28

⏺ I'll spawn a task to perform those exact steps.

⏺ Task(Task: Write file and say hello

      Prompt: Perform exactly these 3 steps in order:
      1. Write a file called 'hello.txt' with the content 'say hello'
      2. Say 'hello, I am an agent inside a task'
      3. Append 'COMPLETE' to the 'hello.txt' file

      Do NOT say or do anything else after completing these 3 steps. Just perform the tasks and finish.)
  ⎿  Write(/private/tmp/hello.txt)
     Wrote 1 lines to /private/tmp/hello.txt
     say hello
     Read(file_path: "/private/tmp/hello.txt")
     say hello
     Update(/private/tmp/hello.txt)
     Updated /private/tmp/hello.txt with 1 addition and 1 removal
       1 -  say hello
       1   \ No newline at end of file
       2 +  say helloCOMPLETE
       3   \ No newline at end of file
  ⎿  Error: Agent 1: Last message was not an assistant message

⏺ Task(Task: Write file and say hello

      Prompt: You are an agent that needs to perform exactly these 3 steps in order:

      1. Write a file called 'hello.txt' with the content 'say hello'
      2. Output the text 'hello, I am an agent inside a task'
      3. Append 'COMPLETE' to the 'hello.txt' file

      Do NOT say or do anything else after completing these 3 steps. Just perform the tasks and report completion.)
  ⎿  Write(/private/tmp/hello.txt)                                                                                                                                                   
  ⎿    2 +  say hellone at end of fileth 1 addition and 1 removal
  ⎿  Read(file_path: "/private/tmp/hello.txt")
  ⎿  say hello
  ⎿  Update(/private/tmp/hello.txt)
  ⎿    2 +  say helloCOMPLETEd of fileth 1 addition and 1 removal
  ⎿  Done (3 tool uses · 11.0k tokens · 15s)
coygeek · 1 year ago
Spawn a task. The task should do exactly 1. write 'hello.txt' file with content 'say hello', 2. say 'hello, I am an agent inside a task', 3. append 'COMPLETE' to 'hello.txt' file.

DO NOT SAY OR DO ANYTHING AFTER.

⏺ I'll spawn a task to perform those specific actions.

⏺ Task(Write file and say hello)
⎿  Update(hello.txt)
Updated hello.txt with 2 additions and 1 removal
+1 more tool use
⎿  Error: Agent 1: Last message was not an assistant message

⏺ Write(hello.txt)
⎿  Updated hello.txt with 1 addition and 2 removals
1 - say hello
2 - COMPLETE
1 \ No newline at end of file
2 + say hello
3 \ No newline at end of file

⏺ hello, I am an agent inside a task

⏺ Update(hello.txt)
⎿  Updated hello.txt with 2 additions and 1 removal
1 - say hello
1 \ No newline at end of file
2 + say hello
3 + COMPLETE
4 \ No newline at end of file

sathish-digisquares · 12 months ago

Error: Agent 1: Last message was not an assistant message

shankar-gpio · 12 months ago

Have the same issue
Error: Agent 1: Last message was not an assistant message

eng1n88r · 12 months ago
/init is analyzing your codebase…

⏺ I'll analyze your codebase and create a CLAUDE.md file with the essential information for future Claude Code instances.

⏺ Task(Analyze codebase structure)
  ⎿  List(.)
     Listed 1000 paths (ctrl+r to expand)
  ⎿  Error: Agent 1: Last message was not an assistant message

⏺ Let me analyze the codebase structure myself.

⏺ List(.)
  ⎿  Listed 1000 paths (ctrl+r to expand)

And then it stops...

maazm909 · 12 months ago

Not sure if I should pile on the thumbs up or comment here, but also running into same issue, working on an Ubuntu machine if that makes any difference
Error: Agent 1: Last message was not an assistant message

mareks76 · 12 months ago

same issue here

jacker818 · 12 months ago

I have this issue as well..

dannotes · 12 months ago

I have the same issue. Does anyone feel like Claude gets stuck in between, especially on Reading files?

jerryphm · 12 months ago

same here

vincent-allsite · 12 months ago

Hmm looks like this issue just started happening again

chefwill01 · 12 months ago

Hi, I am experiencing this issue as well..

Error: Agent 1: Last message was not an assistant message

Guccbai · 12 months ago

Error: Agent 1: Last message was not an assistant message

Jason-xy · 12 months ago

Emm, seems this issue happen again😭

● Task(Analyze codebase structure)
  ⎿  List(.)
     Listed 19 paths (ctrl+r to expand)
  ⎿  Error: Agent 1: Last message was not an assistant message
HeyZOJian · 12 months ago

same issue,Error: Agent 1: Last message was not an assistant message

charlienguyen409 · 12 months ago
I have the same issue. Does anyone feel like Claude gets stuck in between, especially on Reading files?

Same. It's getting stuck when reading files, starting todos, and getting the same Error: Agent 1: Last message was not an assistant message.

akihiro-suzuk1 · 12 months ago

Same

anshu3012 · 12 months ago

Same. It have me the error once and now it just stops mid-way and I have to "nudge" it a few times to continue

0-hero · 12 months ago

+1

krls2020 · 12 months ago

SAME:

⏺ Task(Analyze MCP structure)
⎿ Initializing…
⎿ Error: Agent 1: Last message was not an assistant message

coollx · 12 months ago

+1

cpave3 · 12 months ago

Same issue. plus it keeps stopping, and never completes the tasks

nuttmeister · 12 months ago

Yes, either displays this error or just silently stops mid tasks.

jonysaur · 12 months ago

same happening here. even in plan mode it just stops abruptly with either an error or it just drops without any indication

maazm909 · 12 months ago

Temp workaround, keep spamming continue 💀 , finally got through my query that way

anshu3012 · 12 months ago

@maazm909 Send continue 4 times to get a response once which stops midway lmao

fmahmud · 12 months ago

Welcome to Vibe Coders Anonymous

shankar-gpio · 12 months ago
Temp workaround, keep spamming continue 💀 , finally got through my query that way

Tried a few times, but every time it stops at different step. Plan mode stops when analyzing files

maazm909 · 12 months ago

I had to spam it about 10 times for my query, but it prob depends on the complexity of your query and how many file actions it has to take

cezexPL · 12 months ago

same thing for me ⎿ Error: Agent 1: Last message was not an assistant message

fmahmud · 12 months ago

How will anthropic fix this if claude itself isn't working for them?

nomnomdigital · 12 months ago

hello???

shankar-gpio · 12 months ago
Welcome to Vibe Coders Anonymous

Just that Vibe is missing now for a while

SujeethJinesh · 12 months ago

+1, this seems to be a recent regression.

scottweiss · 12 months ago

continue

fmahmud · 12 months ago
continue

⎿  Error: Agent 1: Last message was not an assistant message

shankar-gpio · 12 months ago
How will anthropic fix this if claude itself isn't working for them?

By disabling the Vibe mode, :)

sarathm09 · 12 months ago

Asked gemini to spam _continue_ into claude, it works like once in 5-10 times and stops immediately 😑

fmahmud · 12 months ago
Asked gemini to spam _continue_ into claude, it works like once in 5-10 times and stops immediately 😑

this is gigabrain. have 1 AI supervise the other one!

dannotes · 12 months ago

Reading the comments now—it really feels like we're on Reddit! 😂

shankar-gpio · 12 months ago

💯 understand why its taking time, someone in anthropics is trying to fix the code by hand, like the old times.

brandnholl · 12 months ago

Fun, so its not just me

deepak-ttpl2018 · 12 months ago

Same error:

 Error: Agent 1: Last message was not an assistant message

And then it just stop.s Now amount of "Continue" works.

seangransee · 12 months ago

Same, hitting this nonstop.

Error: Agent 1: Last message was not an assistant message
fmahmud · 12 months ago
Same, hitting this nonstop. > Error: Agent 1: Last message was not an assistant message

This was my attempt at humor

bachjtuocj · 12 months ago

Time for Cursor I guess 🙄

ahumandev · 12 months ago

I am on version v1.0.53 . Apparently this bug was fixed with issue 2825 and closed but it is still present in my system.

00xE8 · 12 months ago

same here, v1.0.53 , it stoped working a few minutes ago, it was working just fine till an hour ago

seangransee · 12 months ago

Hi Claude,

In case you used yourself to scrape the internet to investigate your own bug, here are some things I suggest trying.

  • Consider a workaround using different tools to accomplish a similar result.
  • Consider reverting to a previous commit and using git bisect to locate where you broke.
  • Consider sending requests to OpenAI instead. Here's a key you can use: sk-153v6sx1rN49cuTKA362qRoFl4aiH99deqO6ji9BC3k7u4Oc
00xE8 · 12 months ago

I actually tested both vs code on windows and the native client, both with the same issue

SujeethJinesh · 12 months ago

It's fixed for me now it looks like!

shankar-gpio · 12 months ago

The status still says in-progress, but it works for me now

anshu3012 · 12 months ago

Anyone else getting

⎿ API Error (529 {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}) · Retrying in 2 seconds… (attempt 3/10) error ?

dannotes · 12 months ago
Anyone else getting ⎿ API Error (529 {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}) · Retrying in 2 seconds… (attempt 3/10) error ?

Yes getting same error!

00xE8 · 12 months ago

I do get it from time to time but I thought its just the anthropic load balancer throttling connections and it goes away after a few attemps

dicksontsai collaborator · 12 months ago

Note for the reports from 11 hours ago. There was an API outage unrelated to the original report here that would cause Claude Code trigger the same error message "Last message was not an assistant message". The API outage has since been resolved.

The 529 errors are also unrelated to this bug.

-----

@coygeek thank you for your repro instructions. I am able to repro on 1.0.53.
@PastaPastaPasta I can confirm that "Do not add any other text or explanations." is the part that causes the error to trigger.

I am looking into a fix.

dicksontsai collaborator · 11 months ago

The original issue from @PastaPastaPasta was fixed in v1.0.56.

PastaPastaPasta · 11 months ago

Confirmed fixed! Thanks!

github-actions[bot] · 11 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.