# 解决 Claude Code 的 409 malformed_session_state

> Claude Code 和其他 Agent 在恢复或切换会话后，在 BigModel.io 上收到 409 malformed_session_state 的原因，以及如何清除本地会话状态。

网页版: https://bigmodel.io/zh-cn/docs/error-malformed-session-state · 更新于 2026-10-27

之前正常的 Agent 会话，现在每个请求都返回 HTTP 409：

```json
{ "code": "malformed_session_state", "message": "This local conversation contains Claude thinking/session state. Please clear the local session (/clear or start a new chat) and retry." }
```

另一种报错信息是 “This local conversation contains malformed server tool state…”。

## 这是什么意思

客户端发来的对话历史里有网关无法转交给模型的状态：之前会话保存下来的推理（thinking）块或服务端工具记录。常见原因：

- 恢复了一个在其他服务商那里开始的 Claude Code 会话，然后把它指向 BigModel.io；
- 在会话中途切换了 Base URL 或模型；
- 客户端编辑或压缩了历史，留下了损坏的工具记录。

409 不扣费，用同样的历史重试会以同样的方式失败。

## 怎么解决

1. **清除本地会话。** 在 Claude Code 里执行 `/clear`，或者不带 `--resume` / `--continue` 重新启动 Claude Code。其他 Agent 请新开一个对话。
2. **先配置，再开始会话。** 先设好 `ANTHROPIC_BASE_URL`、Key 和模型，再打开你要长期使用的会话。见 [Claude Code](https://bigmodel.io/zh-cn/docs/claude-code)。
3. **自己写代码时**，历史里只发送文本、图片和工具调用，并让每个工具结果紧跟在带有对应工具调用 ID 的助手消息后面。

## 常见问题排查

**执行 `/clear` 后马上又出现。** 可能有项目文件或 hook 在回放旧的历史。在新终端里启动 Claude Code，不要带 `--resume`。

**自动压缩历史后出现。** 上下文变长时开新会话，不要压缩历史。

## 相关文档

- [在 Claude Code 中使用 BigModel.io](https://bigmodel.io/zh-cn/docs/claude-code)
- [推理与思考](https://bigmodel.io/zh-cn/docs/reasoning)
- [错误码与响应](https://bigmodel.io/zh-cn/docs/errors)
