Skip to content

Commit de5fea0

Browse files
committed
feat: client mode with Claude Desktop support via mitmproxy
Add a "client mode" so users can connect Claude Code (and optionally Claude Desktop) to a remote CC-Router instance without hosting accounts locally. The setup wizard now asks up-front whether to host or connect. Claude Desktop does not honor ANTHROPIC_BASE_URL, so its traffic is redirected via mitmproxy in local mode — a process-scoped interceptor that rewrites api.anthropic.com requests to the proxy. The server auth middleware now accepts x-api-key as an alternative to Bearer, matching what the Anthropic SDK (embedded in Claude Desktop) sends. - New `cc-router client {connect,disconnect,status,start-desktop,stop-desktop}` commands - New interceptor module: mitmproxy manager + redirect addon - Config schema: ProxyConfig.client with remoteUrl/remoteSecret/desktopEnabled - Setup wizard: "Host vs Connect" first step, Desktop opt-in at the end - README: Client mode + Claude Desktop support sections - server.ts: auth middleware accepts x-api-key (backward-compatible)
1 parent f5d0304 commit de5fea0

11 files changed

Lines changed: 891 additions & 19 deletions

File tree

README.md

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ Distribute Claude Code requests across N subscriptions to multiply your throughp
1717
## How it works
1818

