anthropics / anthropics/claude-code

[BUG] Interactive CLI fails after tool calls while Desktop Code and claude -p work reliably

Abierto
#87,531 0 comentarios 0 reacciones 0 asignados Ver en GitHub
area:core bug has repro platform:macos stale
Lenguaje dominante
Python
Estrellas
145k
Forks
23.1k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code

### What's Wrong?

Interactive Claude Code sessions consistently fail immediately after one or more tool calls with:

API Error: An error occurred while processing the request.

The same machine, account, models, and network work correctly in Claude Desktop's Code tab and in headless `claude -p` mode.

I reproduced this with both Opus 5 and Sonnet 5, with Headroom/Bedrock/custom ANTHROPIC_BASE_URL completely bypassed.

In some cases the interactive CLI fails after only a single Read or Bash tool call.

With normal fallback behavior enabled, the error sometimes appears as:

API Error: API returned an empty or malformed response (HTTP 200)

with diagnostics saying the initial streaming request received 0 stream events and the non-streaming retry unexpectedly received an event-stream.

With CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1, the misleading fallback error disappears, but the underlying request still fails with Anthropic api_error.

### What Should Happen?

After a Read, Bash, Search, MCP, or other tool completes, Claude Code should successfully send the tool result back to the model and continue the interactive turn.

Interactive CLI sessions should behave consistently with Claude Desktop Code and `claude -p` on the same machine/account.

### Error Messages/Logs

```shell
Interactive error:

API Error: An error occurred while processing the request.

Debug log from a direct Anthropic/Claude Max session:

2026-08-18T02:34:53.908Z [DEBUG] [API REQUEST] /v1/messages source=repl_main_thread
2026-08-18T02:35:23.910Z [WARN] Slow first byte: no stream chunk 30.0s after request sent (attempt 1)
2026-08-18T02:35:31.237Z [ERROR] Error streaming (non-streaming fallback disabled): {"type":"error","error":{"type":"api_error","message":"An error occurred while processing the request."}}
2026-08-18T02:35:31.238Z [ERROR] Error in API request: {"type":"error","error":{"type":"api_error","message":"An error occurred while processing the request."}}
2026-08-18T02:35:31.266Z [ERROR] [engine] turn ended in error: API Error: An error occurred while processing the request.

Without CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1 I also received:

API Error: API returned an empty or malformed response (HTTP 200) — check for a proxy or gateway intercepting the request.

Response: content-type event-stream, body is an event stream (the non-streaming request was answered with a stream), request-id req_011Ce9Ykomb88Rn3EhCciHaf, server cloudflare. This was the non-streaming retry of streaming request, which failed with: other; 0 stream events received.
```

### Steps to Reproduce

1. On macOS, start a clean Claude Code interactive session directly against Claude Max:

env \
-u ANTHROPIC_BASE_URL \
-u CLAUDE_CODE_USE_BEDROCK \
-u CLAUDE_CODE_USE_MANTLE \
claude --model sonnet

2. Ask Claude to perform a coding task that requires reading/searching the local repository.

3. Claude successfully performs a Read/Bash/Search tool call.

4. The subsequent interactive model request fails with:

API Error: An error occurred while processing the request.

5. Repeat with Opus 5. The same failure occurs.

6. As a control, run headless Claude Code from the same terminal:

for i in {1..5}; do \
env -u ANTHROPIC_BASE_URL \
-u CLAUDE_CODE_USE_BEDROCK \
-u CLAUDE_CODE_USE_MANTLE \
claude -p "Reply exactly OK" --model sonnet; \
done

7. All 5 headless requests return `OK`.

8. Claude Desktop Code also works normally on the same Mac, account, network, and repository.

I reproduced the interactive failure on both Claude Code 2.1.226 and 2.1.234.

### Claude Model

Opus

### Is this a regression?

I don't know

### Last Working Version

_No response_

### Claude Code Version

2.1.234

### Platform

Anthropic API

### Operating System

macOS

### Terminal/Shell

Terminal.app (macOS)

### Additional Information

Control tests performed:

- Claude Desktop Code on the same machine/account: WORKS
- `claude -p` headless mode: 5/5 successful
- Interactive Claude Code + Sonnet 5: FAILS
- Interactive Claude Code + Opus 5: FAILS
- Opus 5 standard context: FAILS
- Opus 5 1M context: FAILS
- Claude Code 2.1.226: FAILS
- Claude Code 2.1.234: FAILS
- high and xhigh effort: FAIL
- Headroom/custom ANTHROPIC_BASE_URL completely bypassed: FAILS
- CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1: removes the malformed HTTP 200 fallback error, but the underlying Anthropic api_error remains

This appears specific to the interactive CLI continuation after tool results rather than general connectivity or model availability.

Possibly related to existing reports involving interactive streaming stalls / slow first-byte behavior, but this report adds a reproducible comparison where Desktop Code and headless `claude -p` work reliably on the same machine while interactive CLI fails.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Start by reproducing the failure with the documented interactive command, then compare it with the successful `claude -p` control while reviewing the debug logs for the post-tool request. Done means interactive sessions continue successfully after Read, Bash, Search, or MCP results on the reported versions and controls.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python, shell
Área
api, backend, cli
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Necesita aclaración
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.