November 9, 2026 · Platform Setup · 10 min read

Claude Code Proxy Setup: Route Terminal Traffic With V2rayN

Claude Code may fail to sign in or time out when terminal traffic is not using the expected proxy. Follow this practical guide to configure V2rayN for command-line connections, test the route, and troubleshoot common setup issues.

At a glance

Claude Code runs from a terminal, so its network requests may not follow the same route as a browser. This guide shows how to identify V2rayN’s local HTTP proxy port, set proxy variables for the shell that launches Claude Code, test the connection before signing in, and remove temporary settings safely. It is for users who already have a working V2rayN node and need to distinguish a proxy configuration problem from an account, DNS, or service issue.

Why a working browser does not prove the terminal is proxied

A browser and a command-line program can use different proxy settings. V2rayN may configure the operating system’s proxy for applications that honor those settings, while a terminal process may instead read environment variables, use its own networking library, or connect directly. As a result, a webpage can load through V2rayN while Claude Code times out during sign-in or while making a request.

Keep the route in mind as a chain: Claude Code starts in a shell, reads the process environment, connects to V2rayN’s local listener, and then the selected node carries the request toward its destination. A failure at any one of these stages can look like a generic network error. Checking them in order avoids changing node settings when the actual issue is a missing environment variable or a mismatched local port.

Claude Code Shell environment Local proxy V2rayN node Service response

System proxy mode and TUN mode are not interchangeable with an explicit terminal proxy. System proxy settings mainly affect applications that consult the operating system’s proxy configuration. TUN can capture broader device traffic, but it adds another layer of routing and permissions to troubleshoot. For a first test, an explicit local HTTP proxy in the launching terminal is easier to verify and keeps the test limited to that process and its child processes.

1 port
Use the actual local listener shown in V2rayN
2 variables
HTTP_PROXY and HTTPS_PROXY for common CLI tools
1 change
Test one routing change at a time

Find and verify V2rayN’s local proxy listener

Do not assume that a particular port number is correct for every installation. V2rayN versions, imported configurations, and user settings can differ. Open V2rayN’s main window and inspect the local HTTP or mixed proxy port in its settings. In commonly used Chinese-interface builds, look under “Settings” → “Parameter Settings” → “Basic Settings”; labels and menu placement can vary between versions. Record the actual address and port displayed by your client before setting a terminal variable.

For a local listener, the address is often 127.0.0.1 or localhost. The port is the important part to verify in V2rayN. A SOCKS listener and an HTTP listener use different proxy schemes. For a simple command-line test, use the HTTP listener if it is available, because many tools understand an HTTP proxy URL for both HTTP and HTTPS destinations through the CONNECT method. Do not label a SOCKS port as HTTP just because it is open.

Local HTTP listener

Recommended

Set an HTTP proxy URL such as http://127.0.0.1:PORT, replacing PORT with the value shown by V2rayN. It is a practical first choice for command-line programs that read standard proxy variables.

Suitable for: an explicit terminal test with common HTTP-based CLI clients

SOCKS listener

A SOCKS listener may work if the application explicitly supports the appropriate SOCKS URL scheme. Support can vary by program and runtime, so an open SOCKS port alone does not prove that Claude Code or every child process will use it.

Suitable for: applications whose documentation confirms SOCKS proxy support

On Windows, you can check whether the selected port is listening with PowerShell. Replace 10809 below with the port you recorded; this number is only an example. The command reports a TCP connection to the local address, not whether a remote service is reachable or whether V2rayN has a usable node.

Test-NetConnection 127.0.0.1 -Port 10809

Look for TcpTestSucceeded : True. If it is false, recheck the port in V2rayN, confirm that the client is running, and make sure its core is connected and listening. Do not respond by opening the port to the public internet. A terminal proxy listener should normally remain bound to the local machine unless a separate, deliberate network design requires otherwise.

Set proxy variables in Windows PowerShell

Environment variables are inherited when one process launches another. Set them in the same PowerShell window from which you will start Claude Code. Opening a new terminal afterward creates a separate process environment, so the temporary values will not necessarily carry over. This approach is useful for a controlled test because closing the shell removes the session-level settings.

  1. Confirm the port

    Read the HTTP listener port from V2rayN’s settings. Check it with Test-NetConnection 127.0.0.1 -Port PORT, replacing PORT with the real number rather than typing the word itself.

  2. Set the variables

    In the same PowerShell window, assign both variables to the local HTTP proxy URL. Keep the quotes and use the port that V2rayN actually displays.

  3. Test the route

    Use a basic HTTPS request through the shell before starting Claude Code. If the request cannot reach its target, fix the listener or route before investigating the sign-in flow.

  4. Launch from that shell

    Start Claude Code from the same window so the process inherits the variables. If you launch it from another terminal, an editor task, or a shortcut, verify that process has the same environment.