1919
```
20-
Claude Code (terminal)
21-
22-
│ ANTHROPIC_BASE_URL=http://localhost:3456
23-
│ ANTHROPIC_AUTH_TOKEN=proxy-managed
24-
20+
Claude Code (terminal) ─┐
21+
│ ANTHROPIC_BASE_URL=http://localhost:3456
22+
23+
Claude Desktop ─[mitmproxy]─┐ (optional — intercepts api.anthropic.com)
24+
25+
2526
┌─────────────────────────────────────┐
2627
│ CC-Router :3456 │
2728
│ │
@@ -41,6 +42,8 @@ Claude Code (terminal)
4142

4243
All standard Claude Code features work transparently: streaming, extended thinking, tool use, prompt caching.
4344

45+
**Claude Desktop support** is opt-in and requires a small interceptor (mitmproxy) because Claude Desktop doesn't expose a custom API endpoint setting. See [Claude Desktop support](#claude-desktop-support).
46+
4447
---
4548

4649
## Use cases
@@ -280,6 +283,13 @@ cc-router configure (Re)write ~/.claude/settings.json
280283
cc-router configure --show Show current Claude Code proxy settings
281284
cc-router configure --remove Remove cc-router settings (same as revert without stopping)
282285
286+
cc-router client connect <url> Connect Claude Code to a remote CC-Router
287+
cc-router client connect --desktop Also configure Claude Desktop interception
288+
cc-router client disconnect Revert all client configuration
289+
cc-router client status Show connection + remote server health
290+
cc-router client start-desktop Start mitmproxy interceptor for Claude Desktop
291+
cc-router client stop-desktop Stop mitmproxy interceptor
292+
283293
cc-router docker up Start full Docker stack (cc-router + LiteLLM)
284294
cc-router docker up --build Rebuild cc-router image before starting
285295
cc-router docker down Stop Docker containers
@@ -321,6 +331,129 @@ See [docs/litellm-setup.md](docs/litellm-setup.md) for details.
321331

322332
---
323333

334+
## Client mode — connecting to an existing CC-Router
335+
336+
If someone on your team already hosts a CC-Router instance (on a VPS, home server, or another machine on the LAN), you don't need to install accounts locally. You just point your Claude Code at the remote proxy.
337+
338+
The setup wizard asks about this at the very first step:
339+
340+
```bash
341+
cc-router setup
342+
# → What do you want to do?
343+
# • Host CC-Router on this machine
344+
# • Connect to an existing CC-Router server ← pick this
345+
```
346+
347+
Or use the dedicated command directly:
348+
349+
```bash
350+
# Quick connect — just point Claude Code at the remote proxy
351+
cc-router client connect http://192.168.1.50:3456 --secret cc-rtr-abc123...
352+
353+
# Check status
354+
cc-router client status
355+
356+
# Disconnect (restores Claude Code defaults)
357+
cc-router client disconnect
358+
```
359+
360+
Client mode writes `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` into `~/.claude/settings.json`, so Claude Code talks directly to the remote proxy. Nothing runs locally — no accounts, no proxy process, no resources.
361+
362+
### CLI reference
363+
364+
```text
365+
cc-router client connect <url> Connect Claude Code to a CC-Router server
366+
cc-router client connect --desktop Also configure Claude Desktop interception
367+
cc-router client connect -s <secret> Pass the proxy secret inline (or use --secret)
368+
cc-router client disconnect Revert all client configuration
369+
cc-router client status Show current connection + remote server health
370+
cc-router client start-desktop Start the Claude Desktop mitmproxy interceptor
371+
cc-router client stop-desktop Stop the Claude Desktop interceptor
372+
```
373+
374+
---
375+
376+
## Claude Desktop support
377+
378+
Claude Desktop (chat + Cowork) **can be routed through CC-Router**, but unlike Claude Code it does not respect `ANTHROPIC_BASE_URL`. It talks directly to `api.anthropic.com` via an embedded Anthropic SDK. To redirect its traffic, CC-Router uses [mitmproxy](https://mitmproxy.org/) in *local redirect mode* — a process-scoped interceptor that only captures Claude Desktop's network traffic and forwards it to the proxy.
379+
380+
This is **opt-in** — the setup wizard will ask if you want it.
381+
382+
### Requirements
383+
384+
- **mitmproxy ≥ 10.1.5** (macOS, Windows) or **≥ 11.1** (Linux — requires kernel ≥ 6.8)
385+
- Admin access to install the mitmproxy CA certificate
386+
- On macOS: manual approval of mitmproxy's Network Extension (one time, via System Settings)
387+
388+
### Installing mitmproxy
389+
390+
```bash
391+
# macOS
392+
brew install mitmproxy
393+
394+
# Windows
395+
# Download the installer from https://mitmproxy.org/downloads/
396+
# (or: pip install mitmproxy)
397+
398+
# Linux
399+
pip install mitmproxy # kernel 6.8+ required for local mode
400+
```
401+
402+
### Enabling Desktop interception
403+
404+
During `cc-router setup` or `cc-router client connect`, answer **Yes** when asked about Claude Desktop. The wizard will:
405+
406+
1. Check that mitmproxy is installed
407+
2. Generate the mitmproxy CA certificate (if not already present)
408+
3. Install the CA into the OS trust store (requires sudo/admin)
409+
4. Write the redirect addon to `~/.cc-router/interceptor/addon.py`
410+
5. On macOS, prompt you to approve the Network Extension
411+
412+
Then start the interceptor:
413+
414+
```bash
415+
cc-router client start-desktop
416+
```
417+
418+
Open Claude Desktop and send a message. The request will be intercepted, redirected to CC-Router, and round-robinned across your accounts just like Claude Code traffic.
419+
420+
### Stopping / removing Desktop interception
421+
422+
```bash
423+
cc-router client stop-desktop # Stop the interceptor (keep configuration)
424+
cc-router client disconnect # Stop + remove all client config
425+
```
426+
427+
### How it works under the hood
428+
429+
```
430+
Claude Desktop
431+
432+
│ tries to connect to api.anthropic.com:443
433+
434+
mitmproxy (local mode)
435+
│ addon.py rewrites scheme/host to CC-Router
436+
437+
CC-Router :3456 ──► api.anthropic.com (with OAuth Bearer token)
438+
```
439+
440+
mitmproxy's local mode is *process-scoped* — it only intercepts traffic from the Claude process, not your browser, curl, or any other app. The OS-level interception uses:
441+
442+
| Platform | Mechanism |
443+
|----------|-----------|
444+
| macOS | Network Extension (App Proxy Provider API) |
445+
| Windows | WinDivert (WFP kernel driver) |
446+
| Linux | eBPF (kernel ≥ 6.8) |
447+
448+
### Troubleshooting
449+
450+
- **macOS: "provider rejected new flow"** — re-enable Mitmproxy Redirector in System Settings → General → Login Items & Extensions → Network Extensions, then restart mitmproxy.
451+
- **Windows: UAC prompt every start** — expected; mitmproxy's redirector needs admin at runtime.
452+
- **Linux: "eBPF program failed to load"** — check your kernel version with `uname -r`. You need ≥ 6.8.
453+
- **Chat shows "failed to connect"** — make sure CC-Router is reachable from the mitmproxy process. Run `curl http://localhost:3456/cc-router/health` to verify the proxy is up.
454+
455+
---
456+
324457
## Reverting to normal Claude Code
325458

326459
To stop using cc-router and go back to normal Claude Code authentication:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ai-cc-router",
3-
"version": "0.1.12",
3+
"version": "0.2.0",
44
"description": "Round-robin proxy for Claude Max OAuth tokens — use multiple Claude Max accounts with Claude Code",
55
"type": "module",
66
"bin": {
@@ -34,6 +34,7 @@
3434
"homepage": "https://github.com/VictorMinemu/CC-Router#readme",
3535
"files": [
3636
"dist/",
37+
"src/interceptor/addon.py",
3738
"litellm-config.yaml",
3839
"docker-compose.yml",
3940
"Dockerfile",

0 commit comments

Comments
 (0)