yanchang
yanchang
发布于 2026-07-09 / 2 阅读
0
0

Codex cli以及Claude cli使用方法

Codex Cli

1、安装 Node.js(已安装可跳过)

确保 Node.js 版本 ≥ 18.0

# Ubuntu / Debian 用户
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -
sudo apt-get install -y nodejs
node --version

# macOS 用户
sudo xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install node
node --version

2、安装 codex cli

npm i -g @openai/codex
codex --version

3、开始使用

  • 获取 Auth Token:获得Key(以 sk- 开头)

  • 创建 ~/.codex/config.toml 文件,并添加如下配置:

model = "gpt-5-codex"
model_provider = "anyrouter"
preferred_auth_method = "apikey"


[model_providers.anyrouter]
name = "Any Router"
base_url = "https://anyrouter.top/v1"
wire_api = "responses"
  • 创建 ~/.codex/auth.json 文件,并添加如下配置:

{
  "OPENAI_API_KEY":"这里换成你申请的 KEY"
}



上述配置文件的路径 ~/.codex 也可以用 CODEX_HOME 环境变量指定

在您的项目目录下运行:

cd your-project-folder
codex

Claude Code Cli

1️⃣ 安装 Node.js(已安装可跳过)

确保 Node.js 版本 ≥ 18.0

# Ubuntu / Debian 用户
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -
sudo apt-get install -y nodejs
node --version

# macOS 用户
sudo xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install node
node --version



2️⃣ 安装 Claude Code

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



3️⃣ 开始使用

  • 获取 Auth Token: ANTHROPIC_AUTH_TOKEN :注册后在 API令牌 页面点击 添加令牌 获得(以 sk- 开头)

    • 名称随意,额度建议设为无限额度,其他保持默认设置即可


  • API地址: ANTHROPIC_BASE_URLhttps://anyrouter.top 是本站的 API 服务地址,与主站地址相同


在您的项目目录下运行:

cd your-project-folder
export ANTHROPIC_AUTH_TOKEN=sk-... 
export ANTHROPIC_BASE_URL=https://anyrouter.top
claude


运行后

  • 选择你喜欢的主题 + Enter

  • 确认安全须知 + Enter

  • 使用默认 Terminal 配置 + Enter

  • 信任工作目录 + Enter


开始在终端里和你的 AI 编程搭档一起写代码吧!🚀


4️⃣ 配置环境变量(推荐)

为避免每次重复输入,可将环境变量写入 bash_profile 和 bashrc:

echo -e '\n export ANTHROPIC_AUTH_TOKEN=sk-...' >> ~/.bash_profile
echo -e '\n export ANTHROPIC_BASE_URL=https://anyrouter.top' >> ~/.bash_profile
echo -e '\n export ANTHROPIC_AUTH_TOKEN=sk-...' >> ~/.bashrc
echo -e '\n export ANTHROPIC_BASE_URL=https://anyrouter.top' >> ~/.bashrc
echo -e '\n export ANTHROPIC_AUTH_TOKEN=sk-...' >> ~/.zshrc
echo -e '\n export ANTHROPIC_BASE_URL=https://anyrouter.top' >> ~/.zshrc


重启终端后,直接使用:

cd your-project-folder
claude


即可使用 Claude Code


评论