Claude Code V2RayN Setup Guide for Reliable Terminal Access

Claude Code brings AI-assisted coding to the command line, but connection errors and failed sign-ins can interrupt the workflow. Learn how v2rayN works as the client layer, how to import a profile, and which proxy and routing settings to check first.

Claude Code brings AI-assisted coding into the terminal, where it can inspect a project, explain files, propose changes, and run approved development commands. That workflow depends on more than the Claude Code command itself. The terminal must resolve the service domain, establish HTTPS connections, and inherit proxy variables in the same shell where the CLI is running. If a browser works while Claude Code reports a timeout, failed sign-in, or an unreachable service, the most common cause is that the browser is using v2rayN’s system proxy while the terminal is still making a direct connection.

v2rayN acts as the local client layer between the command-line application and the remote node. It does not replace Claude Code authentication, create an account, or repair an invalid subscription. Its job is to provide a local HTTP or SOCKS listener, apply the selected routing rules, and send matching traffic through the configured VMess or VLESS outbound. The final result depends on four connected parts: a working node, a reachable local port, proxy variables visible to the shell, and routing rules that do not send the required domains directly.

Quick overview

This guide explains how to prepare v2rayN for Claude Code on Windows, test the local HTTP or SOCKS listener, configure PowerShell or another terminal session, and verify authentication without confusing browser access with CLI access. The reference ports are HTTP 10809 and SOCKS 10808; menu names can vary slightly across v2rayN 7.x releases.

Understand the terminal proxy path

A browser often follows the Windows system proxy automatically. A command-line program may not. Claude Code normally runs as a process started by the current shell, so it can only use proxy settings that the program or its underlying runtime recognizes. Selecting a node in v2rayN proves that the core can reach the node, but it does not automatically prove that claude will use the same route.

Claude Code starts Shell reads proxy variables v2rayN accepts local traffic Routing selects outbound HTTPS reaches service

For a typical Windows installation, v2rayN provides a local HTTP proxy at 127.0.0.1:10809 and a SOCKS5 proxy at 127.0.0.1:10808. The exact ports are configurable, so confirm them in the v2rayN main window or in “Settings” → “Parameter Settings” → the local proxy or inbound section before copying commands. A port can be open while the selected node is unavailable, and a node can be healthy while no application is connected to the port.

10809
Common local HTTP proxy port
10808
Common local SOCKS5 port
127.0.0.1
Loopback address for the local client
4 checks
Port, route, shell, and sign-in

Claude Code traffic is generally HTTPS traffic, so an HTTP proxy is usually the simplest first choice. The HTTP proxy receives a CONNECT request and creates a tunnel for TLS traffic; it does not mean that the service is using unencrypted HTTP. A SOCKS5 listener can also work when the client or runtime supports SOCKS proxy variables, but HTTP proxy variables are often easier to validate with command-line tools and are less likely to be ignored by a program that expects conventional HTTP environment settings.

  • v2rayN node: Provides the remote VMess or VLESS connection and its transport parameters.
  • Local HTTP listener: Commonly 127.0.0.1:10809, suitable for HTTP_PROXY and HTTPS_PROXY.
  • Local SOCKS5 listener: Commonly 127.0.0.1:10808, useful when the application explicitly supports SOCKS.
  • Shell environment: Supplies proxy variables to the Claude Code process started from that terminal.
  • Routing policy: Determines whether the destination is sent through the node, directly, or blocked.

Prepare v2rayN before launching Claude Code

Start with the smallest reliable configuration. Open v2rayN and confirm that the client is running, the subscription has been updated recently, and one node can connect without repeated timeout messages. If the subscription itself cannot update, do not begin by changing Claude Code variables; first make the client’s own network path functional. A command-line proxy cannot repair an expired subscription, an incorrect UUID, a wrong Reality public key, or an unavailable server.

  1. Update the profile

    Open v2rayN, go to the subscription group area, update the profile, and select a known-good node. Prefer a node that has already passed a latency or connectivity test.

  2. Confirm the core

    Check “Settings” → “Parameter Settings” → “Core Type” and use the installed Xray core when the imported profile requires current VLESS or Reality features.

  3. Check local ports

    Verify the HTTP and SOCKS listeners. Use 127.0.0.1 rather than a LAN address unless another device genuinely needs to use this proxy.

  4. Choose a routing mode

    For the first test, use Global or a rule set known to proxy the required service domains. Switch back to rule-based routing after the connection path is confirmed.

  5. Enable the client

    Turn on the system proxy only if you want compatible desktop applications to use v2rayN automatically. This switch alone may not configure the terminal.

