Home›Developer Center›Claude Code CLI macOS

Claude Code CLI macOS

API DocumentationOpenAI 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 MCP CLIMYAI168 MCP Web & App
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 4.8.

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-4-8

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, revoke and replace it in the MYAI168 console.

Prerequisite

Node.js 22 or later (required by the official npm package as of v2.1.198; on older Node the install prints an EBADENGINE warning).

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 via npm:

npm install -g @anthropic-ai/claude-code

After installing, make the command available and confirm:

source ~/.zshrc
claude --version

(If it is still command not found, it is usually because PATH has not taken effect — reopen a terminal window and try again.)

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
3. Configure MYAI168 (Method A: cc-switch, recommended)

cc-switch is a cross-platform GUI; the macOS interface is the same as on Windows. (For installation, see the "cc-switch macOS" page in the Developer Center.)

  • Open cc-switch and click the "Claude Code" tab at the top.
  • Click "+" to add, and choose Custom Configuration.
  • Basic fields:
    • Provider Name: myai168-claude
    • API Key: your key
    • API Endpoint: https://www.myai168.com/en/api/anthropic (without /v1)
  • Expand Advanced Options:
    • API Format: Anthropic Messages (Native)
    • Auth Field: ANTHROPIC_API_KEY (do not choose AUTH_TOKEN)
  • Model Mapping: set the Requested model for Sonnet / Opus / Fable / Haiku all to claude-opus-4-8; set the Default fallback model to claude-opus-4-8 as well.
  • Config JSON area: make sure it contains apiKeyHelper (pointing to the script from "2. Create the apiKeyHelper"). cc-switch may not add apiKeyHelper by default; this guide's setup supplies the key via apiKeyHelper, so if the Config JSON does not have it, fix it manually to:
    {
      "apiKeyHelper": "/Users/your-account/.claude/api-key-helper.sh",
      "env": {
        "ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
        "ANTHROPIC_MODEL": "claude-opus-4-8"
      }
    }
  • Click Save → Enable it on the card.

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

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 (replace annie91 in the path with your macOS username, which you can find with whoami; paste the whole block and press Enter):

cat > ~/.claude/settings.json << 'EOF'
{
  "apiKeyHelper": "/Users/annie91/.claude/api-key-helper.sh",
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
    "ANTHROPIC_MODEL": "claude-opus-4-8"
  }
}
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

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-4-8. Then ask a question; getting a reply means success (the bottom-left corner shows Opus 4.8 · 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). Second cause (Windows): a leftover .claude.json.backup interferes → delete it (Remove-Item -Force "$env:USERPROFILE\.claude.json.backup").

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 on macOS), 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 are set. Remove ANTHROPIC_API_KEY from env / your shell.

401 / developer key is wrong

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

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)

macOS: source ~/.zshrc or reopen the terminal. Windows: open a new PowerShell so PATH takes effect.

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 official docs say to use install @latest and to avoid npm update -g — it respects the semver range from the original install and may not move you to the newest release):

npm install -g @anthropic-ai/claude-code@latest

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

  1. Revoke the old key and create a new one in the MYAI168 console.
  2. macOS: edit the string after echo in ~/.claude/api-key-helper.sh.
  3. If you use cc-switch, also update the API Key on the card and 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://docs.claude.com/en/docs/claude-code/overview
‹ Previous page: Hermes Agent LinuxNext page: Claude Code CLI Windows ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • 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 MCP CLI
  • MYAI168 MCP Web & App