npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

apixcode

v1.1.0

Published

One-command setup to proxy Claude Code, Codex, and Gemini CLI as API endpoints (Windows/macOS/Linux)

Readme

apixcode

将 Claude Code CLI / Codex CLI / Gemini CLI 转换为标准 API 端点的本地代理服务。

需求背景

问题

  1. Claude Code CLI - 只能通过命令行交互,无法被其他应用(如 n8n、自定义程序)调用
  2. Codex CLI - 同上,只支持命令行模式
  3. Gemini CLI - 使用 Google OAuth 网页登录鉴权,无法直接获取 API Key

解决方案

apixcode 在本地启动一个 HTTP 代理服务,将标准 API 请求转换为 CLI 调用:

客户端 (n8n/程序) → HTTP API 请求 → apixcode 代理 → CLI 命令 → AI 响应

支持的 API 格式

| CLI 工具 | API 端点 | API 格式 | 模型名称 | |---------|---------|---------|---------| | Claude Code | /v1/messages | Anthropic | claude-* | | Codex | /v1/chat/completions | OpenAI | codex, gpt-* | | Gemini | /v1/chat/completions | OpenAI | gemini-* |

安装

前置条件

至少安装以下 CLI 工具之一:

# Claude Code CLI
npm i -g @anthropic-ai/claude-code

# Codex CLI
npm i -g @openai/codex

# Gemini CLI
npm i -g @google/gemini-cli

Python 要求:

  • Linux/macOS: python3
  • Windows: python (Python 3.x)

安装 apixcode

npm i -g apixcode

平台支持

| 平台 | 状态 | 服务管理 | |------|------|---------| | Linux | ✓ 完全支持 | systemd 服务 | | macOS | ✓ 完全支持 | 后台进程 | | Windows | ✓ 完全支持 | 后台进程 (可配合任务计划程序) |

使用

启动配置向导

apixcode

交互式菜单:

  • 安装 - 检测 CLI、配置端口、生成代理脚本、启动服务
  • 启动/停止 - 控制代理服务
  • 切换模式 - 本地 (127.0.0.1) / 远程 (0.0.0.0)
  • 修改端口 - 更改监听端口(默认 18080)

访问模式

| 模式 | 绑定地址 | 用途 | |-----|---------|-----| | 仅本地 | 127.0.0.1 | 只能本机访问 | | 本地+远程 | 0.0.0.0 | 允许外部设备访问 |

API 使用示例

Anthropic API (Claude)

curl -X POST http://127.0.0.1:18080/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk-placeholder" \
  -d '{
    "model": "claude-opus-4-5-20251101",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

OpenAI API (Codex/Gemini)

# Codex
curl -X POST http://127.0.0.1:18080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-placeholder" \
  -d '{
    "model": "codex",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

# Gemini (模型名包含 "gemini" 自动路由)
curl -X POST http://127.0.0.1:18080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-placeholder" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

实际应用案例

Clawdbot (Discord AI 机器人)

Clawdbot 是一个 Discord AI 机器人网关,通过 apixcode 暴露的本地 API 端点调用 Claude:

Discord 用户消息 → Clawdbot → apixcode API (127.0.0.1:18080) → Claude CLI → AI 响应 → Discord

服务器实际配置 (~/.clawdbot/clawdbot.json):

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "anthropic/claude-opus-4-5-20251101"
      },
      "workspace": "/home/ubuntu/clawd"
    }
  },
  "plugins": {
    "entries": {
      "discord": {
        "enabled": true
      }
    }
  },
  "channels": {
    "discord": {
      "enabled": true,
      "token": "YOUR_DISCORD_BOT_TOKEN"
    }
  },
  "models": {
    "providers": {
      "anthropic": {
        "baseUrl": "http://127.0.0.1:18080"
      }
    }
  }
}

关键配置

  • models.providers.anthropic.baseUrl 指向 apixcode 代理地址
  • Clawdbot 无需真实的 Anthropic API Key,直接使用本地 Claude CLI 的订阅额度
  • 支持 Discord 群组中 @ 机器人进行对话

相关服务

# Clawdbot 服务
sudo systemctl status clawdbot.service

# apixcode 代理服务
sudo systemctl status codecli-hostapi.service

在 n8n 中使用

