Skip to content

Instantly share code, notes, and snippets.

@mbailey
Last active October 20, 2025 11:07
Show Gist options
  • Select an option

  • Save mbailey/556651142037d88d0dad8c826bae3141 to your computer and use it in GitHub Desktop.

Select an option

Save mbailey/556651142037d88d0dad8c826bae3141 to your computer and use it in GitHub Desktop.
Claude Code v2.0.22 OAuth Fix Patch

Claude Code v2.0.22 OAuth Fix Patch

Fixes the WebFetch OAuth 401 error in Claude Code v2.0.22.

The Problem

Version 2.0.22 removed the anthropic-beta header required for OAuth authentication, causing WebFetch to fail with:

401 API Error: "OAuth authentication is currently not supported."

The Fix

This script patches your installed Claude Code v2.0.22 to add back the missing header.

Usage

Apply the Patch

# Download the script
curl -O https://gist.githubusercontent.com/[YOUR-USERNAME]/[GIST-ID]/raw/patch-claude-code.sh
chmod +x patch-claude-code.sh

# Apply the patch
./patch-claude-code.sh patch

Check Status

./patch-claude-code.sh status

Remove Patch

./patch-claude-code.sh unpatch

What It Does

The script:

  1. Finds your Claude Code installation automatically
  2. Creates a backup of the original cli.js
  3. Adds the missing header: anthropic-beta: oauth-2025-04-20,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
  4. Verifies the patch worked

This is the same header that v2.0.21 includes, which is why v2.0.21 works.

Safety

  • ✅ Creates automatic backup before modifying anything
  • ✅ Can be safely reverted with unpatch command
  • ✅ Verifies patch applied correctly
  • ✅ Minimal change - only adds one header

Alternative: Use v2.0.21

If you prefer not to patch, downgrade to v2.0.21:

npx @anthropic-ai/claude-code@2.0.21

Technical Details

See GitHub Issue #9887 for root cause analysis and HTTP traffic evidence.

Notes

  • This is a temporary fix until Anthropic releases v2.0.23 with the proper fix
  • The script requires write access to your Claude Code installation (may need sudo)
  • Tested on macOS with Homebrew installation
  • Should work on Linux with npm global installations

Troubleshooting

"Could not find Claude Code installation"

Specify the location manually:

CLI_JS=/path/to/cli.js ./patch-claude-code.sh patch

Find your installation:

# macOS Homebrew
ls /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js

# Linux
ls /usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js

# Find via npm
npm root -g

"Permission denied"

Run with sudo:

sudo ./patch-claude-code.sh patch
#!/usr/bin/env bash
#
# Claude Code v2.0.22 OAuth Fix Patcher
#
# This script patches Claude Code v2.0.22 to fix the WebFetch OAuth 401 error
# by adding the missing anthropic-beta header.
#
# Root cause: v2.0.22 removed the anthropic-beta header that v2.0.21 includes,
# which is required for OAuth authentication to work.
#
# Usage:
# ./patch-claude-code.sh patch # Apply the patch
# ./patch-claude-code.sh unpatch # Remove the patch
# ./patch-claude-code.sh status # Check patch status
#
set -e
# Detect Claude Code location
if command -v claude &>/dev/null; then
CLAUDE_CLI=$(dirname "$(readlink -f "$(which claude)" 2>/dev/null || which claude)")
CLI_JS="$CLAUDE_CLI/cli.js"
elif [ -f "/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js" ]; then
CLI_JS="/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js"
elif [ -f "/usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js" ]; then
CLI_JS="/usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js"
elif [ -f "$HOME/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js" ]; then
CLI_JS="$HOME/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js"
else
echo "❌ Error: Could not find Claude Code installation"
echo "Please specify the path manually:"
echo " CLI_JS=/path/to/cli.js $0 patch"
exit 1
fi
BACKUP="$CLI_JS.oauth-fix-backup"
MISSING_HEADER="oauth-2025-04-20,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14"
check_status() {
if [ -f "$BACKUP" ]; then
echo "✅ Patch is APPLIED"
echo " Original backed up to: $BACKUP"
return 0
else
if grep -q '"anthropic-beta":"'"$MISSING_HEADER"'"' "$CLI_JS" 2>/dev/null; then
echo "✅ Patch appears to be APPLIED (but no backup found)"
return 0
else
echo "❌ Patch is NOT applied"
return 1
fi
fi
}
apply_patch() {
echo "🔧 Patching Claude Code v2.0.22..."
echo " Location: $CLI_JS"
if [ -f "$BACKUP" ]; then
echo "⚠️ Patch already applied (backup exists)"
echo " Run '$0 unpatch' first to revert"
exit 1
fi
# Create backup
echo "📦 Creating backup..."
cp "$CLI_JS" "$BACKUP"
# Apply patch: add anthropic-beta header alongside anthropic-version
echo "🔨 Applying patch..."
sed -i.tmp 's/"anthropic-version":"2023-06-01"/"anthropic-version":"2023-06-01","anthropic-beta":"'"$MISSING_HEADER"'"/g' "$CLI_JS"
rm "$CLI_JS.tmp" 2>/dev/null || true
# Verify patch was applied
if grep -q '"anthropic-beta":"'"$MISSING_HEADER"'"' "$CLI_JS"; then
echo "✅ Patch applied successfully!"
echo ""
echo "The missing anthropic-beta header has been added."
echo "WebFetch should now work correctly."
else
echo "❌ Patch may have failed to apply"
echo "Restoring backup..."
mv "$BACKUP" "$CLI_JS"
exit 1
fi
}
remove_patch() {
echo "🔄 Removing patch..."
if [ ! -f "$BACKUP" ]; then
echo "⚠️ No backup found at: $BACKUP"
echo "Cannot safely unpatch without backup"
exit 1
fi
echo "📦 Restoring from backup..."
mv "$BACKUP" "$CLI_JS"
echo "✅ Patch removed successfully!"
echo "Claude Code restored to original state"
}
case "${1:-status}" in
patch)
apply_patch
;;
unpatch|restore)
remove_patch
;;
status)
check_status
;;
*)
echo "Usage: $0 {patch|unpatch|status}"
echo ""
echo "Commands:"
echo " patch - Apply the OAuth fix patch"
echo " unpatch - Remove the patch and restore original"
echo " status - Check if patch is applied"
echo ""
echo "Current Claude Code location: $CLI_JS"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment