• Home
  • Search
  • AI Services
  • Models
  • Writing
  • Multimedia Creation
  • Translation & Others
Home›Developer Center›Claude Code CLI macOS

Claude Code CLI macOS

API DocumentationAPI Quick StartOpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI Pricing
CLI & Agent Guidescc-switch macOScc-switch Windowscc-switch LinuxOpenCode macOSOpenCode WindowsOpenCode LinuxOpenClaw macOSOpenClaw WindowsOpenClaw LinuxHermes Agent macOSHermes Agent WindowsHermes Agent LinuxClaude Code CLI macOSClaude Code CLI WindowsClaude Code CLI LinuxCodex CLI macOSCodex CLI WindowsCodex CLI Linux
MYAI168 API & MCPMYAI168 Chat API GuideMYAI168 MCP CLIMYAI168 MCP Web & App
User GuidesGT Agent GuideAI Services Guide
No matching questions on this page.Search the whole site
Installation Overview (macOS)

Claude Code CLI Installation and MYAI168 Setup Guide — macOS

Goal of this guide: install the Claude Code CLI on macOS, connect it to your own MYAI168 API, and use Claude Opus 5.5.

Claude Code speaks the Anthropic Messages protocol and connects to MYAI168's native Anthropic endpoint — no proxy needed. The key is supplied via an apiKeyHelper script — this is NOT a required setting (Claude Code officially supports setting the ANTHROPIC_API_KEY environment variable directly; apiKeyHelper is officially intended for dynamic / rotating credentials). This guide uses it so the key stays out of your shell environment variables and is easy to replace in one place.

Endpoint and Model (the most critical part)

  • Endpoint: https://www.myai168.com/en/api/anthropic (do not append /v1 at the end)
  • Model: claude-opus-5-5

The base_url must end with .../anthropic — "never add /v1". Claude Code appends /v1/messages by itself; if the URL already contains /v1 the path becomes wrong, and you get a misleading "model does not exist" error. (This is the most common pitfall.)

Important Security Notes

  • Claude Code can read, write, and execute files in the working directory. For real use, cd into a project folder before launching it; do not launch it in your home directory.
  • Treat your API key like a password and never leak it; if it leaks, delete it on the Developer API Key page and create a new one.

Prerequisite

System requirements (per the official docs): macOS 13.0 or later and 4 GB+ RAM, on Apple Silicon or Intel.

The official native installer (recommended) does not need Node.js; Node.js 22 or later is only required if you install with npm instead.

1. Install

First check whether it is already installed:

claude --version

If you see a version number, skip to "2. Create the apiKeyHelper". If it shows command not found, install with the official native installer (recommended; it then updates itself in the background):

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

You can also use Homebrew (brew install --cask claude-code tracks the stable channel, typically about a week behind; install claude-code@latest for the newest release; Homebrew installs never auto-update) or npm (requires Node.js 22 or later: npm install -g @anthropic-ai/claude-code).

After installing, open a new terminal window and confirm:

claude --version

(If it is still command not found, the install directory ~/.local/bin is not on your PATH yet: run echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc, then source ~/.zshrc and try again; you can also run claude doctor to check the installation.)

2. Create the apiKeyHelper (the key-supply method this guide uses)

This guide supplies the key via an apiKeyHelper whether you use cc-switch or configure manually (it is not an official requirement — Claude Code also supports setting the ANTHROPIC_API_KEY environment variable directly; to follow this guide's flow, create it first):

mkdir -p ~/.claude

Create the key script (copy the whole block, paste it into the terminal, and press Enter once; replace the key with your real MYAI168 key):

cat > ~/.claude/api-key-helper.sh << 'EOF'
#!/bin/bash
echo "your-MYAI168-key"
EOF
chmod +x ~/.claude/api-key-helper.sh

Verify it outputs the key (it should print your key string):

~/.claude/api-key-helper.sh

Note: the script must print nothing but the key — no banners, prompts or log lines. From Claude Code 2.1.227, any extra output makes the helper fail. Claude Code caches the script output for 5 minutes, so a replaced key takes effect within 5 minutes, or immediately after you restart Claude Code.

3. Configure MYAI168 (Method A: cc-switch, recommended)

For installing cc-switch and a tour of its interface, see the cc-switch macOS page.

  • Open cc-switch and select "Claude Code" in the app switcher at the top left.
  • Click "+" (Add Provider) at the top right and set Provider Preset to "Custom Configuration".
  • Basic fields:
    • Provider Name: myai168-claude
    • API Key: leave it empty (the key is supplied only by the apiKeyHelper script; as a result the form's "Fetch Models" button cannot be used, so type the model IDs by hand)
    • API Endpoint: https://www.myai168.com/en/api/anthropic (without /v1)
  • Expand "Advanced Options":
    • Upstream Format: Anthropic Messages (Native)
    • Auth Field: leave it unchanged (with an empty API Key no key field is written)
  • Model Mapping — Requested model: Opus claude-opus-5-5, Sonnet claude-sonnet-5-5, Haiku claude-haiku-4-5, Fable claude-fable-5-1 (the same mapping as settings.json in "3-B"); Default fallback model claude-opus-5-5. To always use Opus, you may set all four to claude-opus-5-5 instead. Third-party endpoints need this mapping — otherwise background tasks use Claude Code's built-in model names and fail.
  • Config JSON area: cc-switch does not add apiKeyHelper for you, so add an "apiKeyHelper" line by hand (pointing to the script from "2. Create the apiKeyHelper"), and make sure there is no ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN line (delete it if present, otherwise you get an Auth conflict warning). It must contain at least the following (keep the ANTHROPIC_DEFAULT_*_MODEL and other lines cc-switch writes from the model mapping):
    {
      "apiKeyHelper": "~/.claude/api-key-helper.sh",
      "env": {
        "ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
        "ANTHROPIC_MODEL": "claude-opus-5-5"
      }
    }
  • Click "Add". Because the API Key is empty, a "Save anyway?" prompt appears — click "Save anyway"; then click "Enable" on the card.

Verify the config file written by cc-switch (key points: the base URL does not contain /v1, apiKeyHelper is present, and there is no ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN):

cat ~/.claude/settings.json
3-B. Configure MYAI168 (Method B: manual, fallback)

If you do not use cc-switch, create settings.json directly from the terminal (paste the whole block and press Enter). The four ANTHROPIC_DEFAULT_*_MODEL lines map Claude Code's built-in Opus / Sonnet / Haiku / Fable aliases to model IDs this site supports, so background tasks (such as generating conversation titles) do not fail on an unsupported model ID:

cat > ~/.claude/settings.json << 'EOF'
{
  "apiKeyHelper": "~/.claude/api-key-helper.sh",
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
    "ANTHROPIC_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "claude-fable-5-1"
  }
}
EOF

Important: once you use apiKeyHelper, do NOT also export ANTHROPIC_API_KEY, otherwise Claude Code shows an Auth conflict warning. If ~/.zshrc has old Claude Code functions / exports, remove them.

(Reminder again: the base URL ends with .../anthropic, without /v1.)

4. Launch and Verify

(Optional) Before launching, confirm that the endpoint and key work. This request bypasses Claude Code, so a failure tells you whether the problem is the key / endpoint or the Claude Code configuration (a successful call costs a tiny number of credits):

curl -sS https://www.myai168.com/en/api/anthropic/v1/messages \
  -H "x-api-key: $(~/.claude/api-key-helper.sh)" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-haiku-4-5","max_tokens":16,"messages":[{"role":"user","content":"Hi"}]}'

A response that starts with {"id":"msg_ and has a "content" field means everything works; 401 means the key is wrong, and for 404 check the URL (the test URL includes /v1/messages, while the base URL in the Claude Code settings does not include /v1).

Open a "brand-new" terminal window (to avoid leftover environment variables interfering) and just type:

claude

(Do not pass any environment variables; apiKeyHelper provides the key automatically.)

First-run screens: color theme → pick one; Security notes → Enter; Terminal setup → 1. Yes; Trust this folder? → 1. Yes. You should go straight to the "Welcome back" main screen, without a login menu.

Verify: type /status and confirm the base URL is MYAI168 and the Model is claude-opus-5-5. Then ask a question; getting a reply means success (the bottom-left corner shows Opus 5.5 · API Usage Billing, meaning API-key billing rather than an official subscription).

5. Quick Troubleshooting

"Model does not exist / It may not exist or you may not have access"

Most common cause: /v1 was appended to the base_url. Change it to .../anthropic (without /v1). Then run /status to confirm the endpoint and the model ID (it must be an ID this site accepts, such as claude-opus-5-5).

Not logged in / Please run /login

The apiKeyHelper is missing, or the helper does not output the key. Confirm the script exists, is executable (chmod +x), and settings.json has the apiKeyHelper field. The login menu only accepts official accounts — do not use it; skip it via apiKeyHelper.

Auth conflict warning

Both apiKeyHelper and ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) are set. Remove those variables from the env block of settings.json, from the cc-switch Config JSON and from your shell profile, so the key lives only in the apiKeyHelper script.

400 / Server-side/hosted tools ... are not supported via this relay

The request carried a tool that runs on Anthropic's servers; apart from web search, this site's endpoint does not support such tools. The usual cause is the advisor feature: turn it off, or add "CLAUDE_CODE_DISABLE_ADVISOR_TOOL": "1" to the env block of settings.json. Also run claude update to get the latest version (from 2.1.276, Claude Code no longer attaches the advisor on custom endpoints unless you turn it on).

401 / developer key is wrong

Wrong key. Check that the key inside the helper script is correct and has no extra spaces.

401 / API key credit limit reached!

This key has reached its credit limit. Raise the limit on the Developer API Key page, or use another key.

Chat works, but background tasks (such as title generation) report a model error

Claude Code runs background tasks with built-in aliases such as Haiku. Add the four lines ANTHROPIC_DEFAULT_OPUS_MODEL / ANTHROPIC_DEFAULT_SONNET_MODEL / ANTHROPIC_DEFAULT_HAIKU_MODEL / ANTHROPIC_DEFAULT_FABLE_MODEL to the env block of settings.json as shown in "3-B"; with cc-switch, set all four aliases in Model Mapping to a model ID this site supports.

Replies fail with 404 / not found

(Only when you have confirmed /v1 was not added and you still get 404) try changing the base URL to .../anthropic/v1 and test again; normally keep it without /v1.

claude command not found (new terminal)

Run source ~/.zshrc or reopen the terminal; if it is still missing, add ~/.local/bin to PATH as described in "1. Install", then run claude doctor to check the installation.

Switch / confirm the model

Use /model to switch during a conversation; use /status to confirm the endpoint and model.

6. Maintenance and Security

Update: the native-installer version updates itself in the background; to update right away, run:

claude update

for the Homebrew version use brew upgrade claude-code; for the npm version use npm install -g @anthropic-ai/claude-code@latest (avoid npm update -g — it respects the semver range from the original install and may not move you to the newest release). If something looks wrong with the installation or settings, run claude doctor.

Change the API Key (after a leak or for regular rotation)

  1. Delete the old key on the Developer API Key page and create a new one.
  2. macOS: edit the string after echo in ~/.claude/api-key-helper.sh.
  3. If you use cc-switch, editing the key script is all you need (the cc-switch card does not store the key); no need to enable it again.

Config File Locations (macOS)

  • ~/.claude/settings.json: endpoint and apiKeyHelper settings.
  • ~/.claude/api-key-helper.sh: the script that provides the key.

Official Docs

  • https://code.claude.com/docs/en/authentication
  • https://code.claude.com/docs/en/setup
  • https://code.claude.com/docs/en/llm-gateway-connect
Advanced settings and useful commands

Everything below is optional. Put environment variables in the env block of ~/.claude/settings.json (next to ANTHROPIC_BASE_URL; values are always strings). If you manage Claude Code with cc-switch, put them in the card's Config JSON instead, otherwise switching providers overwrites them.

Run once without opening a conversation

With -p, Claude Code prints the result and exits, which suits scripts and scheduled jobs:

claude -p "Check this project for unused functions"
claude -p "List the TODOs in this project" --output-format json
claude -p "Summarise the recent changes" --model sonnet --effort low --max-turns 5
claude -p "Add installation steps to the README" --permission-mode acceptEdits
  • --output-format json prints one JSON object: the reply text is in result and is_error tells whether the run failed. total_cost_usd is Claude Code's own estimate, not the credits this site deducts; check the Developer Keys page for real usage.
  • --model picks the model (an alias — opus, sonnet, haiku, fable — or a full model ID); --effort sets the effort level; --max-turns limits the number of turns so a run cannot go on too long.
  • Nobody can click "approve" in this mode, so actions that need permission (editing files, running commands) are denied by default. Pre-approve what you need with --permission-mode acceptEdits (auto-approve file edits) or --allowedTools "Read,Edit".
  • claude -c continues the most recent conversation in the current folder; claude -r lets you pick one from a list.

Switch the model and the effort level

Type /model in a conversation to open the model picker; the Opus / Sonnet / Haiku / Fable aliases resolve to this site's model IDs through the ANTHROPIC_DEFAULT_*_MODEL variables set in step 3-B. You can also name a model directly, for example /model claude-sonnet-5-5. /effort adjusts the effort level (low / medium / high / xhigh / max; the available levels depend on the model) — higher effort gives more careful answers at the cost of more output and usage.

List every Claude model of this site in the model picker

Add the line below to the env block and Claude Code queries this site's model list at startup (GET https://www.myai168.com/en/api/anthropic/v1/models, free of charge) and adds the Claude models it returns to the /model picker:

"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"

The query waits at most 3 seconds; on a timeout or failure the previously fetched list is reused and conversations are not affected.

Models for background tasks and subagents

Small background tasks such as generating conversation titles use the model set in ANTHROPIC_DEFAULT_HAIKU_MODEL (step 3-B sets it to claude-haiku-4-5). Subagents inherit the main model by default; to run them on a cheaper model, add this to the env block:

"CLAUDE_CODE_SUBAGENT_MODEL": "claude-haiku-4-5"

Useful environment variables

VariableDescription
API_TIMEOUT_MSTimeout of one request in milliseconds; the default is 600000 (10 minutes).
CLAUDE_CODE_MAX_OUTPUT_TOKENSMaximum output tokens of one reply. A lower value caps the usage of a single reply, but too low a value truncates long answers.
CLAUDE_CODE_EFFORT_LEVELPins the effort level (low / medium / high / xhigh / max, or auto for the model default); it takes precedence over --effort and /effort.
CLAUDE_CODE_SUBAGENT_MODELModel for subagents that are not assigned a model another way; accepts an alias such as haiku or a full model ID.
CLAUDE_CODE_API_KEY_HELPER_TTL_MSHow long the apiKeyHelper output is cached, in milliseconds; the default is 5 minutes, and 900000 means 15 minutes.
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICSet to 1 to turn off traffic unrelated to model calls, such as version checks and telemetry. It also disables auto-updates, so update manually afterwards.
DISABLE_TELEMETRYSet to 1 to turn off telemetry only.
CLAUDE_CODE_DISABLE_ADVISOR_TOOLSet to 1 to disable the advisor feature, which this endpoint does not support.

Example (add the lines inside the existing env block and keep the commas between lines):

"env": {
  "ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
  "ANTHROPIC_MODEL": "claude-opus-5-5",
  "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1",
  "CLAUDE_CODE_SUBAGENT_MODEL": "claude-haiku-4-5",
  "API_TIMEOUT_MS": "600000"
}

Permission modes

Press Shift+Tab in a conversation to cycle through the modes: the default mode (asks before every action) → acceptEdits (auto-approves file edits) → plan (plans only, changes nothing). You can also start in a mode, for example claude --permission-mode plan; /permissions manages individual allow and deny rules.

With a custom endpoint, Claude Code may print a notice at startup that begins with We're changing auto mode to no longer charge for classifier requests. It only says that auto mode's classifier requests keep counting toward usage; nothing breaks and you can ignore it.

Project guide and settings levels

  • CLAUDE.md: a guide in the project root that holds the project conventions, common commands and caveats; Claude Code reads it every time. Run /init in the project folder to generate it and /memory to edit it.
  • ~/.claude/settings.json: your personal settings for every project. The endpoint and key settings of this guide live here.
  • .claude/settings.json inside a project: committed and shared with the team. Never put a key in this file.
  • .claude/settings.local.json inside a project: applies only to you and only in this project, and is not committed.

Useful slash commands

CommandPurpose
/statusShows the version, endpoint, current model and credential source.
/modelSwitches the model (use the left/right arrows to adjust the effort level).
/effortAdjusts the effort level.
/usageShows usage statistics of the session (/cost is an alias). The amount shown is Claude Code's own estimate, not the credits this site actually deducts.
/contextShows how much of the context window is in use.
/compactSummarises the conversation so far to free up context.
/clearStarts a new conversation with empty context.
/resumeResumes an earlier conversation.
/permissionsManages the allow and deny rules for tools.
/initCreates a CLAUDE.md guide for the project.
/mcpShows and manages MCP server connections.

Connect MYAI168 MCP

To let Claude Code use this site's AI modules as tools, see the "Claude Code" section of the MYAI168 MCP CLI page.

‹ Previous page: Hermes Agent LinuxNext page: Claude Code CLI Windows ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • API Quick Start
  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • OpenRouter API
  • API Pricing

CLI & Agent Guides

  • cc-switch macOS
  • cc-switch Windows
  • cc-switch Linux
  • OpenCode macOS
  • OpenCode Windows
  • OpenCode Linux
  • OpenClaw macOS
  • OpenClaw Windows
  • OpenClaw Linux
  • Hermes Agent macOS
  • Hermes Agent Windows
  • Hermes Agent Linux
  • Claude Code CLI Windows
  • Claude Code CLI Linux
  • Codex CLI macOS
  • Codex CLI Windows
  • Codex CLI Linux

MYAI168 API & MCP

  • MYAI168 Chat API Guide
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App

User Guides

  • GT Agent Guide
  • AI Services Guide