$env:HTTP_PROXY = "http://127.0.0.1:10809"
$env:HTTPS_PROXY = "http://127.0.0.1:10809"

# Test a request through the configured proxy
curl.exe -I https://example.com

# Start Claude Code from this same PowerShell window
claude

Replace 10809 with the local HTTP port you verified. The example request uses a general HTTPS destination to test the network path; it does not test Claude Code authentication or guarantee access to any specific service. If the command reports that the proxy cannot be reached, check for a mistyped port or a stopped listener. If it receives an HTTP response, the local proxy path is functioning for that request, though a different destination can still be blocked or unavailable.

Use curl.exe in PowerShell when you specifically want the Windows curl executable. In some PowerShell versions, curl may refer to a shell alias rather than the program you expect. A reliable test command reduces confusion when comparing output or following troubleshooting instructions.

To return the current shell to its previous state, remove the variables from that session:

Remove-Item Env:HTTP_PROXY -ErrorAction SilentlyContinue
Remove-Item Env:HTTPS_PROXY -ErrorAction SilentlyContinue

These commands clear the variables in the current PowerShell process; they do not uninstall V2rayN, alter its listener, or change other terminals already open. If you deliberately saved proxy variables in Windows user or system settings, remove or update them through the same settings location instead. Avoid setting persistent machine-wide variables just to solve a one-shell test, since unrelated tools may inherit them later.

Configure Command Prompt, Git Bash, or another shell

The key principle is the same across terminals: use a proxy URL that matches the listener and start Claude Code from a process that inherits the variables. The syntax for setting environment variables differs by shell. Do not paste PowerShell assignment syntax into Command Prompt or Bash; a command may fail, or a variable may be created only for a different process than intended.

Command Prompt

In Command Prompt, use set to define variables for that window and commands launched from it. Replace the sample port before testing.

set HTTP_PROXY=http://127.0.0.1:10809
set HTTPS_PROXY=http://127.0.0.1:10809
curl.exe -I https://example.com
claude

These assignments apply to the current Command Prompt session and its child processes. Closing the window discards them. If you open a second Command Prompt, set the variables there as well before launching Claude Code.

Git Bash and other Bash shells

In a Bash-compatible shell, use export. The same syntax generally applies to shells on Linux and macOS, but the local proxy address must be reachable from that machine. If V2rayN is running on a different computer, 127.0.0.1 points to the terminal’s own computer, not to the V2rayN host.

export HTTP_PROXY="http://127.0.0.1:10809"
export HTTPS_PROXY="http://127.0.0.1:10809"
curl -I https://example.com
claude

For a temporary test, run the commands directly in the shell. If you choose to add exports to a shell startup file, understand that they will affect future terminal sessions and may route unrelated command-line programs through V2rayN. Keep a note of the exact lines so you can remove them later. Avoid putting subscription links or authentication credentials in shell files; proxy variables should normally contain only the local listener address and port.

Some tools recognize lowercase names such as http_proxy and https_proxy, while others prefer uppercase names. If a verified request works in the shell but one child tool appears to ignore the proxy, check that tool’s documentation and inspect which variables its process receives. Add lowercase variants only when the specific environment needs them, and keep the values consistent rather than setting conflicting addresses.

Test Claude Code without confusing connection stages

Once an ordinary HTTPS request succeeds through the local proxy, start Claude Code from that same terminal. If the command is not found, that is a command installation or PATH issue, not a proxy failure. If Claude Code starts but sign-in fails, note exactly where the failure occurs: before a browser opens, during browser authentication, when the terminal callback returns, or after the command resumes. Each stage uses a different part of the setup.

Do not treat a browser-based sign-in window as proof that terminal requests are proxied. The browser may use operating-system proxy settings while the CLI process reads environment variables. Conversely, an authentication page may open successfully while the local callback cannot reach the original terminal process. Record the message shown in the terminal and whether the browser completed its step before changing any configuration.

Local route check

Listener address
127.0.0.1
Listener port
Use the HTTP port shown in V2rayN
Shell variables
HTTP_PROXY and HTTPS_PROXY
Basic test
HTTPS request from the same terminal

A successful test confirms that this request used a working local path; it does not confirm every destination is available.

Claude Code check

Launch context
Same shell where variables were set
Command
claude
Failure detail
Capture the first specific message
Comparison
Retest without changing the node