Claude (Anthropic 节点)

  1. 添加 Anthropic 节点
  2. 凭证配置:
    • API Key: 任意值(如 sk-placeholder
    • Base URL: http://你的IP:18080

Codex / Gemini (OpenAI 节点)

  1. 添加 OpenAI 节点
  2. 凭证配置:
    • API Key: 任意值(如 sk-placeholder
    • Base URL: http://你的IP:18080/v1
  3. 模型设置:
    • Codex: codexgpt-4o
    • Gemini: gemini-2.5-progemini-2.5-flash

⚠️ 注意: n8n 的 "Google Gemini" 原生节点无法使用,因为它期望 Google 原生 API 格式。请使用 OpenAI 节点。

实现原理

架构

┌─────────────────────────────────────────────────────────┐
│                    apixcode 代理                         │
│                                                         │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐ │
│  │ /v1/messages│    │/v1/chat/    │    │/v1/chat/    │ │
│  │ (Anthropic) │    │completions  │    │completions  │ │
│  └──────┬──────┘    │(model:gpt-*)│    │(model:      │ │
│         │           └──────┬──────┘    │gemini-*)    │ │
│         │                  │           └──────┬──────┘ │
│         ▼                  ▼                  ▼        │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐ │
│  │ Claude CLI  │    │  Codex CLI  │    │ Gemini CLI  │ │
│  │ --print     │    │ --full-auto │    │ -p -o text  │ │
│  │ --output-   │    │ --quiet     │    │ --yolo      │ │
│  │ format text │    │             │    │             │ │
│  └─────────────┘    └─────────────┘    └─────────────┘ │
└─────────────────────────────────────────────────────────┘

路由逻辑

# 端点路由
if path == "/v1/messages":
    # Anthropic API → Claude CLI
    run_claude(prompt)

elif path == "/v1/chat/completions":
    # OpenAI API → 根据模型名路由
    if "gemini" in model.lower():
        run_gemini(prompt)
    else:
        run_codex(prompt)

CLI 调用方式

| CLI | 命令 | 说明 | |-----|-----|-----| | Claude | claude --print --output-format text --permission-mode bypassPermissions <prompt> | 非交互模式,绕过权限确认 | | Codex | codex --full-auto --quiet <prompt> | 全自动模式,静默输出 | | Gemini | gemini -p <prompt> -o text --yolo | 非交互模式,自动批准操作 |

文件结构

Linux/macOS:

~/.local/share/codecli-hostapi/
├── proxy.py          # 代理脚本(自动生成)
└── backups/          # 配置备份

~/.config/codecli-hostapi/
└── config.json       # 配置文件

/etc/systemd/system/
└── codecli-hostapi.service  # systemd 服务(仅 Linux)

Windows:

%LOCALAPPDATA%\codecli-hostapi\
├── proxy.py          # 代理脚本(自动生成)
├── config\
│   └── config.json   # 配置文件
└── backups\          # 配置备份

配置文件

~/.config/codecli-hostapi/config.json:

{
  "installed": true,
  "installedAt": "2026-01-30T11:00:00.000Z",
  "proxyHost": "0.0.0.0",
  "proxyPort": 18080,
  "claudePath": "/home/ubuntu/.npm-global/bin/claude",
  "codexPath": "/home/ubuntu/.npm-global/bin/codex",
  "geminiPath": "/home/ubuntu/.npm-global/bin/gemini"
}

服务管理

Linux (systemd)

# 查看状态
sudo systemctl status codecli-hostapi.service

# 启动/停止/重启
sudo systemctl start codecli-hostapi.service
sudo systemctl stop codecli-hostapi.service
sudo systemctl restart codecli-hostapi.service

# 查看日志
sudo journalctl -u codecli-hostapi.service -f

macOS / Windows

使用 apixcode 命令的交互式菜单进行启动/停止管理。

Windows 开机自启(可选):

  1. 打开任务计划程序 (taskschd.msc)
  2. 创建基本任务
  3. 触发器:计算机启动时
  4. 操作:启动程序
    • 程序:python
    • 参数:%LOCALAPPDATA%\codecli-hostapi\proxy.py

常见问题

1. 端口被占用

Linux/macOS:

# 查看占用进程
sudo lsof -i :18080

# 杀掉进程
sudo kill -9 <PID>

Windows (PowerShell/CMD):

# 查看占用进程
netstat -ano | findstr :18080

# 杀掉进程 (PID 为上一步输出的最后一列)
taskkill /PID <PID> /F

2. CLI 命令找不到

代理使用完整路径调用 CLI。如果 CLI 安装位置变化,需要重新运行 apixcode 选择"安装"。

3. Gemini 无响应

确保 Gemini CLI 已完成 Google OAuth 登录:

gemini  # 首次运行会打开浏览器登录

4. 旧代理服务冲突

如果之前安装过其他代理服务(如 anthropic-proxy.service),需要先禁用:

sudo systemctl stop anthropic-proxy.service
sudo systemctl disable anthropic-proxy.service

License

MIT