# Native Binary Interception — ⛔ DISPROVEN (DO NOT USE)

## Verdict: This approach does NOT work

The hosts-based proxy interception strategy was tested extensively and failed:

1. **The binary connects to BOTH `api.anthropic.com` AND `console.anthropic.com`** — OAuth authentication requires `console.anthropic.com` BEFORE any API call reaches `api.anthropic.com`
2. **Redirecting `api.anthropic.com` breaks OAuth** — the OAuth flow silently fails (exit code 0 or timeout, no proxy requests received)
3. **Proxying `console.anthropic.com` is impractical** — the OAuth flow involves browser redirects, token exchange, and session cookies that can't be intercepted by a simple API proxy
4. **Self-signed TLS certificates on system level** — even with `SSL_CERT_FILE` and `NODE_TLS_REJECT_UNAUTHORIZED=0`, the nexe binary does not trust custom CA bundles for `console.anthropic.com` connections

## Evidence from testing session (2026-05-24)

```
$ sudo cat /etc/hosts
127.0.0.1 api.anthropic.com

$ claude -p "Say OK"
# Exit code 0, no output, no proxy requests received

$ sudo journalctl -u kiwi-proxy --since "5 seconds ago"
-- No entries --
```

## What actually works

Use **claude-code-router (CCR)** — the `ccr code` wrapper script intercepts env vars at the Node.js level BEFORE spawning the native binary. This is the only reliable method to use Claude Code with non-Anthropic backends.

See `references/claude-code-router.md` for full setup instructions.

## Preserved for reference: The original approach (FAILED)

The idea was: since `api.anthropic.com` is hardcoded in the binary, redirect it via `/etc/hosts` to a local proxy that translates Anthropic Messages API → OpenAI-compatible API.

```bash
echo "127.0.0.1 api.anthropic.com" | sudo tee -a /etc/hosts
```

This fails because the binary's startup sequence is:
1. Check OAuth token validity → calls `console.anthropic.com`
2. Refresh token if needed → calls `console.anthropic.com`
3. Only THEN make API calls → calls `api.anthropic.com`

Step 1 fails silently with the redirect in place, and step 3 never executes.

## Legacy proxy code

The proxy implementation (`templates/kiwi-proxy.py`) still works as a standalone Anthropic→OpenAI translator. It's useful for other purposes (e.g., if you have a client that DOES respect `ANTHROPIC_BASE_URL`), but useless for the Claude Code native binary.