Separate a CLI network error from a missing command, an account issue, or a browser callback problem.

Keep a small test record: the V2rayN listener port, selected node name (without credentials), shell type, result of the local-port check, result of the HTTPS request, and the exact time of the Claude Code error. This makes it easier to see whether the issue changes when the listener or node changes. Never include a subscription URL, access token, API key, or private configuration in a shared log.

Where a service or network policy restricts access, follow the applicable rules and use an authorized connection. A proxy can route traffic, but it cannot make an unavailable account, invalid credential, expired subscription, unsupported feature, or service-side outage valid. Once the proxy test is successful, investigate those separate causes using the relevant service guidance rather than repeatedly changing V2rayN.

Troubleshoot common proxy setup errors

Change one variable at a time and repeat the same test. If you change the port, node, shell, and TUN setting simultaneously, a successful result will not tell you which change mattered. Start with the most local failure and work outward: shell configuration, listener, V2rayN connection, then the destination and application behavior.

ECONNREFUSED 127.0.0.1:10809

Cause and fix: Nothing is accepting the connection at that address and port, or the listener is not active. Verify the HTTP port in V2rayN, confirm the client and core are running, then repeat the local port test.

Could not resolve proxy

Cause and fix: The proxy URL may be malformed or may contain a placeholder instead of a port. Use a URL such as http://127.0.0.1:10809 with the actual listener port and no extra spaces.

407 Proxy Authentication Required

Cause and fix: The proxy endpoint is requesting authentication or is not the local listener you intended to use. Check the variable value and the selected listener; do not put node credentials into a local proxy URL.

curl succeeds, but Claude Code still times out

Cause and fix: The two processes may have different environments, or the application request may be failing for another reason. Start Claude Code from the tested shell, confirm its proxy support, and compare the exact error before changing the node.

If the local port test succeeds but the HTTPS request fails, examine the request error. A connection refusal usually points back to the local listener; a timeout after connecting can involve the core, node, DNS, or destination. A certificate error is different again: do not disable certificate verification as a routine workaround. Record the hostname, time, and complete error text while removing any secrets before sharing diagnostic output.

If requests work in one terminal but not another, compare the launching process rather than reinstalling V2rayN. An editor’s integrated terminal, a task runner, and a separately opened shell may not share the same environment. Set the variables in the environment that directly starts Claude Code, or use a documented environment configuration for that launcher. Restart the terminal or editor when it needs to create a fresh process with updated settings.

If a previously working setup stops, check whether V2rayN’s port changed, whether a second application took the old port, whether the client disconnected, or whether the shell inherited stale values. A port change in V2rayN does not automatically rewrite environment variables already set in open terminals. Update the variables and retest; do not assume that restarting Claude Code in the same incorrectly configured shell will fix the mismatch.

Conclusion: prove each hop before changing the node

First confirm the local listener, then verify a basic request from the same shell, and only then test Claude Code. If the first two checks pass, focus on the application’s launch environment or the specific service response instead of cycling through nodes without evidence.

Keep the working setup temporary or make it persistent deliberately

For most troubleshooting, session-level variables are the safer starting point. They affect the terminal window and child processes you choose, making it clear which commands are using the proxy. When the window closes, the temporary settings disappear. This also helps avoid surprising behavior in unrelated tools that may otherwise inherit proxy variables.

If you need a persistent setup, choose the narrowest scope that meets your workflow. A shell startup file can apply the variables to future shells for your user account; a user-level operating-system environment setting can affect more applications launched from that account. After changing persistent settings, open a new terminal and inspect the resulting values before relying on them. Update or remove them if V2rayN’s listener port changes.

Leave TUN and system proxy settings in their original state during the first explicit-proxy test. If you later choose to use TUN or system-wide routing, treat that as a separate configuration and verify its effects independently. Running multiple routing methods at once can make it difficult to determine which path a request used.

When asking for help, include the operating system, shell type, V2rayN version, the kind of local listener used, and the sequence of test results. Redact account information, API keys, subscription tokens, server addresses when sensitive, and personal directory names. A short sanitized error from the first failing step is usually more useful than a full environment dump containing unrelated secrets.

The core procedure is straightforward: identify the local HTTP listener, set HTTP_PROXY and HTTPS_PROXY in the launching shell, test a basic HTTPS request, and start Claude Code from that same shell. When those checks are recorded separately, a failure is easier to place in context. You can then distinguish a terminal that never reached V2rayN from a request that reached the proxy but failed later in the route.

Download V2rayNChoose your platform