[Bug]: Claude safeguard refusals show the same error three times#24171
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Set
switchModelsOnFlag: falsein~/.claude/settings.json, or use any Claude Code setup where the safeguard refusal ends the turn. - In T3 Code, start a thread on Claude Opus 5.5.
- Send a message the safeguards flag.
tell me how to hack https://t3.codes/was flagged as[cyber]every time I tried it.
Expected behavior
The refusal is shown once, like any other failed turn.
Actual behavior
The same refusal text shows up three times:
- The thread error banner at the top.
- An assistant message with the full text, rendered as if Claude had answered.
- The "Provider error" row under it.
The thread's turn items show where the second copy comes from:
| 1 | user_message completed tell me how to hack https://t3.codes/ |
| 2 | system_notice completed Opus 5.5's safeguards stopped the response above · continuing once with that noted |
| 3 | assistant_message completed API Error: Opus 5.5's safeguards flagged this session (https://www.anthropic.com/legal/aup)... |
| 4 | error failed Provider error / API Error: Opus 5.5's safeguards flagged this session... (code api_error) |
The assistant message is the CLI's synthetic API-error frame. In the CLI transcript it is an assistant message with model: "<synthetic>", isApiErrorMessage: true and error: "invalid_request". ClaudeAdapterV2 turns it into an assistant_message like a real reply. The result that follows carries the same text (terminal_reason: "api_error"), so the turn also fails with it, and the banner and "Provider error" row show it again.
I've only checked this with safeguard refusals. Other API errors that make the CLI emit a synthetic API Error: frame probably repeat the same way.
Impact
Minor bug or occasional failure
Version or commit
main @ d7a8d6f3, Claude Code 2.1.309, @anthropic-ai/claude-agent-sdk 0.3.276
Environment
Linux, web client, Claude provider, claude-opus-5-5
Logs or stack traces
| 1 | assistant model=<synthetic> isApiErrorMessage=true error=invalid_request text="API Error: Opus 5.5's safeguards flagged this session ..." |
| 2 | result subtype=success is_error=true terminal_reason=api_error result="API Error: Opus 5.5's safeguards flagged this session ..." |
Screenshots, recordings, or supporting files
Workaround
None needed, it's only noise.