天天AI
教程 登录 免费注册

首页 / 教程

Claude Code: step-by-step install

Install the Claude Code CLI, skip official login with Tiantian AI, and code in the terminal.

Want an AI that can read your project, edit code, and run commands right in the terminal?

Try Claude Code: Anthropic’s official terminal AI coding agent. Install it, point it at Tiantian AI, and start chatting.

This guide covers the CLI only. Desktop, VS Code, and JetBrains extensions are out of scope — see the official site if you need those.

About the links in this article: We include official docs for deeper reading or later reference. Following the steps here is usually enough; you do not need to open every link.

For multi-role orchestration (plan vs execute), see: OpenCode + oh-my-opencode: step-by-step install.

1. What it is

Claude Code is Anthropic’s official terminal agent: it can read your repo, edit files, run a shell, and help with Git. Talk to it in natural language.

2. Install

The official recommendation is the native installer (it also auto-updates in the background). Pick one command for your OS.

Case 1: macOS / Linux / WSL

curl -fsSL https://claude.ai/install.sh | bash

Open a new terminal, then confirm:

claude --version

Something like 2.1.211 (Claude Code) means it worked.

Case 2: Windows

PowerShell (prompt starts with PS):

irm https://claude.ai/install.ps1 | iex

CMD (no PS in the prompt):

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Open a new terminal and run claude --version as well.

Tip: on native Windows, install Git for Windows so Claude Code can use Bash tools.

3. Configure (smallest working loop)

The goal is simple: let Claude Code reach a model and start working.
The official “sign in with a Claude subscription / Console in the browser” path is expensive and roundabout. Skip it as a beginner. This guide wires Tiantian AI in one shot.

About official login
The first time you run claude, it may ask you to sign in with a Claude account in the browser (see https://code.claude.com/docs/en/quickstart).

We do not use that path. Write Tiantian AI into the config file as below. If it asks you to approve an API key, accept — do not log into the Claude website, and do not type /login in the session.

Do this instead:

  1. Write the config below first
  2. Then start claude
  3. Ask for what you need in plain language

1. Get a Tiantian AI key

  1. Open https://ai.ttshuli.com, sign up, and sign in
  2. In the console, create an API key (usually looks like sk-mt-...)
  3. Copy and keep it — you will paste it into the config. Do not post it in chats or screenshots.

The site docs have the same snippet for comparison: https://ai.ttshuli.com/docs.html

2. Write settings.json

Directory (create it if missing):

  • macOS / Linux: ~/.claude/
  • Windows: C:\Users\YourUsername\.claude\

Create or edit settings.json and paste this block (replace the key):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.ttshuli.com",
    "ANTHROPIC_API_KEY": "replace-with-your-key",
    "ANTHROPIC_MODEL": "auto",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "auto",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "auto",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "auto",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "auto",
    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "200000",
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "180000"
  }
}

Notes:

  • ANTHROPIC_BASE_URL is the site root https://ai.ttshuli.com — do not append /v1. Claude Code uses the Anthropic protocol; the OpenCode guide is the one that uses the OpenAI-compatible /v1 URL.
  • Point every *_MODEL at auto so Tiantian AI picks the best model. The catalog changes; beginners should not hard-code a specific name.
  • CLAUDE_CODE_MAX_CONTEXT_TOKENS is the max context window 200000 (plain digits only — not 200k). Claude Code does not read the window from the API for unrecognized IDs like auto; this env sets the assumed limit.
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW is 180000: auto-compaction runs at that threshold, a bit below the max for headroom. With only the max window set, the gauge can hit 100% without compacting, then the upstream rejects for context length. Set both, both as plain integers.

Also create ~/.claude.json in your home directory (note: under ~, not inside ~/.claude/):

{
  "hasCompletedOnboarding": true
}

Windows path: C:\Users\YourUsername\.claude.json.

3. Open Claude Code

Go to your project and start:

cd /path/to/your/project
claude

Then type something like:

What does this project do?

A normal answer means the config works.

4. How to use it (enough to start)

Ask first, then edit

On a new project, let it map the structure before changing code. For example:

What stack does this project use? Where is the entry point?

Then give a concrete task:

Add nickname search on the user list page, reuse the existing table component, do not change the API contract

Saying “what to change and what not to touch” saves tokens and rework versus “just fix it.”

Permissions: Shift+Tab

When it wants to edit files or run commands, it may ask for approval. Read the prompt before you accept.

Press Shift+Tab anytime to switch permission mode for the current session (whether every action needs confirmation). Stay conservative at first; loosen later when you trust it.

Common launch options

From your system terminal:

Command What it does
claude Interactive session in the current directory
claude -c Continue the last conversation in this directory
claude --dangerously-skip-permissions Open this project and auto-approve permissions; use when you do not want to confirm every step
claude --dangerously-skip-permissions -c Same, and resume the last session
claude -p "one question" Ask once and exit (one-shot queries)
claude "fix the build error" Start a chat with an initial task

In-session commands

Command What it does
/help List slash commands
/clear Clear the current conversation context
/exit Exit (or press Ctrl+D twice)

Type / for the command list; ↑ recalls previous input.

Optional: CLAUDE.md in the repo

Put a CLAUDE.md at the project root with stack notes, directory conventions, and “do not touch” rules. It helps Claude Code follow your project; you can skip it for a first try.

5. Saving money and troubleshooting

You already connected Tiantian AI, which is usually cheaper than an official subscription. A few habits save more:

  1. Keep the model at auto; do not force the most expensive tier for small jobs
  2. Scope the task (which files, what not to change)
  3. For large changes, ask it to analyze only, no edits, then implement after you agree on the plan

Common issues:

  • claude not found: open a new terminal; make sure ~/.local/bin (or the path the installer printed) is on PATH; run claude doctor
  • Still prompts official login / browser auth: check ~/.claude/settings.json, and that ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL are in effect
  • Cannot connect / auth errors: in the console, confirm the key still exists and you have quota; do not add /v1 to the Base URL
  • Rotate a key: change ANTHROPIC_API_KEY in settings.json

Official links

First run: write ~/.claude/settings.json and ~/.claude.json → cd into the project → claude → ask “what does this project do?”; once that works, give it a small edit.