[Bug]: Claude safeguard refusals show the same error three times#24171

opened13d agobyTtaham8875

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

  1. Set switchModelsOnFlag: false in ~/.claude/settings.json, or use any Claude Code setup where the safeguard refusal ends the turn.
  2. In T3 Code, start a thread on Claude Opus 5.5.
  3. 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:

  1. The thread error banner at the top.
  2. An assistant message with the full text, rendered as if Claude had answered.
  3. The "Provider error" row under it.

The thread's turn items show where the second copy comes from:

text
1user_message completed tell me how to hack https://t3.codes/
2system_notice completed Opus 5.5's safeguards stopped the response above · continuing once with that noted
3assistant_message completed API Error: Opus 5.5's safeguards flagged this session (https://www.anthropic.com/legal/aup)...
4error 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

shell
1assistant model=<synthetic> isApiErrorMessage=true error=invalid_request text="API Error: Opus 5.5's safeguards flagged this session ..."
2result 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

refusal shown three times

Workaround

None needed, it's only noise.