claudeers.
// Other

agentrouter-autoretry-claudecode

Autoretry local proxy for agentrouter via claudcode

// Other[ cli ][ api ][ claude ]#claude#otherMIT$open-sourceupdated about 2 hours ago

Install with your AI

Paste into Claude Code, Cursor, or any agent — it reads the repo and wires the tool into your project.

Install and set up agentrouter-autoretry-claudecode (git-clone project) into my current project.
Found on https://claudeers.com/agentrouter-autoretry-claudecode
Repo: https://github.com/brainstormersia-cmd/agentrouter-autoretry-claudecode
Homepage/docs: —
Detected install method: git-clone → git clone https://github.com/brainstormersia-cmd/agentrouter-autoretry-claudecode
Category: other. Platforms: cli, api.
Read the repo's README for exact setup and env vars, then install it and wire it into my project.

Claudeers Health Verdict:
unknown; community-verified: false. Confirm the source before running anything.
// or clone
git clone https://github.com/brainstormersia-cmd/agentrouter-autoretry-claudecode

// compatibility

Platformscli, api
Operating systems
AI compatibilityclaude
LicenseMIT
Pricingopen-source
LanguagePython

ClaudeShield

ClaudeShield

A local reliability proxy that keeps Claude Code alive through gateway outages.

MIT License · Quickstart · How It Works · Configuration


The Problem

Claude Code auto-retries 429 and 5xx errors, but stops dead on 403 and 400. Most third-party gateways (AgentRouter, Lumosel, Aerolink) return 403 for quota limits instead of the standard 429. Some return errors in Chinese (用户额度不足). Some return 200 with an error hidden inside the SSE stream body.

Result: your coding session crashes. You restart manually. You lose context.

The Solution

ClaudeShield is a local Python proxy that sits between Claude Code and your gateway. It:

  • Converts non-retryable 403/400/504 errors into 429 + Retry-After
  • Peeks at the first 8KB of SSE streams to detect errors hidden in 200 responses
  • Filters data: null SSE events that break Anthropic parsers
  • Injects the claude-cli/1.0.0 User-Agent header that AgentRouter requires
  • Detects Chinese error messages (用户额度不足, 无权访问模型)
  • Uses a circuit breaker to prevent infinite retry loops on permanent errors
  • Forwards all auth headers from Claude Code without storing them
Claude Code  -->  ClaudeShield (localhost:8787)  -->  AgentRouter
                       |
                       +-- 403 quota?   --> 429 + Retry-After (client retries)
                       +-- 504 timeout?  --> 429 + Retry-After (client retries)
                       +-- 200 + error in SSE? --> 503 (client retries)
                       +-- 403 no model? --> pass through (circuit breaker, fail fast)
                       +-- 200 OK?       --> stream passthrough (zero overhead)

Quickstart

1. Download

curl -O https://raw.githubusercontent.com/brainstormersia-cmd/agentrouter-autoretry-claudecode/main/retry-proxy.py

2. Run interactive setup

python retry-proxy.py

Answer 3 questions: gateway, API key, model. It auto-configures ~/.claude/settings.json.

3. Launch Claude Code

claude --dangerously-skip-permissions

Done. Claude Code now survives gateway outages automatically.

How It Works

Error Classification

Gateway returnsBody containsClaudeShield actionClaude Code sees
403用户额度不足 (quota)Convert to 429 + Retry-After: 20sAuto-retry
403无权访问模型 (no model access)Pass through (circuit breaker)Fail fast
400rate_limit, quota, exhaustedConvert to 429 + Retry-After: 20sAuto-retry
504Gateway timeoutConvert to 429 + Retry-After: 20sAuto-retry
429Rate limitPass through + Retry-After: 15sAuto-retry
500-530Server errorPass through + Retry-After: 15sAuto-retry
200Empty bodyConvert to 503 + Retry-After: 10sAuto-retry
200Non-JSON (HTML error page)Convert to 503 + Retry-After: 10sAuto-retry
200SSE with type:error insideConvert to 503 + Retry-After: 10sAuto-retry
200 + valid SSEmessage_start presentStream passthroughNormal response
401Invalid keyPass throughFail fast
404Model not foundPass throughFail fast
Network errorConnection resetConvert to 503 + Retry-After: 10sAuto-retry

Circuit Breaker

The proxy distinguishes retryable errors from permanent ones:

  • Retryable: quota, rate limit, capacity, timeout, server error, network drop
  • Permanent: model not accessible, invalid auth, non-existent endpoint

