Claude Code CLI

Installation Overview (macOS)

Claude Code CLI Installation and Custom API Setup Guide — macOS

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

Key point

Claude Code only speaks the Anthropic Messages protocol, so any provider with an Anthropic-compatible endpoint can be connected directly — no proxy needed. MYAI168 has a native Anthropic endpoint, which is a perfect fit.

The key trick

Claude Code's interactive mode has one limitation —— without a pre-existing login record, it still forces the login screen even if you set the API key via an environment variable. This guide therefore uses the official apiKeyHelper mechanism to bypass login, which is the most stable and reliable approach.

Before you begin: prerequisites and security notes

Prerequisites: Node.js and API Key

  • Claude Code is installed via npm and needs Node.js (18+ recommended; if you already installed Node 24 following another guide, you are fine).
  • Have your MYAI168 API Key ready, along with the native Anthropic endpoint URL:
Endpoint   https://www.myai168.com/en/api/anthropic
Model      claude-opus-4-8

Important security notes

  • Claude Code can read, edit, and execute files in its working directory. In practice, cd into a specific project folder before launching it; do not open it in your home directory (~), or it will have read/write/execute access to your entire home directory.
  • Treat your API Key like a password: never leak it or paste it in public places. If it is exposed, immediately revoke it in the MYAI168 console and issue a new one.
1. Install Claude Code

First check whether it is already installed:

claude --version

If you see a version number, skip to the next section. 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. Configure apiKeyHelper to connect to MYAI168

Make sure the settings folder exists:

mkdir -p ~/.claude

Step 1: create the small script that provides the key

Copy the whole block below, 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 the script outputs the key correctly:

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

It should print your key string, which means success.

Step 2: create settings.json to specify the helper and endpoint

Again, paste the whole block and press Enter (replace annie91 in the path with your macOS username, which you can find with whoami):

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: do not also set ANTHROPIC_API_KEY

Once you use apiKeyHelper, do NOT also export ANTHROPIC_API_KEY in ~/.zshrc or your shell, otherwise Claude Code will show an Auth conflict warning. If you previously added a function or export in .zshrc pointing to Claude Code, edit ~/.zshrc and remove them.

3. Launch and verify

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

claude

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

On first launch, a few screens appear in sequence — handle them as follows:

  • Choose color theme → pick what you like (for a dark background choose Dark mode), Enter.
  • Security notes → Enter to continue.
  • Terminal setup → choose 1. Yes, use recommended settings.
  • Trust this folder? → choose 1. Yes, I trust this folder.

On success, you go straight to the "Welcome back" main screen, without a login menu popping up.

Once on the main screen, verify:

/status

Confirm: no /login is requested, the Anthropic base URL is MYAI168, and the Model is claude-opus-4-8.

Then ask a question to test:

Hello, please tell me which model you are using

If it replies normally and reports the model as Claude Opus 4.8, the connection succeeded. The bottom-left of the main screen shows "Opus 4.8 · API Usage Billing"; "API Usage Billing" means it is using API-key billing (your MYAI168), not an official subscription.

4. Everyday use

Once set up, just type claude as usual and it goes through MYAI168 — no extra commands needed.

For actual development, enter the project folder before launching:

cd ~/your-project-folder
claude

To switch back to the official subscription: remove the apiKeyHelper line from ~/.claude/settings.json, then run /login again.

5. Troubleshooting quick reference

Keeps showing the login menu (Select login method)

Interactive mode needs apiKeyHelper to skip login. Make sure both files in section 2 were created correctly, and that you opened a brand-new terminal window. Press Esc to temporarily skip the menu.

401 / developer key is wrong

The key is wrong. Check whether the key inside api-key-helper.sh is the real key, with no extra spaces or placeholder text.

Not logged in / Please run /login (still appears even though the key is set)

The key was not read. Usually the helper script lacks execute permission (rerun chmod +x), or the path is wrong, or there is a leftover environment-variable conflict (try a new window).

Auth conflict warning

Both apiKeyHelper and ANTHROPIC_API_KEY are set. Remove the ANTHROPIC_API_KEY export from your shell.

Replies report 404 / not found

An endpoint-path issue. Change ANTHROPIC_BASE_URL in settings.json to .../anthropic/v1 (add /v1) and try again.

Switch models

Use /model in the conversation; or change ANTHROPIC_MODEL in settings.json.

Check the current auth method

Type /status inside Claude Code.

6. Maintenance and security

Update Claude Code:

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

Replace the API Key (when leaked or for periodic rotation)

  1. Revoke the old key in the MYAI168 console and generate a new one.
  2. Edit ~/.claude/api-key-helper.sh and replace the string after echo with the new key.
  3. If the same key is used in other tools, remember to update their config files too.

Config file locations

  • ~/.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

Other FAQ pages

  • FAQ
  • Account
  • Features
  • Privacy
  • OpenAI ChatGPT API
  • Anthropic Claude API
  • Google Gemini API
  • Google News API
  • OpenRouter API
  • API Pricing
  • OpenCode
  • OpenClaw
  • Hermes Agent
  • Codex CLI
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App