For a first Claude Code test, use Global mode temporarily or inspect the active rule set for direct rules affecting the service’s domains. Global mode is useful for diagnosis because it removes many routing variables, but it is not always the best permanent policy. In rule-based mode, a domain rule can send the authentication endpoint direct while another related endpoint uses the proxy. That creates confusing symptoms such as a login page opening but the CLI failing when it exchanges a token.

Do not enable TUN merely because the terminal is not working. TUN can capture applications that ignore proxy variables, but Claude Code should first be tested with an explicit local proxy. If the explicit HTTP proxy works, the issue is usually shell configuration or application inheritance rather than packet capture. TUN is a broader interception layer and should be introduced only when the required application does not honor the available proxy settings.

Configure PowerShell and terminal sessions

Open a new PowerShell window after v2rayN is ready. Setting variables in an existing terminal can work, but a new session makes it easier to know exactly what configuration is active. The following commands configure the current PowerShell process to use v2rayN’s HTTP listener:

$env:HTTP_PROXY = "http://127.0.0.1:10809"
$env:HTTPS_PROXY = "http://127.0.0.1:10809"
$env:ALL_PROXY = "http://127.0.0.1:10809"
$env:NO_PROXY = "localhost,127.0.0.1"

HTTP_PROXY and HTTPS_PROXY are the conventional variables to try first. Some tools read lowercase names instead, so setting both forms can improve compatibility in mixed environments:

$env:http_proxy = $env:HTTP_PROXY
$env:https_proxy = $env:HTTPS_PROXY
$env:all_proxy = $env:ALL_PROXY
$env:no_proxy = $env:NO_PROXY

These assignments affect only the current PowerShell process and programs launched from it. They do not change Windows system-wide proxy settings. That is normally desirable for troubleshooting because it prevents unrelated applications from receiving an experimental proxy configuration. If you use Command Prompt, the equivalent temporary settings are:

set HTTP_PROXY=http://127.0.0.1:10809
set HTTPS_PROXY=http://127.0.0.1:10809
set ALL_PROXY=http://127.0.0.1:10809
set NO_PROXY=localhost,127.0.0.1

When a terminal is opened inside an editor, check whether the editor started before the variables were set. Integrated terminals inherit the environment of their parent process. Close and reopen the terminal panel, or restart the editor, if Get-ChildItem Env:HTTPS_PROXY does not show the expected value. Also check for conflicting variables such as HTTP_PROXY pointing to an old port, a corporate proxy, or a second local client.

Do not place credentials or subscription URLs into proxy variables. A local v2rayN listener normally requires no username or password. If the port is protected by authentication in a custom setup, use the format required by that listener and avoid leaving secrets in shell history or shared configuration files.

Verify the route before signing in

Test the local listener independently before invoking Claude Code. First confirm that v2rayN is listening. In PowerShell, use:

Test-NetConnection 127.0.0.1 -Port 10809
Get-ChildItem Env:HTTP_PROXY,Env:HTTPS_PROXY

A successful TCP test proves only that something is listening on the port. It does not prove that v2rayN can reach the remote destination. Next, use a command-line HTTPS request through the same HTTP proxy:

curl.exe -I --proxy http://127.0.0.1:10809 https://claude.ai/

The response status can vary with service availability, authentication state, redirects, and policy. The useful result at this stage is that the request reaches an HTTPS response rather than failing immediately with “Could not connect to server,” “connection refused,” or a local timeout. Do not interpret a 401, 403, or redirect as proof that the proxy is broken; those responses mean the remote service answered and the next question is account or application behavior.

If the HTTP test fails, compare three observations: whether the port is listening, whether v2rayN logs show an outbound attempt, and whether the selected node remains connected. A refusal usually indicates a wrong port or disabled listener. A timeout with no corresponding v2rayN log often means the command did not use the proxy. A logged outbound timeout points to the node, routing, DNS, or remote network path.

Conclusion: test the shell before testing the assistant

If curl.exe succeeds through 127.0.0.1:10809 but Claude Code fails, stop changing node protocols first. Compare the Claude Code process environment, its proxy support, and its authentication flow; the basic v2rayN route is already demonstrated.

Launch Claude Code with a controlled configuration

With the variables set and the route tested, start Claude Code from that same terminal. The normal entry point is:

claude

Follow the sign-in instructions displayed by the CLI. Depending on the release and account configuration, the authentication flow may open a browser or provide a device-oriented confirmation step. Keep v2rayN running while the browser completes authentication, because the browser and the terminal may need to reach different endpoints during the same sign-in sequence. If a browser opens but the final confirmation never reaches the CLI, inspect the terminal’s proxy variables and v2rayN logs rather than repeatedly starting new login attempts.

