No assumed knowledge here. If you know what a terminal is but have never touched an environment variable, you're in the right place.
If you've heard people talk about running Claude Code without paying for an Anthropic subscription, this is how. Agent Router hands out free API credits, and you can point Claude Code at them instead of your own wallet. This guide walks through the whole thing: what Agent Router actually is, how to claim the credits, and how to wire them into Claude Code on a Windows terminal, screenshot by screenshot, including the part where it broke and how I fixed it.
What Is Agent Router, and Why Are They Giving Away Credits?
Agent Router is an API gateway. That's a fancy way of saying: instead of signing up separately for Anthropic, OpenAI, DeepSeek, and every other AI provider, each with its own account, billing page, and API key, you sign up once with Agent Router and get one key that talks to all of them. Launched around October 2025, it positions itself as a non-profit, "public welfare" platform, meaning the free credits aren't a bait-and-switch into a paid tier. They're genuinely subsidized.
Why give away money in credits? The stated reason is to lower the barrier for developers who want to try tools like Claude Code but can't justify a subscription before knowing if it's worth it. New sign-ups get $100 in free credits. Sign up through a referral link and that jumps to $200. Refer someone else and you get a bonus too. Whether that's a permanent policy or a promotion that dries up when the budget runs out isn't something Agent Router has published clearly, so treat "free credits" as a limited-time offer, not a guarantee.
A fair warning before you dive in: Agent Router is new, it's not run by Anthropic or any of the model providers it routes to, and there's no published uptime guarantee. It's fine for learning, testing, and side projects. It is not something to build a client-facing product on top of.
Claim your credits here: Register here
Getting Your Credits...
- Go to your referral link (above) and sign up, GitHub login is the fastest route.
- Your account starts with credits already loaded, check your Dashboard to confirm the balance.
- Head to Console → API Token and generate a token. This token is what Claude Code will use to authenticate.
- Keep that token private. Anyone who has it can spend your balance. If it's ever exposed (screenshot, shared repo, pasted into a public chat), delete it immediately and generate a new one.
That's it for the Agent Router side. The next part is getting Claude Code to actually use it.
Credit where it's due: my first pass at this setup leaned on Vaibhav Verma's walkthrough on Medium, which lays out the basic install-configure-run flow clearly. Worth a read if you want a second perspective, and worth the follow, since a solid guide like that deserves more than three claps.
Setting Up Claude Code With Agent Router Credits (Windows Terminal)
Step 1: Install Node.js
Claude Code needs Node.js (v18 or newer) to run. Open PowerShell and check if you already have it:
powershell
node -v
npm -v
If either command comes back with an error, download and install Node.js from nodejs.org, then re-check.
Step 2: Install Claude Code
The straightforward path is npm:
powershell
npm install -g @anthropic-ai/claude-code
Heads up, this might fail. It did for me. The error looked like this:
Program 'claude.exe' failed to run: The specified executable is not a valid application for this OS platform
If you hit this, don't fight it, switch methods. Uninstall the npm version and use Anthropic's native installer instead:
powershell
npm uninstall -g @anthropic-ai/claude-code
irm https://claude.ai/install.ps1 | iex
If the install script also stalls or throws a file-access error, it's usually a leftover claude.exe process holding a file lock. The locked file is an .exe, not a .zip the exact filename appears in the error message itself, so copy it from there rather than guessing:
Close every terminal window and tab you have open, not just the one running the installer.
Open Task Manager (
Ctrl + Shift + Esc) → Details tab → look forclaude.exe→ if it's there, End Task.Clear the locked cached download(adjust the filename to match whatever version is failing)
:
powershell
Remove-Item "$env:USERPROFILE\.claude\downloads\claude-2.1.220-win32-x64.zip" -Force
Open a fresh PowerShell window as Administrator.
Run the install again:
powershell
irm https://claude.ai/install.ps1 | iex
Step 3: Add Claude Code to Your PATH (missing from most guides, but you will likely need this)
Even after a successful native install, Windows often won't recognize the claude command yet. The installer itself tells you why, right in its output:
Native installation exists but
C:\Users\<you>\.local\binis not in your PATH.
Fix it manually:
Search "environment variables" in the Start menu → open "Edit the system environment variables."
Click Environment Variables...
- Under User variables, select Path, click Edit, then New, and add:
C:\Users\<yourusername>\.local\bin
Click OK on every open dialog.
Close your terminal completely, open a fresh one, and confirm:
powersell
claude --version
You should now see a version number like 2.1.220 (Claude Code).
Step 4: Get Your Agent Router API Token
Head back to your Agent Router console →** API Token*. If you haven't created one yet, the list will be empty. Click **Create Token*
Fill it in:
Name: anything recognizable, e.g. "Claude."
Expiration time: pick "Never expires" explicitly. Don't leave the default placeholder date as-is, it can look like an already-expired timestamp.
Quota: caps how much of your balance this specific token can spend. Leave "Unlimited quota" off if you want a hard ceiling.
Submit, then copy the generated key. It'll look like sk- followed by a long string. This is the key you must not show in screenshots.
Step 5: Set Your Environment Variables
The original version of this guide has you set three variables, including both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY with the same value. In practice, setting both at once triggers a conflict warning every time Claude Code launches. It doesn't break anything, but it's unnecessary. Set only the base URL and the auth token:
powershell
setx ANTHROPIC_BASE_URL "https://agentrouter.org/"
setx ANTHROPIC_AUTH_TOKEN "sk-your-key-here"
If you already set ANTHROPIC_API_KEY earlier (from following the original three-variable version), remove it so it doesn't conflict:
powershell
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue
To confirm it's actually gone (check in a fresh terminal window, not the one you set it in):
powershell
echo $env:ANTHROPIC_API_KEY
echo $env:ANTHROPIC_AUTH_TOKEN
[System.Environment]::GetEnvironmentVariable("ANTHROPIC_API_KEY","User")
[System.Environment]::GetEnvironmentVariable("ANTHROPIC_API_KEY","Machine")
ANTHROPIC_API_KEY should print nothing on all four.
ANTHROPIC_AUTH_TOKEN should print your key.
Important: After setting these with setx or the GUI, close and reopen your terminal completely. setx doesn't apply to windows that are already open.
Step 6: Tell Claude Code Which Model to Use
This step gets skipped in most guides, and it matters. Without it, Claude Code falls back to its own default model behavior, which may not match what your Agent Router token is actually scoped to use, especially if you set a model restrictions list on the token itself (visible under the token's Access Restrictions section in the Agent Router console).
You may see advice online telling you to run claude --model claude-3-opus. Don't use that, it names a model that's no longer current, and a one-off flag only applies to that single session. Set it permanently instead, alongside your other two variables:
powershell
setx ANTHROPIC_MODEL "claude-opus-4-8"
Use whichever exact model identifier your Agent Router console lists for you, check Console → API Token → your token → Access Restrictions → Model restrictions list to see the exact strings it supports (for example claude-opus-4-8, claude-opus-5, or non-Claude options like gpt-5.6-sol if you want to route to a different provider entirely through the same gateway).
If you leave a token's model restrictions blank, it supports all models Agent Router offers, in which case setting ANTHROPIC_MODEL just pins Claude Code to a specific one instead of leaving it ambiguous.
Close and reopen your terminal after setting this, same as the other variables.
A note on running out of credits
At some point your token's quota (or your account balance) will hit zero. When that happens, Claude Code won't crash outright, you'll get an authentication or request error back from Agent Router mid-session, usually something referencing a 402 or quota-exceeded response. If you see requests suddenly failing after previously working fine, that's the first thing to check, not your PATH or your variables.
Fix: go back to Console → API Token, either top up your account balance or generate a fresh token if the old one expired, then repeat Step 5 with the new key.
Step 7: Launch Claude Code
Open a fresh terminal and run:
powershell
claude
If you followed Step 5 and only have ANTHROPIC_AUTH_TOKEN set, this warning won't appear at all, and you'll go straight to the folder trust check:
Folder trust check: Claude Code asks if it's okay to read/edit/execute files in your current folder. Choose "Yes" if it's your own project.
Once you're past this, you're in.
Step 8: Confirm the Credits Are Actually Being Used
Go back to your Agent Router dashboard. You should see your balance ticking down and a request log building up as you use Claude Code.
If the numbers are moving, it's working. You're now running Claude Code on Agent Router's credits instead of a direct Anthropic subscription.
One more check: make sure it's not silently falling back to Anthropic
Setting the variables correctly doesn't guarantee Claude Code is actually using them, if any of the three (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL) got typo'd, dropped, or overridden by a leftover settings.json entry, Claude Code can still run without erroring, just against Anthropic directly, quietly spending nothing from Agent Router while you assume it's working.
Don't just glance at the dashboard once, actually run one real request in Claude Code, then immediately check:
Agent Router's usage log (Console → Usage log) should show a new entry with a timestamp matching right now.
If the log is empty after a request that clearly went through, something's misconfigured, recheck Step 5's variables in a fresh terminal before assuming it's fine.
Part 4: Using Claude Code After Setup
Everything above only needs to happen once. After that, running Claude Code is quick, no admin terminal, no environment variables to re-set, none of it.
Step 1: Open a normal terminal
Regular PowerShell is fine now, you don't need Administrator anymore. All three environment variables (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL) were set with setx, so they persist across every new terminal session automatically.
Step 2: Navigate to your project
powershell
cd C:\Users\<yourusername>\path\to\your\project
Run Claude Code from inside the actual project folder you want it working on, not your whole user directory, it scopes its file access to wherever you launch it from.
Step 3: Launch it
powershell
claude
First time in a given folder, you'll get the folder trust prompt again, choose "Yes, I trust this folder." You won't see this again for that same folder on future runs.
Step 4: Just talk to it
Once you're in, type what you want in plain language:
Fix the bug in src/components/Header.tsx
Explain what this function does
Add a dark mode toggle to the navbar
Refactor this component to use Tailwind instead of inline styles
Write tests for the useContract hook
It'll propose changes and show you what it plans to do before applying them. Review, approve, move on.
Quick sanity check, if it's been a while
If you haven't used it in a bit and want to confirm everything's still wired up correctly before diving in:
powershell
claude --version
A version number back means you're good to go straight into a project.
Quick Troubleshooting Recap
| Problem | Fix |
|---|---|
claude.exe "not a valid application for this OS platform" |
Uninstall the npm version, use the native installer (irm https://claude.ai/install.ps1 | iex) |
| Install script hangs or throws a file-access error | Close all terminals, kill any claude.exe process in Task Manager, delete the exact locked file named in the error, retry as Administrator |
claude --version says "not recognized" after a successful install |
.local\bin isn't in your PATH yet, add it manually and open a fresh terminal |
"Both AUTH_TOKEN and API_KEY set" warning |
Avoidable entirely — only set ANTHROPIC_AUTH_TOKEN, skip ANTHROPIC_API_KEY
|
Environment variables not showing up after setx
|
Close and reopen your terminal completely — setx doesn't affect already-open windows |
If you get stuck somewhere this guide doesn't cover, drop a comment below or reach out, happy to help troubleshoot. This setup has enough moving parts (Windows quirks especially) that something almost always breaks on the first try, you're not doing anything wrong.


















Top comments (0)