[Regression 2.1.9] max_tokens off-by-one: MAX_THINKING_TOKENS=64000 sends 64001 to API

Resolved 💬 4 comments Opened Jan 16, 2026 by rso42 Closed Feb 28, 2026

Preflight Checklist

  • [x] I have searched existing issues 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?

When MAX_THINKING_TOKENS is set to exactly the API limit (64000), the actual API request sends max_tokens: 64001 — one more than configured. This causes a 400 error because 64001 exceeds the model's 64000 limit.

The arithmetic suggests somewhere in the 2.1.9 changes, a +1 was added to the max_tokens calculation path.

What Should Happen?

MAX_THINKING_TOKENS=64000 should result in max_tokens: 64000 in the API request, not 64001.

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 64001 > 64000, which is the maximum allowed number of output tokens for claude-opus-4-5-20251101"},"request_id":"req_xxxxxx"}

Steps to Reproduce

  1. Create/edit ~/.claude/settings.json:

```json
{
"env": {
"MAX_THINKING_TOKENS": "64000"
},
"alwaysThinkingEnabled": true
}

  1. Start new Claude Code session: claude
  2. Send any message
  3. First API call fails with 400 error

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.8

Claude Code Version

2.1.9 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Workaround: Set MAX_THINKING_TOKENS to 63999

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