refatbd / laravel-claude-mirror
High-performance Claude.ai Web UI reverse proxy and Anthropic/OpenAI-compatible /v1 API gateway for Laravel with encrypted sessionKey pooling, HTTP/2 streaming, Artifacts origin rewriting, and SaaS integration hooks.
Requires
- php: ^8.2|^8.3|^8.4|^8.5
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- guzzlehttp/guzzle: ^7.8|^8.0
- illuminate/console: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.5|^11.0|^12.0
Suggests
- ext-curl: Required for native Pure-PHP HTTP/2 ALPN streaming in GuzzleTransport
- ext-redis: Recommended in Webuzo PHP Extensions for high-concurrency Redis caching and distributed token locks
- predis/predis: Pure-PHP Redis client (^2.2|^3.0) when phpredis extension is not enabled
Provides
None
Conflicts
None
Replaces
None
README
A production-ready Laravel Composer package providing a Claude.ai Web UI Reverse Proxy, Dual Anthropic (/v1/messages) & OpenAI-Compatible (/v1/chat/completions) API Gateway, Artifacts (claudeusercontent.com) Multi-Origin Rewriter, Multi-Account Encrypted sessionKey Pooling, SaaS Auth & Telemetry Hooks, and a 5-Menu Light-Mode Control Suite — built for universal web servers (Apache/Webuzo, Nginx, LiteSpeed/OpenLiteSpeed, Caddy, FrankenPHP, Laravel Octane) and dynamic Redis (auto | enabled | disabled) with native Pure PHP curl_multi HTTP/2 streaming plus an optional Chrome TLS sidecar.
Developed by Mostafizur Rahman Refat.
Navigation & Built-in Interfaces
| Interface | Default URL | Description |
|---|---|---|
| Claude Web Proxy (Optional) | / |
Full-fidelity claude.ai reverse proxy (/, /new, /chat/{id}, /project/{id}, /artifacts, /recents, /settings, /_next/*, /api/*, /edge-api/*) with zero floating overlays. Disable via CLAUDE_MIRROR_WEB_PROXY_ENABLED=false for API-only SaaS apps. |
| Settings & Admin Dashboard | /claude-mirror/admin |
Clean Light-Mode Control Panel. Upload or paste calude.txt, Cookie-Editor JSON, Netscape cookies, or DevTools cURL; edit per-account User-Agent (with 1-click browser UA matching), cf_clearance, and proxy overrides inline; configure Redis, Web Server, CORS, Pool, and Rate Limiting live in DB. |
| Interactive Playground | /claude-mirror/playground |
Protected browser UI (AuthorizeAdmin) to test both POST /v1/messages (Anthropic) and POST /v1/chat/completions (OpenAI-compatible adapter) live with SSE streaming, attachment uploads, and conversation continuation. |
| Swagger UI API Docs | /claude-mirror/api-docs |
Local offline OpenAPI 3.1.0 documentation rendered from /claude-mirror/openapi (?format=json or ?format=yaml). |
| Help & About Reference | /claude-mirror/help |
Searchable 13-section interactive reference with sticky TOC (IntersectionObserver), beginner Cookie-Editor walkthrough, HTTP/2 vs Sidecar guide, dynamic .env map, SaaS hooks, server recipes, and troubleshooting. |
Dual /v1 API Gateway |
/v1/* |
Drop-in /v1/models, /v1/messages (Anthropic native), /v1/chat/completions (OpenAI-compatible JSON adapter backed strictly by your connected Claude accounts), and /v1/capabilities. |
| Control & Diagnostics APIs | /claude-mirror/api/*, /claude-mirror/health, /claude-mirror/diagnostics |
Conversation listing/search/export/delete, binary uploads (/claude-mirror/api/files), runtime settings API, and liveness/diagnostics JSON. |
Key Capabilities
- Dual
/v1API Compatibility (Anthropic+OpenAIAdapter): Works natively with Anthropic SDKs (/v1/messages,x-api-key) and OpenAI SDKs/tools like Cursor, Continue, n8n, or Open WebUI (/v1/chat/completions,Authorization: Bearer ...). Every request is fulfilled exclusively by your pooledclaude.aiaccounts and Claude models. - Zero-Python Pure PHP HTTP/2 Streaming (
guzzleDriver):GuzzleTransportstreams SSE via native PHPcurl_multiwithCURL_HTTP_VERSION_2TLSso streaming completion calls keep HTTP/2 ALPN TLS instead of falling back to HTTP/1.1StreamHandler, captures Cloudflare edge continuity cookies (__cf_bm,_cfuvid,__cfruid), and automatically self-heals expiredcf_clearancecookies once if direct retry succeeds. - Optional Chrome TLS Sidecar (
sidecarDriver): Switch cleanly tosidecar/claude_tls_relay.py(curl_cffi) in.envor/claude-mirror/adminwhen deploying behind strict datacenter IPs that reject PHPext-curlTLS fingerprints. - Smart Token Extraction & Per-Account Editing: Drag/drop or
Ctrl+Vpastecalude.txt/ Cookie JSON (with UTF-8 BOM support),cURL, Netscape cookies, or rawsk-ant-sid...tokens, or click Edit next to any stored account to manageUser-Agent,cf_clearance, and per-account proxies without re-enteringsessionKey. - Fail-Closed Production Security:
/claude-mirror/admin,/claude-mirror/playground,/claude-mirror/diagnostics, andclaude_mirror_controlcookies fail closed whenAPP_ENV=productionunlessCLAUDE_MIRROR_ADMIN_KEYorClaudeMirror::authorizeAdminUsing()authorizes access;/v1/*and/claude-mirror/api/*fail closed with401in production unlessCLAUDE_MIRROR_API_KEYorClaudeMirror::authenticateApiKeyUsing()is configured. - Dual-Mode Artifacts Origin Rewriting: Supports
subpath(/__claude_usercontent/*,/__claude_frame/{frameId}/*) for localhost and single-domain setups, andsubdomain(CLAUDE_MIRROR_USERCONTENT_DOMAIN,CLAUDE_MIRROR_FRAME_DOMAIN) for cross-origin production isolation.
Installation
Install the package via Composer:
composer require refatbd/laravel-claude-mirror
Run the installer to publish configuration, run migrations, generate CLAUDE_MIRROR_API_KEY in .env, and optionally write server rules:
php artisan claude-mirror:install
# Or target Apache / Webuzo directly:
php artisan claude-mirror:install --server=webuzo
Optional publish tags:
php artisan vendor:publish --tag=claude-mirror-config php artisan vendor:publish --tag=claude-mirror-migrations php artisan vendor:publish --tag=claude-mirror-deploy
Building a SaaS with This Package
laravel-claude-mirror mirrors the static hook ergonomics of Refatbd\LaravelChatGptMirror\Mirror so it drops cleanly into multi-tenant Laravel SaaS applications without hijacking your landing page or customer auth routes.
1. Keep Your Host SaaS Routes Isolated (.env)
CLAUDE_MIRROR_WEB_PROXY_ENABLED=false CLAUDE_MIRROR_ROOT_ALIASES=false CLAUDE_MIRROR_API_KEY=sk-claude-mirror-your-secret-key CLAUDE_MIRROR_ADMIN_KEY=your-strong-admin-secret CLAUDE_MIRROR_ALLOWED_HOSTS=api.yoursaas.com # Optional custom mount prefixes or subdomain # CLAUDE_MIRROR_DOMAIN=claude.yoursaas.com CLAUDE_MIRROR_OPENAI_PREFIX=v1 CLAUDE_MIRROR_ADMIN_PREFIX=internal/claude-admin CLAUDE_MIRROR_PLAYGROUND_PREFIX=internal/claude-playground CLAUDE_MIRROR_HELP_PREFIX=internal/claude-help
2. Per-Customer SaaS Hooks (AppServiceProvider::boot())
use Illuminate\Http\Request; use Refatbd\LaravelClaudeMirror\Facades\ClaudeMirror; public function boot(): void { // 1. Authenticate per-tenant API keys on /v1/* and /claude-mirror/api/* ClaudeMirror::authenticateApiKeyUsing(function (string $token, Request $request) { $record = \App\Models\CustomerApiKey::query() ->where('token_hash', hash('sha256', $token)) ->where('active', true) ->first(); return $record ? ['user_id' => $record->user_id, 'plan' => $record->user->plan] : false; }); // 2. Restrict Admin Dashboard, Playground & Diagnostics to SaaS admins ClaudeMirror::authorizeAdminUsing(fn (Request $request): bool => (bool) $request->user()?->is_admin); // 3. Optional Web UI proxy context & hooks (when hosting shared Claude Web UI) ClaudeMirror::shouldProxyRequestUsing(fn (Request $request): bool => true); ClaudeMirror::resolveWebContextUsing(fn (Request $request): ?array => null); ClaudeMirror::customizeBrowserSessionUsing(fn (array $session, Request $request, $user): array => $session); ClaudeMirror::interceptBackendRequestUsing(fn (Request $request, string $path, array $ctx) => null); ClaudeMirror::observeBackendStreamUsing(function (string $event, array $telemetry, Request $request, string $path, array $ctx): void { // Meter token/message usage }); ClaudeMirror::filterBackendResponseUsing(fn ($response, Request $request, string $path, array $ctx) => $response); ClaudeMirror::injectBrowserHtmlUsing(fn (string $html, Request $request, array $ctx): string => $html); ClaudeMirror::filterBrowserResponseHeadersUsing(fn (array $headers, Request $request, array $ctx): array => $headers); }
You can also disable package routes or migrations in AppServiceProvider::register() using ClaudeMirror::ignoreRoutes() and ClaudeMirror::ignoreMigrations(), or assign middleware arrays (routes.web_middleware, routes.api_middleware, routes.admin_middleware) and aliases (claude-mirror.admin, claude-mirror.runtime, claude-mirror.api_key, claude-mirror.control).
Configuration (.env)
CLAUDE_MIRROR_ENABLED=true CLAUDE_MIRROR_WEB_PROXY_ENABLED=true CLAUDE_MIRROR_API_PROXY_ENABLED=true CLAUDE_MIRROR_OPENAI_API_ENABLED=true CLAUDE_MIRROR_NATIVE_API_ENABLED=true CLAUDE_MIRROR_ADMIN_ENABLED=true CLAUDE_MIRROR_PLAYGROUND_ENABLED=true CLAUDE_MIRROR_HELP_ENABLED=true CLAUDE_MIRROR_DOCS_ENABLED=true CLAUDE_MIRROR_HEALTH_ENABLED=true CLAUDE_MIRROR_ROOT_ALIASES=false # Auth & Hosts CLAUDE_MIRROR_API_KEY=sk-claude-mirror-your-secret-key CLAUDE_MIRROR_ADMIN_KEY=your-strong-admin-key CLAUDE_MIRROR_ALLOWED_HOSTS=claude.example.com # Transport & Proxy (guzzle uses native HTTP/2 curl_multi streaming) CLAUDE_MIRROR_TRANSPORT=guzzle CLAUDE_MIRROR_SIDECAR_URL=http://127.0.0.1:8789 CLAUDE_MIRROR_HTTP_PROXY= CLAUDE_MIRROR_VERIFY_SSL=true # Artifacts Mode (subpath | subdomain) CLAUDE_MIRROR_ARTIFACTS_MODE=subpath CLAUDE_MIRROR_USERCONTENT_DOMAIN= CLAUDE_MIRROR_FRAME_DOMAIN= # Pool & Timeouts CLAUDE_MIRROR_POOL_STRATEGY=least_busy CLAUDE_MIRROR_MAX_CONCURRENT_PER_TOKEN=5 CLAUDE_MIRROR_COOLDOWN_SECONDS=60 CLAUDE_MIRROR_REQUEST_TIMEOUT=120 CLAUDE_MIRROR_READ_TIMEOUT=180 # Universal Server, CORS & Rate Limiting (Live-editable in /claude-mirror/admin) CLAUDE_MIRROR_SERVER_PLATFORM=auto CLAUDE_MIRROR_TRUST_PROXIES=true CLAUDE_MIRROR_TRUSTED_PROXIES=* CLAUDE_MIRROR_FORCE_HTTPS= CLAUDE_MIRROR_STREAM_MAX_EXECUTION_TIME=300 CLAUDE_MIRROR_DISABLE_OUTPUT_COMPRESSION=true CLAUDE_MIRROR_CORS_ENABLED=true CLAUDE_MIRROR_CORS_ALLOWED_ORIGINS=* CLAUDE_MIRROR_RATE_LIMIT_ENABLED=false CLAUDE_MIRROR_RATE_LIMIT_MAX_ATTEMPTS=180 CLAUDE_MIRROR_RATE_LIMIT_DECAY_SECONDS=60 # Optional Dynamic Redis (auto | enabled | disabled) CLAUDE_MIRROR_REDIS_ENABLED=auto CLAUDE_MIRROR_REDIS_CLIENT=auto CLAUDE_MIRROR_REDIS_HOST=127.0.0.1 CLAUDE_MIRROR_REDIS_PORT=6379 CLAUDE_MIRROR_REDIS_PASSWORD= CLAUDE_MIRROR_REDIS_DB=0
Universal Production Deployment & Artisan CLI
# Write .htaccess rules (Authorization header forwarding + unbuffered SSE) for Webuzo/Apache/LiteSpeed php artisan claude-mirror:server webuzo --write --vhost --domain=claude.example.com --root=/home/user/public_html/public # Print Nginx, Caddy/FrankenPHP, or Octane configuration php artisan claude-mirror:server nginx --vhost --domain=claude.example.com --root=/var/www/app/public php artisan claude-mirror:server caddy --vhost --domain=claude.example.com --root=/var/www/app/public # Account & Health CLI php artisan claude-mirror:token-add "sk-ant-sid01-..." --name="Primary Claude" php artisan claude-mirror:token-list php artisan claude-mirror:tokens:probe php artisan claude-mirror:health
Optional curl_cffi TLS Sidecar
If your cloud VPS IP receives strict TLS fingerprint challenges (403) on direct PHP requests and you do not use a residential/WARP proxy:
python -m venv .venv .venv/bin/pip install -r sidecar/requirements.txt python sidecar/claude_tls_relay.py
Set CLAUDE_MIRROR_TRANSPORT=sidecar in .env or switch drivers live from /claude-mirror/admin.
Testing & Quality
composer validate --strict composer test # or vendor/bin/phpunit --testdox
Changelog & License
Please see CHANGELOG for recent changes and License File for MIT licensing details.