Task tool fails with "Last message was not an assistant message" error when Stop hook is configured

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

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

  1. Add a Stop hook to .claude/settings.json:

``json
"hooks": {
"Stop": [{
"matcher": "",
"hooks": [{"type": "command", "command": "afplay /System/Library/Sounds/Glass.aiff"}]
}]
}
``

  1. Use the Task tool: Task(description="Test", prompt="Return the word test")
  2. 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 :)

View original on GitHub ↗

34 Comments

dicksontsai collaborator · 1 year ago

This will be fixed in the next release. I'm aware that it's a popular example.

arunjish · 1 year ago

This is fixed now in 1.0.41.
What's new:
• 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
tool_decision event

georgiedekker · 12 months ago

encountering first time today

SlimeCodex · 12 months ago

Same for me, happens a lot this few minutes.

georgiedekker · 12 months ago

Thanks for confirming. I imagine it's a little code regression. Hope a fix can be pushed out soon.

charlienguyen409 · 12 months ago

Likewise. Just started in the past few hours. @arunjish @dicksontsai

seanodonnell-udisc · 12 months ago

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.

darkguy2008 · 12 months ago

I thought it was just me:

[DEBUG] Executing hooks for PostToolUse:TodoWrite
[DEBUG] Getting matching hook commands for PostToolUse with query: TodoWrite
[DEBUG] Found 0 hook matchers in settings
[DEBUG] Matched 0 hooks for query "TodoWrite"
[DEBUG] Found 0 hook commands to execute
[DEBUG] Stream started - received first chunk
[DEBUG] executePreToolHooks called for tool: Task
[DEBUG] Executing hooks for PreToolUse:Task
[DEBUG] Getting matching hook commands for PreToolUse with query: Task
[DEBUG] Found 0 hook matchers in settings
[DEBUG] Matched 0 hooks for query "Task"
[DEBUG] Found 0 hook commands to execute
[DEBUG] Stream started - received first chunk
[DEBUG] Executing hooks for SubagentStop
[DEBUG] Getting matching hook commands for SubagentStop with query: undefined
[DEBUG] Found 0 hook matchers in settings
[DEBUG] No match query, returning all 0 hooks
[DEBUG] Found 0 hook commands to execute

● Task(Find cache system implementation)
  ⎿  Initializing…
  ⎿  Error: Agent 1: Last message was not an assistant message
[DEBUG] Stream started - received first chunk
[DEBUG] Executing hooks for Stop
[DEBUG] Getting matching hook commands for Stop with query: undefined
[DEBUG] Found 0 hook matchers in settings
[DEBUG] No match query, returning all 0 hooks
[DEBUG] Found 0 hook commands to execute
[DEBUG] Metrics opt-out API response: enabled=true
[DEBUG] BigQuery metrics exported successfully
[DEBUG] API Response: {
  "accepted_count": 13,
  "rejected_count": 0
}

The status page says all systems operational but they're evidently not 😅

mareks76 · 12 months ago

Same experience here, happening now

alittlebitweird · 12 months ago

\+ 1

islamuddin · 12 months ago

+1

goweb-dev · 12 months ago

+1

jonysaur · 12 months ago

same happening here

sgoodluck · 12 months ago

+1

koofree · 12 months ago

+1

GJmelody · 12 months ago

same here

calaunte · 12 months ago

+20

daffigusti · 12 months ago

just got this same error now.

ashi-dog · 12 months ago

+100

SonnyC56 · 12 months ago

Same for me

vibespacedevadmin · 12 months ago

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

ahumandev · 12 months ago

Not sure why you "Closed" this issue if this is still happening???

sujarniel · 12 months ago

any update??

pgvanniekerk · 12 months ago

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

nealshuh · 12 months ago

anyone listen to 2hollis

rashmiranjanrrs · 12 months ago

same for me

devkya · 12 months ago

+1

georgiedekker · 12 months ago

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!

ben1787 · 12 months ago

+1

georgiedekker · 12 months ago

We're back in action! thanks Anthropic team! real nice quick resolution of the issue!

nealshuh · 12 months ago

Works for me now :) Thank you guys!

georgiedekker · 12 months ago

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 🥺

dicksontsai collaborator · 12 months ago

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.

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.