Back to guides
Tutorial·September 11, 2026·Updated October 3, 2026·10 min read

Claude Code Tutorial — Everyday Use with a Pay-as-You-Go Key: Switch Models, Calculate Costs, and Manage Context

Other tutorials assume you are logged into a subscription. With a pay-as-you-go key, every step is billed by token — this page explains how to use it smoothly and economically every day in that situation.

Claude Code can be summed up in four steps: run claude in your project folder, run /init once to generate CLAUDE.md, describe the task in Chinese and include the file path, then review its proposed changes and decide whether to accept them. It is a coding assistant that runs in your terminal: it reads and edits files and runs tests, asking for your approval before it makes changes. You can use it by signing in with a Pro/Max subscription or configuring a pay-as-you-go API key. When using a key, every step is billed by token, so the key to everyday use is three things: switch models based on the task, know how much a session costs, and keep context concise.

Most Claude Code tutorials online assume you are signed in with a subscription. This page is for a different kind of user: someone without a subscription, or who does not want to be constrained by the 5-hour usage window, and instead uses a pay-as-you-go key. If you have not installed it yet, start with the Claude Code installation guide, then come back once it is installed and connected.

Getting started: four actions

# 1. 一定要在專案資料夾裡啟動——它能看、能改的範圍就是這個資料夾
cd ~/work/my-app
claude

# 2. 第一個指令:讀過整個 repo,產生 CLAUDE.md
> /init

# 3. 之後直接用中文交代任務,附上檔案路徑最準
> 把 src/api/user.ts 的輸入驗證改用 zod,測試也一起修好

# 4. 牽涉很多檔案的任務,先按 Shift+Tab 切到計畫模式,確認做法再動手

It asks you first every time it needs to modify a file or run a command. If it is heading in the wrong direction, press Esc to stop it, then use /rewind to return to an earlier checkpoint. Both the code and the conversation will be rolled back. The CLAUDE.md generated by /init is only a draft; a section below explains specifically how to shorten it.

How a session is billed when using an API key

Each time Claude Code sends a request, it resends the system prompt, CLAUDE.md, the entire conversation, and the contents of files it has read, with new content appended at the end. The unchanged portion at the beginning is served from cache: cache reads are billed at 10% of the input price, and cache writes at 1.25 times the input price. As a result, the biggest part of a session's bill is often rereading the old conversation.

The table below uses the example session from Anthropic's official cost documentation—1,200 input, 5,300 output, 940,000 cache-read, and 50,000 cache-write tokens—and calculates it at Kunavo's rates for each of four models:

ModelInput / output (per 1M tokens)Cache reads (per 1M tokens)This session
Claude Haiku 4.5$0.70 / $3.50$0.07$0.129
Claude Sonnet 5$1.40 / $7.00$0.14$0.258
Claude Opus 5.5$2.80 / $14.00$0.14$0.384
Claude Fable 5$7.00 / $35.00$0.70$1.289

On Claude Sonnet 5, cache reads and writes account for about 85% of this bill. In other words, cost is determined by how long the conversation gets, not by how many words you type—which is why the next section covers context hygiene.

To check your own figures, run /usage in Claude Code (/cost is its alias). It will list the counts for these four token types. However, the amount shown next to them is Claude Code's local estimate using Anthropic's list prices. When using Kunavo, actual charges are shown on the dashboard's usage page, which lists token counts for each model, including cache reads and writes, along with the amount charged.

Switch models based on the task

First, in the ~/.claude/settings.json env block, map each alias to the actual model. Writing it in this file makes it available to editor extensions and background processes as well; do not write it to .claude/settings.json, which would be committed with the project. Aliases must be mapped: Claude Code’s default model and the opus alias both point to the latest Opus, and if Kunavo has not listed it yet, the first request will receive a 404 without the mapping; the sonnet alias points to Sonnet 5.5, which Kunavo does not offer, so without ANTHROPIC_DEFAULT_SONNET_MODEL, /model sonnet, the execution phase of opusplan, and subagents configured with model: sonnet will all receive 404. The configuration below maps the opus alias to Claude Opus 5.5 (claude-opus-5-5), and requires Claude Code v2.1.280 or later; on older versions, run claude update first.

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.kunavo.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-kn-...",
    "ANTHROPIC_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "claude-fable-5"
  }
}

Once configured, switching takes one line:

# 工作階段裡切換(別名會對應到上面設定的模型)
> /model haiku
> /model sonnet
> /model opus

# 也可以直接打完整名稱
> /model claude-fable-5

# 或在啟動時指定
claude --model claude-opus-5-5

