Skip to content

A simple pattern patcher for Claude Code Issue 4510 to temporarily handle CLAUDE_CODE_MAX_OUTPUT_TOKENS bug

Notifications You must be signed in to change notification settings

nmindz/claudio-4510

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Token Limit Patcher

A tool to fix the token limit bug in Anthropic's Claude Code CLI until an official fix is released.

🐛 The Problem

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

🔧 The Solution

This patcher automatically finds and fixes the token limit function in Claude Code's minified CLI, regardless of function name changes across versions.

Key Features

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

🚀 Quick Start

Option 1: Patch Global Installation (Recommended)

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

Option 2: Patch Specific Files

# Patch a specific file
node patcher.js input_cli.js output_cli.js

# View usage help
node patcher.js --help

📋 Installation

  1. Clone this repository:

    git clone <repository-url>
    cd claude-code-patches
  2. Run the patcher:

    node patcher.js --global

That's it! Your Claude Code CLI now supports the correct token limits.

🛠️ Usage Options

Global Installation Patching

# 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

File-based Patching

# Patch specific files
node patcher.js input_file.js output_file.js

# Default behavior (looks for original_cli.js)
node patcher.js

Help and Information

# Show all available options
node patcher.js --help

# Show version information
node patcher.js --version

📁 How It Works

The patcher:

  1. Locates the target function using pattern matching (not function names)
  2. Creates a backup of the original file (for --global mode)
  3. Applies the token limit fix by replacing the function body
  4. Verifies the patch was applied correctly
  5. Reports success/failure with detailed information

Function Pattern

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}

⚠️ Important Notes

  • Backup First: The --global mode 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 --restore if you encounter issues

🔍 Verification

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

🆘 Troubleshooting

Common Issues

"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

Getting Help

  • Check node patcher.js --status for diagnostic information
  • Use node patcher.js --help for usage details
  • Create an issue on GitHub with error messages and CLI version

📜 License

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.

About

A simple pattern patcher for Claude Code Issue 4510 to temporarily handle CLAUDE_CODE_MAX_OUTPUT_TOKENS bug

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published