A tool to fix the token limit bug in Anthropic's Claude Code CLI until an official fix is released.
If you landed here from a search about the following error:
API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.
Then, you probably already know that Claude Code CLI (v1.0.83 and potentially other versions) has a bug in the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable implementation. This has been reported in the anthropics/claude-code#4510 issue.
Current Broken Behavior:
- All models are limited to a maximum of 32,000 tokens
- Sonnet models should support up to 64,000 tokens but are artificially limited
- Haiku models default to 8,192 tokens (this part works correctly)
Expected Fixed Behavior:
- Sonnet models: Support up to 64,000 tokens
- Haiku models: Default to 8,192 tokens
- All other models: Default to 32,000 tokens
This patcher automatically finds and fixes the token limit function in Claude Code's minified CLI, regardless of function name changes across versions.
✅ Version-agnostic: Works with different minified versions where function names change
✅ Pattern-based: Identifies the function by its unique signature, not name
✅ Safe: Creates backups before patching
✅ Automatic: Can patch your globally installed Claude Code CLI
✅ Verified: Compares output to ensure patch success
Automatically find and patch your globally installed Claude Code CLI:
# Patch the global Claude Code installation
node patcher.js --global
# Restore from backup if needed
node patcher.js --restore# Patch a specific file
node patcher.js input_cli.js output_cli.js
# View usage help
node patcher.js --help-
Clone this repository:
git clone <repository-url> cd claude-code-patches
-
Run the patcher:
node patcher.js --global
That's it! Your Claude Code CLI now supports the correct token limits.
# Patch global Claude Code CLI (creates backup automatically)
node patcher.js --global
# Check status of global installation
node patcher.js --status
# Restore from backup
node patcher.js --restore
# Force re-patch (overwrites existing backup)
node patcher.js --global --force# Patch specific files
node patcher.js input_file.js output_file.js
# Default behavior (looks for original_cli.js)
node patcher.js# Show all available options
node patcher.js --help
# Show version information
node patcher.js --versionThe patcher:
- Locates the target function using pattern matching (not function names)
- Creates a backup of the original file (for --global mode)
- Applies the token limit fix by replacing the function body
- Verifies the patch was applied correctly
- Reports success/failure with detailed information
The patcher looks for this specific pattern in the minified code:
{if(A.includes("3-5"))return 8192;if(A.includes("haiku"))return 8192;let B=process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS;if(B){let Q=parseInt(B,10);if(!isNaN(Q)&&Q>0&&Q<=32000)return Q;else throw new Error(`Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${B}`)}return 32000}And replaces it with:
{let maxTokens=A.includes("haiku")?8192:(A.includes("3-5")||A.includes("sonnet"))?64000:32000;let B=process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS;if(B){let Q=parseInt(B,10);if(!isNaN(Q)&&Q>0&&Q<=maxTokens)return Q;else throw new Error(`Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${B}. Must be between 1 and ${maxTokens} for model ${A}`)}return A.includes("haiku")?8192:32000}- Backup First: The
--globalmode automatically creates backups - Test After Patching: Verify Claude Code still works correctly
- Version Updates: Re-run the patcher when Claude Code updates
- Restore Available: Use
--restoreif you encounter issues
After patching, test with different models:
# Test with Sonnet (should allow up to 64,000 tokens)
CLAUDE_CODE_MAX_OUTPUT_TOKENS=50000 claude-code
# Test with Haiku (should allow up to 8,192 tokens)
CLAUDE_CODE_MAX_OUTPUT_TOKENS=8000 claude-code
# Test with other models (should allow up to 32,000 tokens)
CLAUDE_CODE_MAX_OUTPUT_TOKENS=30000 claude-code"Function pattern not found":
- The CLI version may have a different pattern
- Try updating to the latest patcher version
- File a GitHub issue with your CLI version
"Permission denied":
- Run with appropriate permissions (sudo on Linux/macOS)
- Ensure Claude Code CLI is not currently running
"Backup not found":
- Backup may not exist or was deleted
- Reinstall Claude Code CLI globally to restore original
- Check
node patcher.js --statusfor diagnostic information - Use
node patcher.js --helpfor usage details - Create an issue on GitHub with error messages and CLI version
This patcher is provided as-is for fixing a temporary bug in Claude Code CLI. Use responsibly and update to official versions when the fixes become available.
All credits to @salah9003 for finding, reporting and providing the proposed fix.
Note: This is a temporary fix while waiting for an official patch from Anthropic. Remove this patcher and reinstall Claude Code CLI once the official fix is released.