/model saves your choice as the default for future new sessions; to switch just this once, run /model without an argument and press s in the menu. ANTHROPIC_DEFAULT_HAIKU_MODEL is required on Kunavo: without it, the haiku alias requests a model name that Kunavo does not offer (Haiku 5.5 from v2.1.293 onward), so /model haiku and subagents set to haiku both return 404s. It also determines which model Claude Code uses for its own background summaries and titles; setting it to the cheapest model can save money as well.

TaskModelPer step (25k input / 1.2k output, no cache)
Renaming, formatting, writing commit messages, summarizing logsclaude-haiku-4-5$0.022
Everyday feature development, bug fixes, adding testsclaude-sonnet-5$0.043
Architecture-level refactoring, planning across many filesclaude-opus-5-5$0.087
The hardest problems that neither of the first two can solveclaude-fable-5$0.217

At Kunavo, Claude Opus 5.5 costs $2.80 / $14.00, while Claude Sonnet 5 costs $1.40 / $7.00; Claude Haiku 4.5's unit price is approximately 1/2 of Claude Sonnet 5's, while Claude Fable 5 costs 5 times as much. Compared with official pricing: Claude Sonnet 5 Approximately 30% cheaper than Anthropic's official pricing, Claude Opus 5.5 Approximately 30% cheaper than Anthropic's official pricing, Claude Haiku 4.5 Approximately 30% cheaper than Anthropic's official pricing, Claude Fable 5 Approximately 30% cheaper than Anthropic's official pricing.

Switch models between tasks, not in the middle of a task.Each model has a separate cache: if you run /model halfway through a task, the next request has to reread the entire conversation at the uncached price (if the cache is still valid, Claude Code will ask you to confirm first). Run /clear before switching, and only the short new conversation needs to be reread. Thinking tokens are billed at the output price. For simple tasks, use /effort to lower the thinking level—set it at the start of the task as well, since changing effort mid-task invalidates the cache for most models.

CLAUDE.md: include only what you will need to repeat

CLAUDE.md
# CLAUDE.md — 放在專案根目錄,commit 進 git

## 指令
- 測試:npm test(只跑一個檔:npm test -- path/to/file)
- 型別檢查:npx tsc --noEmit
- Lint:npm run lint

## 規則
- 日期一律用 date-fns,不用 moment。
- API handler 只放在 app/api/**/route.ts。
- commit 訊息用繁體中文,前綴 feat / fix / docs。

## 不要動的地方
- db/migrations/ —— 產生出來的檔案,不要手改。

CLAUDE.md is loaded at the start of each session and included in every subsequent request, usually at the cache-read price. Anthropic recommends keeping each file to 200 lines or fewer—the longer it is, the more context it uses and the less reliably its instructions are followed. Do not include information that can be inferred from the code, such as directory structure or function descriptions. Notes meant only for people can be wrapped in <!-- -->; they are removed before being added to context.

Another common misconception: changes to CLAUDE.md made in the middle of a session do not take effect immediately. The new version is read only after /clear, /compact, or a restart.

Context hygiene: keep every step inexpensive

  • Use /clear between unrelated tasks. It starts a new conversation and costs nothing; you can retrieve the old conversation later with /resume.
  • Use /compact when the same task goes on too long. You can specify the key points to keep, for example /compact 保留測試輸出和改過的檔案. It sends one summary request, so it is cheapest to use while the cache is still valid. If you compact after being away for a long time, the summary request has to reread the entire history at the uncached price.
  • If it goes in the wrong direction, use /rewind. Rolling back to an earlier, already cached portion costs less than compacting.
  • In key mode, the cache expires after 5 minutes by default. If you return after more than 5 minutes away, the first step writes the entire previous context to the cache again (at 1.25 times the input price). Before leaving for a meeting or a meal, use /compact or /clear to wrap up.
  • Use /context to see what is taking up context. When using Kunavo, this figure is a local estimate—Kunavo currently does not provide /v1/messages/count_tokens; automatic compaction and the session itself are unaffected.
  • Turn off MCP servers you do not need in /mcp. Anthropic's documentation states that setting a custom ANTHROPIC_BASE_URL disables tool search, so MCP tool definitions are not loaded later; they take up space in every request from the start.
  • Include the file path when describing a task. “Fix the validation” makes it search all over and read many more files; “switch the validation in src/api/user.ts to zod” limits it to the files it needs.

To reduce the number of times it asks “May I run this?”, allow only commands used for reading and validation. Flags that skip all confirmations at once should be used only in environments you can afford to discard; see the explanation of --dangerously-skip-permissions (in English). For cache billing, see the cache documentation.

