Skip to content

fix: auto-detect TUN and add direct route for proxy#29

Open
nmhjklnm wants to merge 1 commit intomasterfrom
fix/tun-auto-route-v2
Open

fix: auto-detect TUN and add direct route for proxy#29
nmhjklnm wants to merge 1 commit intomasterfrom
fix/tun-auto-route-v2

Conversation

@nmhjklnm
Copy link
Copy Markdown
Owner

Reimplementation of #24 on current master (original had unresolvable conflicts).

What it does

When a proxy is configured and TUN is active (Clash/sing-box/etc), the proxy connection gets hijacked by the TUN tunnel, creating a routing loop. This PR auto-detects TUN and adds a direct host route for the proxy IP.

Changes

Wrapper — on every claude launch:

  • Detect TUN interfaces (utun count on macOS, tun0 on Linux)
  • Check if proxy IP routes through physical gateway
  • Auto-add /32 host route if missing (one sudo prompt)

Checkcac env check:

  • Replace old relay connectivity test with direct route check
  • Auto-fix missing route (simpler, no curl needed)

Relay — internal functions:

  • New _relay_route_ok / _relay_ensure_route helpers
  • _relay_add_route now deletes existing route before adding (handles TUN-created entries)
  • Removed legacy cmd_relay user command (relay is fully automatic)

relay.js — debug logging for CONNECT, errors, 502

Replaces #24

Reimplementation of #24 on current master.

Wrapper (templates.sh):
- Detect TUN on every claude launch (utun count on macOS, tun0 on Linux)
- Check if proxy IP has direct route via physical gateway
- Auto-add /32 host route if missing (delete-then-add for TUN entries)

Check (cmd_check.sh):
- Replace relay connectivity test with route check
- Auto-fix missing route on check (may need sudo)

Relay (cmd_relay.sh):
- Add _relay_route_ok / _relay_ensure_route helpers
- Improve _relay_add_route: delete existing route before adding
- Remove legacy cmd_relay user command (relay is now fully automatic)

relay.js:
- Add debug logging for CONNECT, errors, and 502 responses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant