Claude Code on Windows: A PowerShell Cost Receipt
01 / Start with a receipt, not a monthly promise
A useful Claude Code budget has four lines: ordinary input, output, cache writes, and cache reads. Counting prompts alone tells you little about the final bill. Claude Code can report these token categories, but its displayed dollar estimate may use list prices rather than your relay’s actual rates. Treat the relay’s billing record as the receipt. ([code.claude.com](https://code.claude.com/docs/en/costs))
CheapRelay offers pay-as-you-go access with no monthly fee or subscription, billing real tokens, including cache reads and writes. That removes a recurring subscription charge from this setup; it does not make individual coding tasks free or predictably priced.
02 / Set the PowerShell environment before launching Claude
Assume Claude Code is already installed. In PowerShell, environment assignments use $env:NAME, not Bash’s export syntax. Set them in the same terminal that will launch Claude Code: child processes inherit that terminal’s environment. ([learn.microsoft.com](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.1&utm_source=openai))
Run these commands individually. The prompts avoid putting a literal credential into the command itself; use a private terminal when entering it.
- ■ $env:ANTHROPIC_BASE_URL = Read-Host 'Paste the CheapRelay Claude Code API base'
- ■ $env:ANTHROPIC_AUTH_TOKEN = Read-Host 'Paste your CheapRelay API key'
- ■ $env:ANTHROPIC_MODEL = Read-Host 'Paste the exact supported model ID'
- ■ claude
Copy the API base and model identifier from CheapRelay’s current Claude Code instructions. Do not substitute a display name or assume an OpenAI-compatible endpoint is automatically the correct Claude Code endpoint. Anthropic documents ANTHROPIC_BASE_URL for gateway routing and ANTHROPIC_AUTH_TOKEN for gateway authentication; the gateway must support the required API format. ([code.claude.com](https://code.claude.com/docs/en/llm-gateway-connect))
For example, if choosing Claude Haiku 4.5, copy its exact relay model ID rather than guessing the spelling. Keep this first session temporary until a small request succeeds.
03 / Keep the endpoint persistent without saving the key
For the current process, check the endpoint with $env:ANTHROPIC_BASE_URL. Check credential presence without printing it using [bool]$env:ANTHROPIC_AUTH_TOKEN. These checks establish what the shell contains, not whether the server accepts the credential.
To persist only the endpoint, run [Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', $env:ANTHROPIC_BASE_URL, 'User'). Windows user-scoped variables survive the current process; $env: assignments alone do not. Restart the terminal application before testing inheritance in a fresh session. ([learn.microsoft.com](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Environment_Variables?utm_source=openai))
I recommend entering the key again for each working session rather than adding it to a repository or profile. If authentication fails, inspect the configured endpoint and credential method before sending repeated test requests.
04 / A four-line example receipt totaling $0.235
The following rates are hypothetical arithmetic inputs, not verified CheapRelay prices, advertised discounts, or measured task costs. Replace every rate with the current rate for your selected model and cache duration before budgeting.
- ■ Ordinary input: 40,000 tokens at an assumed $1.00 per million = $0.040.
- ■ Output: 10,000 tokens at an assumed $5.00 per million = $0.050.
- ■ Cache writes: 100,000 tokens at an assumed $1.25 per million = $0.125.
- ■ Cache reads: 200,000 tokens at an assumed $0.10 per million = $0.020.
- ■ Example usage total: $0.235, or 23.5 cents, before any applicable taxes or separate charges.
Each line follows the same calculation: tokens divided by 1,000,000, multiplied by the category’s rate. These buckets must be non-overlapping: do not charge cache tokens again as ordinary input. Caching has distinct read and write pricing, so one blended input rate can conceal the expensive part. ([claude.com](https://claude.com/resources/articles/maximizing-the-value-of-your-claude-code-sessions?c=42&fcdaa149_sort_Plus+ancien=asc&utm_source=openai))
05 / Turn one receipt into a working budget
Twenty identical example sessions would total $4.70; forty would total $9.40. Those are multiplication exercises, not monthly forecasts. Your next debugging task might consume a different amount of context or output.
Record the selected model, four token counts, applicable rates, and actual debit after your first small task. Compare the debit with your reconstruction before running unattended work. Sign up for CheapRelay when you are ready to test that first receipt, then budget from observed charges rather than a promised cost per prompt.
注册 价格自己试,注册就送试用额度。
顺手再看
| 日期 | 货架 | 语言 | 标题 |
|---|---|---|---|
| 2026-10-25 | 省钱用编码 Agent | EN | Coding Assistant Habits That Double Your Bill A receipt-style breakdown shows how oversized prompts and verbose answers turn a $0.60 coding session into $1.20, before retries. |
| 2026-10-25 | 省钱用编码 Agent | EN | Three AI CLIs, One Desktop, a $30 Budget A receipt-style plan for running Claude Code, Codex and Gemini CLI together, with a $30 usage budget and no invented token prices. |
| 2026-10-25 | 省钱用编码 Agent | EN | Coding Agents in CI: A $0.50 Pipeline Budget Build a receipt for every coding-agent run, reserve spend before requests, and stop retries before they turn a small fix into a large bill. |
| 2026-10-25 | 省钱用编码 Agent | EN | Gemini CLI vs Claude Code: The Shell Chore Receipt A concrete token-cost comparison for shell chores, with itemized receipts, retry math, cache caveats, and practical spending controls. |
| 2026-10-25 | 省钱用编码 Agent | EN | Cheap First, Escalate Later: A Coding Cost Receipt A worked token receipt shows how cheaper-first pair programming can cut API spending, with clear rules for escalating without wasting developer time. |
| 2026-10-25 | 省钱用编码 Agent | EN | Coding Agent Memory Files: Show Me the Receipt A concrete cost breakdown of coding agent memory files: repeated input, cache reads, maintenance, and the point where useful instructions pay off. |