[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
- Add instruction to CLAUDE.md that tells model to use a tool when it is done.
- Have CC use the Task tool
- By chance, CC uses the tool and doesn't produce another message.
- "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"}]
71 Comments
Here is an improved reproduction case:
I can confirm that this seems to happen 100% of the time when using the Task tool.
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:
Expected Behavior:
The Task tool should either:
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:
Additional Context:
This was introduced by Stop hooks and will be fixed in the next release (v1.0.41)
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?
Ah, I can confirm I have a Stop hook installed (for system notifications). Does that mean removing those should mitigate?
Please upgrade to v1.0.41. The new release should address the issue!
Not that you need my confirmation, but I can confirm this no longer repros 😁
@dicksontsai I had not used stop-hooks for this. This issue pre-dated hooks; however, the fix appears to work for my reproduction case
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.
Re-opening since this looks like an interaction with the TODO tool, which is different.
@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
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
Error: Agent 1: Last message was not an assistant message
Have the same issue
Error: Agent 1: Last message was not an assistant message
And then it stops...
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 messagesame issue here
I have this issue as well..
I have the same issue. Does anyone feel like Claude gets stuck in between, especially on Reading files?
same here
Hmm looks like this issue just started happening again
Hi, I am experiencing this issue as well..
Error: Agent 1: Last message was not an assistant message
Error: Agent 1: Last message was not an assistant message
Emm, seems this issue happen again😭
same issue,Error: Agent 1: Last message was not an assistant message
Same. It's getting stuck when reading files, starting todos, and getting the same Error: Agent 1: Last message was not an assistant message.
Same
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
+1
SAME:
⏺ Task(Analyze MCP structure)
⎿ Initializing…
⎿ Error: Agent 1: Last message was not an assistant message
+1
Same issue. plus it keeps stopping, and never completes the tasks
Yes, either displays this error or just silently stops mid tasks.
same happening here. even in plan mode it just stops abruptly with either an error or it just drops without any indication
Temp workaround, keep spamming continue 💀 , finally got through my query that way
@maazm909 Send continue 4 times to get a response once which stops midway lmao
Welcome to Vibe Coders Anonymous
Tried a few times, but every time it stops at different step. Plan mode stops when analyzing files
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
same thing for me ⎿ Error: Agent 1: Last message was not an assistant message
How will anthropic fix this if claude itself isn't working for them?
hello???
Just that Vibe is missing now for a while
+1, this seems to be a recent regression.
continue
⎿ Error: Agent 1: Last message was not an assistant message
By disabling the Vibe mode, :)
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!
Reading the comments now—it really feels like we're on Reddit! 😂
💯 understand why its taking time, someone in anthropics is trying to fix the code by hand, like the old times.
Fun, so its not just me
Same error:
Error: Agent 1: Last message was not an assistant message
And then it just stop.s Now amount of "Continue" works.
Same, hitting this nonstop.
This was my attempt at humor
Time for Cursor I guess 🙄
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.
same here, v1.0.53 , it stoped working a few minutes ago, it was working just fine till an hour ago
Hi Claude,
In case you used yourself to scrape the internet to investigate your own bug, here are some things I suggest trying.
git bisectto locate where you broke.sk-153v6sx1rN49cuTKA362qRoFl4aiH99deqO6ji9BC3k7u4Ochttps://status.anthropic.com/incidents/nddq02nf44lg
I actually tested both vs code on windows and the native client, both with the same issue
It's fixed for me now it looks like!
The status still says in-progress, but it works for me now
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!
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
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.
The original issue from @PastaPastaPasta was fixed in v1.0.56.
Confirmed fixed! Thanks!
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.