After authentication, run a low-risk request in a small test project. Ask Claude Code to inspect a file or summarize the project structure before allowing commands that modify files. This separates connectivity from permission and project-state issues. A response arriving in the terminal proves that the process can communicate, but it does not mean every future command will be safe to approve; review tool requests and shell commands according to the project’s requirements.

If the CLI offers an explicit proxy option in your installed release, follow that release’s help output instead of assuming every version accepts the same flags. Environment variables are the most portable starting point, while application-specific options can change between versions. Record the working v2rayN port and shell commands so that a later update can be compared against a known baseline.

The browser signs in, but Claude Code times out. What should I check?

Run Get-ChildItem Env:HTTPS_PROXY in the same terminal, then repeat curl.exe -I --proxy http://127.0.0.1:10809 https://claude.ai/. If the variable is empty or the port differs from v2rayN, the CLI is probably bypassing the client.

Should I use the HTTP port or the SOCKS port?

Try the HTTP listener first with HTTP_PROXY and HTTPS_PROXY. Use 127.0.0.1:10808 only when the application or its runtime explicitly supports SOCKS5 proxy variables.

Why does Global mode work while rule mode fails?

A domain, IP, or geosite rule is likely selecting a direct outbound. Keep Global mode for diagnosis, then inspect the rule order and add a narrow proxy rule for the affected service domains.

Can TUN fix a missing proxy variable?

TUN may capture traffic that ignores proxy settings, but it does not fix an incorrect node or authentication problem. Test explicit HTTP proxy variables first, then consider TUN if the process still bypasses them.

Diagnose common failures without changing everything

Use the error location to choose the next test. A local port error belongs to v2rayN’s inbound listener. A proxy refusal belongs to the local connection between Claude Code and v2rayN. A remote timeout belongs to the selected node, DNS path, routing policy, or destination availability. A successful remote response followed by a sign-in rejection belongs to authentication, account access, or service policy rather than basic proxy connectivity.

Error: connect ECONNREFUSED 127.0.0.1:10809

Cause and fix: Nothing is accepting connections on the configured HTTP port, or the shell points to the wrong port. Start v2rayN, confirm the listener, and make HTTPS_PROXY match it exactly.

Error: Proxy CONNECT aborted or connection timed out

Cause and fix: The local proxy received the request but could not complete the remote tunnel. Check the selected node, routing mode, DNS handling, and Xray log entries for the destination.

Error: unable to verify certificate or TLS handshake failed

Cause and fix: Check the system clock, interception software, and node transport settings. Do not disable certificate verification as a first fix; confirm that the proxy path and server name are correct.

Sign-in completed in the browser but the CLI remains waiting

Cause and fix: The browser and terminal may be using different routes, or the callback was interrupted. Keep v2rayN active, verify the terminal’s proxy variables, and restart one controlled sign-in attempt.

Once the command works, switch from Global mode to your normal rule-based mode and run the same low-risk test again. This two-pass check identifies whether the issue is connectivity or policy. If the second test fails, compare v2rayN logs and rule matches rather than changing the subscription, core, ports, and shell variables simultaneously. One change at a time leaves a traceable result.

Maintain a reliable Claude Code workflow

For regular use, keep a short checklist beside the project rather than relying on memory. Confirm that v2rayN is running before starting the terminal, verify the selected node once, and use a consistent local port. If the subscription changes, test the route again because a newly selected node may have different DNS behavior, transport support, or availability. If Claude Code is launched by a task runner, service, or editor rather than an interactive shell, confirm that the same proxy variables are inherited by that parent process.

  • Use a dedicated PowerShell profile entry only after the temporary commands have been tested successfully.
  • Keep NO_PROXY limited to local addresses and internal domains that truly must bypass v2rayN.
  • Prefer rule-based routing for normal use, but use Global mode as a short diagnostic comparison.
  • Do not expose the local proxy listener to the LAN unless there is a specific reason and access control is configured.
  • Review Claude Code’s requested commands before approval, especially commands that modify files, install packages, or access credentials.
  • When troubleshooting, save the exact error, local port, routing mode, selected node, and terminal type.

The most dependable setup is not the one with the most switches enabled. It is the setup where each layer has been verified independently: v2rayN can connect to a node, the local HTTP listener accepts a request, the shell exposes that listener, the routing rules choose the intended outbound, and Claude Code can complete its own authentication flow. Once those checks pass, later failures are easier to classify and fix without rebuilding the entire configuration.

Download v2rayN