Task tool fails with "Last message was not an assistant message" error when Stop hook is configured
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Code inside of Cursor
- Claude CLI version: 1.0.38
- Operating System: macOS 15
- Terminal: Claude Code CLI
Bug Description
The Task tool fails with error "Agent 1: Last message was not an assistant message" when a Stop hook is configured in .claude/settings.json. Removing the hook fixes the issue.
Steps to Reproduce
- Add a Stop hook to
.claude/settings.json:
``json``
"hooks": {
"Stop": [{
"matcher": "",
"hooks": [{"type": "command", "command": "afplay /System/Library/Sounds/Glass.aiff"}]
}]
}
- Use the Task tool:
Task(description="Test", prompt="Return the word test") - Observe error: "Agent 1: Last message was not an assistant message"
Expected Behavior
Task tool should function normally with Stop hooks configured, or hooks should only execute for the main agent.
Actual Behavior
Task tool fails immediately for all invocations when any Stop hook is present.
Additional Context
The empty matcher "" causes the hook to fire for all agents including Task subagents, breaking their initialization. A potential solution would be to allow hooks to be disabled for Task subagents. This would also just be nice to have because I don't want to hear a notification for each subagent completion.
Thanks for the great work on cc :)
34 Comments
This will be fixed in the next release. I'm aware that it's a popular example.
This is fixed now in 1.0.41.
What's new:tool_decision• Hooks: Split Stop hook triggering into Stop and SubagentStop
• Hooks: Enabled optional timeout configuration for each command
• Hooks: Added "hook_event_name" to hook input
• Fixed a bug where MCP tools would display twice in tool list
• New tool parameters JSON for Bash tool in
eventencountering first time today
Same for me, happens a lot this few minutes.
Thanks for confirming. I imagine it's a little code regression. Hope a fix can be pushed out soon.
Likewise. Just started in the past few hours. @arunjish @dicksontsai
Seeing this as well, paired with Claude continually ceasing execution on it's current task. I see this error, and on subsequent prompts Claude starts forgetting what it is doing over and over again. I can prompt it with "use tools to continue" and it may take a few steps or none at all.
I thought it was just me:
The status page says all systems operational but they're evidently not 😅
Same experience here, happening now
\+ 1
+1
+1
same happening here
+1
+1
same here
+20
just got this same error now.
+100
Same for me
guess nobody is building anything tonight! now is the chance to throw away all the red bull cans on your desk and put the mugs in the dish washer
Not sure why you "Closed" this issue if this is still happening???
any update??
This is happening to me from this morning(1 hour ago). ANY prompt just suddenly stops, generally without even printing anything, or if it does start listing tasks I get Error: Agent 1: Last message was not an assistant message. Am not using any hooks etc nor MCP, just plain Claude Code
anyone listen to 2hollis
same for me
+1
Yeah I started working about 2 hours ago, was okay for the first half an hour, broken since. Claude code will basically not do anything for me. the status page states:
API requests stopping prematurely
Identified - The issue has been identified and a fix is being implemented.
Jul 17, 2025 - 05:04 UTC
Investigating - We are currently investigating this issue.
Jul 17, 2025 - 04:48 UTC
So it seems that they have some techs working already which is amazing! I was afraid the whole day would be a write off because if the team is only on the West Coast USA, it could be 9 hours or so before they start working.
Amazing work gents at Anthropic, looking forward to the push of the fix!
+1
We're back in action! thanks Anthropic team! real nice quick resolution of the issue!
Works for me now :) Thank you guys!
The only small issue... i think the many attempts to get any work done over the last 2 hours have been counting against my max plan usage... and now I'm out of usage for the next 2.5 hours... would be awesome if the usage over the last 2 hours that clearly was not working or working well would be reset please 🥺
For the record: There was an API outage unrelated to Stop hooks that would cause Claude Code trigger the same error message "Last message was not an assistant message". The API outage has since been resolved.
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.