Spending limits and payments

Create a dedicated key for Claude Code on the key management page and set a monthly spending limit. Once it reaches the limit, requests from this key will return 402 and incur no further charges, so even an out-of-control loop can spend only up to the limit. You can also set an IP allowlist on the same page.

The account is prepaid: minimum top-up $10, the balance never expires, and failed requests are not charged. In Taiwan, you can top up with international credit cards (Visa, Mastercard, Amex, JCB, UnionPay) or Apple Pay and Google Pay; local channels such as JKO Pay and LINE Pay are currently unavailable. See Claude Code pricing for details.

When a subscription is more cost-effective

For people who interact with it for long periods every day and run many steps each month, a subscription's fixed monthly price is usually cheaper than pay-as-you-go. The calculation is one division: monthly fee ÷ cost per step = break-even number of steps. Based on Claude Sonnet 5's approximate cost of $0.043 per step (without cache), pay-as-you-go costs less if you run fewer than that number of steps in a month; months when you do not work cost $0 as well. Current monthly prices for each plan and the full calculation are on the Claude Code costs page; they are not repeated here.

The trade-off is worth stating clearly: when using Kunavo, you use shared capacity, with no dedicated quota or contractual SLA. Teams that need guaranteed capacity or an SLA should purchase directly from Anthropic. Full connection setup instructions are in the Claude Code integration documentation (in English).

Frequently asked questions

How do I use Claude Code?

Open a terminal in the project folder and run claude. The first time, run /init to let it read the whole project and create CLAUDE.md. Then describe the task in Chinese and include the file path, for example, “Change the validation in src/api/user.ts to use zod.” Claude Code reads and edits files and runs tests; it asks you before each file change or command. For tasks involving many files, press Shift+Tab to switch to plan mode, review the approach, and then let it make the changes.

Can I use Claude Code without a Pro or Max subscription?

Yes. Claude Code supports using an API key instead of signing in with a subscription: set the ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN environment variables, and it will authenticate with that endpoint instead. You'll be billed for the tokens actually used, with no monthly fee or 5-hour usage window. While the variables are present, your signed-in subscription is put on hold; remove them to return to your subscription.

How much does a Claude Code session cost with an API key?

For an example session from Anthropic's official cost documentation (1,200 input, 5,300 output, 940,000 cache-read, and 50,000 cache-write tokens), the cost at Kunavo rates is about $0.258 on Claude Sonnet 5 and about $0.129 on Claude Haiku 4.5. About 85% of the cost comes from cache reads and writes—that is, resending old conversation content—so conversation length, not how many characters you type, is the key to controlling cost. The amount shown by /usage in Claude Code is a local estimate using Anthropic's list prices; actual charges are shown on Kunavo's usage page.

How do I switch models in Claude Code?

In a session, enter /model followed by an alias (haiku, sonnet, or opus) or a full model name, such as /model claude-opus-5-5; you can also specify one at startup with claude --model. When using the gateway, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_HAIKU_MODEL determine which model each alias maps to. /model saves the selection as the default for future new sessions; to change it only this time, press s in the /model menu without arguments.

Does switching models halfway through a task cost more?

It costs extra once. Each model has its own cache, so after switching mid-task, the next request has to reread the entire conversation at the uncached rate. Claude Code asks you to confirm while the cache is still valid. To save money, switch between tasks: run /clear to start a new conversation, then /model. Only the short new context needs to be reread.

What should I put in CLAUDE.md?

Include only things you find yourself repeating: commands for tests and type checks, project-specific rules, and paths to generated files that must not be edited manually. Don't include directory structure or function descriptions that can be understood from the code. CLAUDE.md is loaded at the start of every session and sent with every request. Anthropic recommends keeping each file to 200 lines or fewer; longer files use more context and are followed less reliably.

/clear and /compact: what's the difference?

/clear starts a completely new conversation and costs nothing, so it is useful when switching to an unrelated task; you can retrieve the old conversation later with /resume. /compact summarizes the current conversation and continues from there, which is useful when the same task has gone on too long; you can specify the key points to retain. /compact itself sends one summary request, so it is cheapest to use while the cache is still valid.

Can I set a spending limit for Claude Code?

Yes. Create a dedicated key for Claude Code in your Kunavo dashboard and set a monthly spending limit. Once it reaches the limit, requests from that key will return 402 and incur no further charges. The account is prepaid, with a minimum top-up of $10, a balance that never expires, and no charge for failed requests.