Permanent errors pass through without conversion. This prevents the infinite retry loop that freezes Claude Code at 95% context compaction when the "small fast model" is not available on the gateway.

SSE Stream Inspection

Claude Code uses streaming (Server-Sent Events). AgentRouter sometimes returns HTTP 200 with an error payload inside the SSE stream body instead of message_start. ClaudeShield reads the first 8KB of every stream and checks for error markers before forwarding. If an error is detected, it converts the response to 503 so Claude Code retries.

Stats Endpoint

The proxy exposes telemetry for monitoring:

curl http://127.0.0.1:8787/stats
{
  "version": "3.1.0",
  "uptime_seconds": 45.9,
  "requests": 127,
  "converted": 14,
  "passed": 110,
  "errors": 3,
  "retry_rate": 0.1102
}

Configuration

settings.json

The interactive setup writes this to ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:8787",
    "ANTHROPIC_API_KEY": "your-gateway-key",
    "CLAUDE_CODE_RETRY_WATCHDOG": "1",
    "CLAUDE_CODE_MAX_RETRIES": "300"
  }
}

CLI

python retry-proxy.py                              # Interactive setup
python retry-proxy.py --start                     # Start with defaults
python retry-proxy.py --start --upstream https://api.lumosel.vip  # Different gateway
python retry-proxy.py --start --port 9090          # Custom port
python retry-proxy.py --version                    # Show version

Supported Gateways

GatewayURLNotes
AgentRouterhttps://agentrouter.orgPrimary target. Injects required User-Agent.
Lumoselhttps://api.lumosel.vipWorks out of the box.
Aerolinkhttps://capi.aerolink.latWorks out of the box.
Anyhttps://your-gateway.comAny Anthropic-compatible gateway.

Requirements

  • Python 3.8+ (standard library only, no pip install)
  • Claude Code v2.1.186+ (for CLAUDE_CODE_RETRY_WATCHDOG)

Files

FileDescription
retry-proxy.pyThe proxy (single file, zero dependencies)
start-proxy.batWindows auto-start script
start-proxy.shmacOS/Linux auto-start script
claude-proxy.servicesystemd service file
assets/logo.pngLogo
assets/feature-403-429.png403-to-429 conversion diagram

Privacy

  • No API keys stored. The proxy forwards what Claude Code sends.
  • No external dependencies. Pure Python standard library.
  • Local only. Listens on 127.0.0.1, never exposes ports externally.
  • No telemetry. Zero network calls except forwarding to your configured gateway.

License

MIT

// faq

What is agentrouter-autoretry-claudecode?

Autoretry local proxy for agentrouter via claudcode. It is open-source on GitHub.

Is agentrouter-autoretry-claudecode free to use?

agentrouter-autoretry-claudecode is open-source under the MIT license, so it is free to use.

What category does agentrouter-autoretry-claudecode belong to?

agentrouter-autoretry-claudecode is listed under other in the Claudeers registry of Claude-compatible tools.

0 views
10 stars
unclaimed
updated about 2 hours ago

// embed badge

agentrouter-autoretry-claudecode on Claudeers
[![Claudeers](https://claudeers.com/api/badge/agentrouter-autoretry-claudecode.svg)](https://claudeers.com/agentrouter-autoretry-claudecode)

// retro hit counter

agentrouter-autoretry-claudecode hit counter
[![Hits](https://claudeers.com/api/counter/agentrouter-autoretry-claudecode.svg)](https://claudeers.com/agentrouter-autoretry-claudecode)

// reviews

// guestbook

0/500

// related in Other

🔓

符合nature论文学术表达和科研绘图的Skill

// otherYuan1z0825/Python36,535Apache-2.0[ claude ]
🔓

Open source Ghostty-based macOS terminal with vertical tabs and notifications for AI coding agents. Built for multitasking, organization, and programmability.

// othermanaflow-ai/Swift26,069NOASSERTION[ claude ]
🔓

Anti-AI-slop design skill for Claude Code, Cursor, and Codex.

// otherNutlope/CSS25,307MIT[ claude ]
🔓

Huashu Design · HTML-native design skill for Claude Code · Claude Code 里 HTML 原生的设计 skill · 高保真原型 / 幻灯片 / 动画 + 20 设计哲学 + 5 维评审 + MP4 导出 · Agent-agnostic

// otheralchaincyf/HTML23,151MIT[ claude ]
→ see how agentrouter-autoretry-claudecode connects across the ecosystem