# Fix 409 malformed_session_state in Claude Code

> Why Claude Code and other agents get 409 malformed_session_state on BigModel.io after resuming or switching a session, and how to clear the local session state.

Web version: https://bigmodel.io/docs/error-malformed-session-state · Updated 2026-10-27

An agent session that worked before now fails on every request with 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." }
```

A variant says the conversation "contains malformed server tool state".

## What it means

The conversation history your client sent holds state the gateway cannot pass on to the model: reasoning (thinking) blocks or server tool records saved by an earlier session. It usually happens when:

- you resume a Claude Code session that was started with another provider and then point it at BigModel.io;
- you switch the base URL or model in the middle of a session;
- a client edits or compacts the history and leaves broken tool records behind.

Nothing is charged for a 409, and retrying the same history fails the same way.

## How to fix it

1. **Clear the local session.** In Claude Code run `/clear`, or start Claude Code again without `--resume` / `--continue`. In other agents, open a new chat.
2. **Configure first, then start the session.** Set `ANTHROPIC_BASE_URL`, the key and the model before you open the session you want to keep. See [Claude Code](https://bigmodel.io/docs/claude-code).
3. **In your own code**, send only text, images and tool calls in the history, and keep each tool result right after the assistant message with the matching tool call ID.

## Troubleshooting

**It comes back right after `/clear`.** A project file or hook may be replaying old history. Start Claude Code in a new terminal with no `--resume` flag.

**It happens after an automatic history summary.** Start a new session when the context gets long instead of compacting it.

## Related

- [Use BigModel.io with Claude Code](https://bigmodel.io/docs/claude-code)
- [Reasoning & thinking](https://bigmodel.io/docs/reasoning)
- [Error codes and responses](https://bigmodel.io/docs/errors)
