Nexus-CLI:支持 Claude Code 与 Ollama 的纯 Go 版 DeepSeek R1/V3 Web 桥接工具
英文标题:🔶 Nexus-CLI – Pure Go Bridge to DeepSeek R1/V3 with Claude Code and Ollama Support
Nexus-CLI 是一款纯 Go 语言构建的高性能命令行工具与本地 API 代理服务器,允许开发者通过免费网页账号接入 DeepSeek V3 与 R1 模型,无需官方付费 API Key。项目内置高效的并行 PoW 求解器,可在 40–50 毫秒内完成服务端验证,并提供了与 OpenAI、Anthropic 及 Ollama 完全兼容的 API 端点。此外,它支持多账号轮询避免速率限制,并能一键启动 Claude Code、Aider 等多种 AI 编码 Agent,为开发者低成本本地接入前沿大模型提供了极具实用价值的解决方案。
1.5 KB
29.9 KB
中文
Nexus-CLI(面向 Golang 的 DeepSeek Web 桥接工具)⚡
一款高性能 Golang 命令行工具及本地 API 代理服务器,支持任何应用程序或编程 Agent 通过免费 Web 账号(chat.deepseek.com)连接 DeepSeek V3(deepseek-chat)和 R1(deepseek-reasoner / 深度思考)模型,无需官方付费 DeepSeek API 密钥。
在深入分析 Node.js(FreeDeepseekAPI-EN)和 Python(deepseek_bridge)项目的基础上,采用纯 Go(Golang)从零重写,具备零运行时依赖特性。
- 纯 Go 并行工作量证明(PoW)求解器:
- 基于 CPU 多核并行运行
DeepSeekHashV1算法(Keccak-f[1600] 1..23 轮 SHA3-256)破解 DeepSeek 服务端验证。 - 仅需 约 40–50 毫秒 即可完成 144,000 难度的挑战(无需 CGO、WASM 或 Python 依赖)。
- 基于 CPU 多核并行运行
- 交互式终端聊天(REPL):
- 实时流式输出 R1 模型的思考过程(
reasoning_content),并配有专属样式(斜体/青色)。 - 精美的 ANSI UI 界面,具备彩色提示符和动态加载动效。
- 内置斜杠命令:
/help、/new、/model、/thinking、/search、/whoami、/clear、/exit。
- 实时流式输出 R1 模型的思考过程(
- 单次查询与 Unix 管道支持:
- 直接通过 CLI 提问:
nexus "什么是量子计算?" - 适配 Linux/macOS 管道工作流:
cat main.go | nexus "检查这段代码的安全性和性能问题"
- 直接通过 CLI 提问:
- 兼容 OpenAI、Anthropic 和 Ollama 的代理服务器(
nexus serve):POST /v1/chat/completions(OpenAI 格式,支持 SSE 流式和 JSON)POST /v1/messages(Anthropic Messages API —— 100% 兼容 Claude Code 及 Anthropic SDK!)POST /v1/responses(OpenAI Responses API)GET /v1/models与GET /v1/model-capabilitiesGET /v1/sessions与POST /v1/sessions/reset- 无缝连接 Open WebUI、Continue.dev、Cursor、Cline 以及任何其他 OpenAI/Anthropic 客户端。
- 原生 Ollama API 仿真 🦙:
- 模拟提供
GET /api/tags、POST /api/chat、POST /api/generate、GET /api/version。 - 即插即用,直接兼容 Open WebUI、Dify、AnythingLLM、Cursor、LlamaIndex 及官方 Ollama SDK。
- 模拟提供
- 结构化输出与 JSON Schema 🎯:
- 在 CLI、Ollama 和 OpenAI 端点中强制执行严格的 JSON 输出或根据 JSON Schema 进行校验。
- 通用集成启动器(Launcher)🚀:
- 一键启动 Claude Code、DeepSeek Harness、Codex、OpenCode、Goose 和 Aider(Nexus 会自动在后台拉起代理服务)。
- 多账号池 👥:
- 采用轮询(Round-Robin)调度策略轮换多个 DeepSeek 账号,彻底消除速率限制(HTTP 429)瓶颈。
- 认证管理(
nexus auth):- 手动登录:
nexus auth login(从浏览器 LocalStorage 中提取userToken) - 通过 Chrome 自动提取:
nexus auth chrome(通过 CDP 从浏览器内存中读取会话令牌) - 账号查看:
nexus auth whoami
- 手动登录:
- 系统诊断(Doctor):
*
nexus doctor—— 即时检查令牌有效性、服务端连通性、PoW 求解器性能以及会话创建状态。
环境要求:Go 1.20+:
# 克隆仓库并进入目录:
git clone https://github.com/xamrayev/nexus-cli.git
cd nexus-cli
# 编译生成可执行二进制文件:
go build -o bin/nexus .
# (可选)全局安装至系统 PATH:
go install .
🔑 认证(关联账号)
共有 3 种方式连接你的 DeepSeek 账号:
1. 交互式命令行提示:
系统会提示你输入 userToken:
- 在浏览器中打开
https://chat.deepseek.com。 - 按
F12(macOS 上按Cmd+Option+I)。 - 切换至
Application->Local Storage->https://chat.deepseek.com-> 复制userToken的值并粘贴到提示框中。
2. 通过 Chrome 自动提取(CDP):
该操作会自动打开一个 Chrome 窗口。登录完成后,Nexus 会安全捕获并存储会话令牌。
在项目根目录下创建一个 .env 文件:
DEEPSEEK_TOKEN=your_deepseek_token_here
1. 交互式聊天(REPL)
或者直接运行:
实时 R1 推理思维流:
nexus ❯ 为什么天空是蓝色的?
💭 Thinking Process:
用户正在询问天空呈现蓝色的物理成因……
需要解释阳光被大气分子产生的瑞利散射机制……
🤖 DeepSeek (deepseek-reasoner):
天空之所以呈现蓝色,主要归因于一种被称为瑞利散射(Rayleigh scattering)的物理现象……
./bin/nexus "提供有关广义相对论的 3 个关键事实"
3. 通过 Unix 管道进行代码分析
cat main.go | ./bin/nexus "分析这段代码的安全漏洞和性能瓶颈"
4. 运行本地 API 代理服务器
./bin/nexus serve --port 9655
现在你可以将任何工具(Cursor、Open WebUI、Claude Code)的端点指向 http://localhost:9655/v1!
以 OpenAI 格式发送的 cURL 请求示例:
curl http://localhost:9655/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "你好!"}],
"stream": true
}'
5. 原生 Ollama API 仿真 🦙
Nexus 实现了 Ollama API 规范。Open WebUI、Dify、AnythingLLM、Cursor、LlamaIndex 以及官方 Ollama 库可以直接连接到 http://localhost:9655:
# 1. 获取可用模型列表(Ollama 格式)
curl http://localhost:9655/api/tags
# 2. Ollama 对话请求(NDJSON 流式)
curl http://localhost:9655/api/chat -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "你好!"}],
"stream": true
}'
使用官方 Python Ollama SDK 示例:
import ollama
client = ollama.Client(host="http://localhost:9655")
resp = client.chat(model="deepseek-reasoner", messages=[
{"role": "user", "content": "用 Go 语言编写一个简单的 HTTP 服务器"}
])
print(resp["message"]["content"])
6. 结构化输出与 JSON Schema 🎯
强制模型输出严格的 JSON 或符合指定的 Schema 约束:
# 1. 直接在 CLI 中输出 JSON(可通过管道传给 jq 处理)
./bin/nexus "排名前三的编程语言及其主要应用领域" --format json | jq .
# 2. 通过 Ollama API:
curl http://localhost:9655/api/chat -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "以 JSON 列出 3 种水果"}],
"format": "json",
"stream": false
}'
# 3. 通过 OpenAI API(response_format 参数):
curl http://localhost:9655/v1/chat/completions -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "以 JSON 格式返回设备规格"}],
"response_format": {"type": "json_object"}
}'
7. 通用集成(启动器)🚀
一条命令即可启动常用编码工具与 Agent —— Nexus 会自动在后台启动代理服务器:
# 1. Claude Code CLI(由 DeepSeek R1 / V3 驱动)
./bin/nexus launch claude
./bin/nexus launch claude -p "重构这段 Go 代码"
# 2. 官方 DeepSeek Harness CLI(@deepseek-ai/dsh)
./bin/nexus launch dsh
# 3. OpenAI Codex CLI(自动配置 responses wire API)
./bin/nexus launch codex
# 4. OpenCode CLI(自动注入配置)
./bin/nexus launch opencode
# 5. Block Goose AI Agent(通过 OpenAI provider 连接)
./bin/nexus launch goose
# 6. Aider 结对编程 CLI(结合 DeepSeek R1)
./bin/nexus launch aider
# 7. ChatGPT Desktop (macOS) 与本地桥接
./bin/nexus launch chatgpt
# 8. 多账号池监控器
./bin/nexus launch pool
# 9. DeepSeek Agentic 评估与基准测试 Harness
./bin/nexus launch harness
通过轮询(Round-Robin)调度多个 DeepSeek 账号,避免速率限制(HTTP 429):
# 添加新账号
./bin/nexus auth add acc2 --chrome
# 列出账号并检查其状态
./bin/nexus auth list
# 切换当前活跃账号
./bin/nexus auth switch acc2
# 测试并验证账号池中的所有账号
./bin/nexus auth test
9. 系统诊断(Doctor)
nexus-cli/
├── bin/
│ └── nexus # 编译生成的可执行二进制文件
├── cmd/
│ └── nexus/main.go # CLI 命令分发器
├── pkg/
│ ├── deepseek/
│ │ ├── pow.go # 纯 Go 并行 DeepSeekHashV1 Keccak PoW 求解器
│ │ ├── pow_test.go # PoW 测试套件与性能基准测试
│ │ ├── stream.go # SSE JSON patch 及 OpenAI 流解析器
│ │ ├── stream_test.go # 流处理测试
│ │ ├── auth.go # 令牌、会话和个人信息管理器
│ │ ├── chrome_auth.go # 基于 Chrome CDP 的自动化身份认证
│ │ ├── client.go # DeepSeek Web API 客户端(Chat、会话、自动重试)
│ │ └── types.go # 模型配置与类型定义
│ ├── server/
│ │ ├── server.go # 本地 HTTP 代理服务器(路由、CORS、认证)
│ │ ├── server_test.go # 服务器端点单元测试
│ │ ├── openai.go # OpenAI Chat Completions API 适配器
│ │ ├── anthropic.go # Anthropic Messages API 适配器(适用于 Claude Code)
│ │ └── session.go # Agent 会话隔离与清理机制
│ ├── launcher/
│ │ └── launcher.go # Claude Code、Codex、Goose、Aider 等工具的启动器
│ └── cli/
│ ├── terminal.go # ANSI 样式、横幅和加载动效
│ ├── repl.go # 交互式终端聊天与斜杠命令
│ ├── runner.go # 单次 Prompt 与 Unix 管道运行器
│ └── doctor.go # 端到端系统诊断工具
├── main.go # 应用程序主入口
├── go.mod # Go 模块定义文件
├── README.md # 主说明文档(英文)
├── README.ru.md # 俄文说明文档(Русский)
└── README.uz.md # 乌兹别克文说明文档(O'zbekcha)
本项目基于 MIT 许可证开源。
English / 原文
Nexus-CLI (DeepSeek Web Bridge for Golang) ⚡
A high-performance Golang CLI utility and local API proxy server that enables any application or coding agent to connect to DeepSeek V3 (deepseek-chat) and R1 (deepseek-reasoner / Thinking) models via a free web account (chat.deepseek.com), without requiring an official paid DeepSeek API key.
Rewritten from scratch in pure Go (Golang) based on in-depth analysis of Node.js (FreeDeepseekAPI-EN) and Python (deepseek_bridge) projects, featuring zero runtime dependencies.
- Pure Go Parallel PoW (Proof-of-Work) Solver:
- Solves DeepSeek server challenges using the
DeepSeekHashV1algorithm (Keccak-f[1600] 1..23 rounds SHA3-256) parallelized across CPU cores. - Solves difficulty 144,000 challenges in just ~40–50 milliseconds (no CGO, WASM, or Python dependencies required).
- Solves DeepSeek server challenges using the
- Interactive Terminal Chat (REPL):
- Streams the R1 model's thought process (
reasoning_content) in real-time with dedicated styling (italic/cyan). - Polished ANSI UI with colorful prompts and animated loading spinners.
- Built-in slash commands:
/help,/new,/model,/thinking,/search,/whoami,/clear,/exit.
- Streams the R1 model's thought process (
- One-Off & Unix Pipe Support:
- Direct CLI queries:
nexus "What is quantum computing?" - Linux/macOS pipe workflows:
cat main.go | nexus "Review this code for security and performance"
- Direct CLI queries:
- OpenAI, Anthropic & Ollama Compatible Proxy Server (
nexus serve):POST /v1/chat/completions(OpenAI format, SSE streaming, and JSON)POST /v1/messages(Anthropic Messages API — 100% compatible with Claude Code and the Anthropic SDK!)POST /v1/responses(OpenAI Responses API)GET /v1/modelsandGET /v1/model-capabilitiesGET /v1/sessionsandPOST /v1/sessions/reset- Connects seamlessly with Open WebUI, Continue.dev, Cursor, Cline, and any other OpenAI/Anthropic client.
- Native Ollama API Emulation 🦙:
- Emulates
GET /api/tags,POST /api/chat,POST /api/generate,GET /api/version. - Direct plug-and-play compatibility with Open WebUI, Dify, AnythingLLM, Cursor, LlamaIndex, and official Ollama SDKs.
- Emulates
- Structured Outputs & JSON Schema 🎯:
- Enforce strict JSON output or validate against JSON Schemas across CLI, Ollama, and OpenAI endpoints.
- Universal Integrations (Launcher) 🚀:
- One-command launcher for Claude Code, DeepSeek Harness, Codex, OpenCode, Goose, and Aider (Nexus automatically boots the proxy in the background).
- Multi-Account Pool 👥:
- Rotate multiple DeepSeek accounts using Round-Robin scheduling to eliminate rate-limit roadblocks (HTTP 429).
- Authentication Management (
nexus auth):- Manual login:
nexus auth login(extractuserTokenfrom browser LocalStorage) - Automatic via Chrome:
nexus auth chrome(reads session token from browser memory via CDP) - Account inspection:
nexus auth whoami
- Manual login:
- System Diagnostics (Doctor):
*
nexus doctor— instantly checks token validity, server connectivity, PoW solver performance, and session creation.
Requires Go 1.20+:
# Clone repository and navigate to directory:
git clone https://github.com/xamrayev/nexus-cli.git
cd nexus-cli
# Build the executable binary:
go build -o bin/nexus .
# Install globally to system PATH (optional):
go install .
🔑 Authentication (Account Linking)
There are 3 ways to connect your DeepSeek account:
1. Interactive CLI prompt:
You will be prompted for your userToken:
- Open
https://chat.deepseek.comin your browser. - Press
F12(orCmd+Option+Ion macOS). - Navigate to
Application->Local Storage->https://chat.deepseek.com-> copy theuserTokenvalue and paste it into the prompt.
2. Automatic via Chrome (CDP):
This automatically launches a Chrome window. Once you log in, Nexus securely captures and stores the session token.
Create a .env file in the project root:
DEEPSEEK_TOKEN=your_deepseek_token_here
1. Interactive Chat (REPL)
Or simply:
Real-time R1 reasoning stream:
nexus ❯ Why is the sky blue?
💭 Thinking Process:
The user is asking about the physical cause behind the color of the sky...
Need to explain the mechanism of Rayleigh scattering of sunlight by atmospheric molecules...
🤖 DeepSeek (deepseek-reasoner):
The primary reason the sky appears blue is due to a phenomenon called Rayleigh scattering...
./bin/nexus "Provide 3 key facts about general relativity"
3. Code analysis via Unix Pipe
cat main.go | ./bin/nexus "Analyze this code for security vulnerabilities and performance bottlenecks"
4. Running the Local API Proxy Server
./bin/nexus serve --port 9655
You can now route any tool (Cursor, Open WebUI, Claude Code) to http://localhost:9655/v1!
Sample cURL request in OpenAI format:
curl http://localhost:9655/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'
5. Native Ollama API Emulation 🦙
Nexus implements the Ollama API specification. Open WebUI, Dify, AnythingLLM, Cursor, LlamaIndex, and official Ollama libraries can connect directly to http://localhost:9655:
# 1. Fetch available models (Ollama format)
curl http://localhost:9655/api/tags
# 2. Ollama Chat request (NDJSON streaming)
curl http://localhost:9655/api/chat -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'
Using the official Python Ollama SDK:
import ollama
client = ollama.Client(host="http://localhost:9655")
resp = client.chat(model="deepseek-reasoner", messages=[
{"role": "user", "content": "Write a simple HTTP server in Go"}
])
print(resp["message"]["content"])
6. Structured Outputs & JSON Schema 🎯
Enforce strict JSON output or conform to a specified schema:
# 1. Direct JSON from CLI (pipeable to jq)
./bin/nexus "Top 3 programming languages and their primary domains" --format json | jq .
# 2. Via Ollama API:
curl http://localhost:9655/api/chat -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "List 3 fruits in JSON"}],
"format": "json",
"stream": false
}'
# 3. Via OpenAI API (response_format):
curl http://localhost:9655/v1/chat/completions -d '{
"model": "deepseek-reasoner",
"messages": [{"role": "user", "content": "Return device specs as JSON"}],
"response_format": {"type": "json_object"}
}'
7. Universal Integrations (Launcher) 🚀
Launch coding tools and agents with a single command — Nexus automatically boots the proxy server in the background:
# 1. Claude Code CLI (powered by DeepSeek R1 / V3)
./bin/nexus launch claude
./bin/nexus launch claude -p "Refactor this Go code"
# 2. Official DeepSeek Harness CLI (@deepseek-ai/dsh)
./bin/nexus launch dsh
# 3. OpenAI Codex CLI (auto-configured with responses wire API)
./bin/nexus launch codex
# 4. OpenCode CLI (with automated config injection)
./bin/nexus launch opencode
# 5. Block Goose AI Agent (via OpenAI provider)
./bin/nexus launch goose
# 6. Aider Pair Programming CLI (with DeepSeek R1)
./bin/nexus launch aider
# 7. ChatGPT Desktop (macOS) & local bridge
./bin/nexus launch chatgpt
# 8. Multi-Account Pool Monitor
./bin/nexus launch pool
# 9. DeepSeek Agentic Eval & Benchmark Harness
./bin/nexus launch harness
Avoid rate limits (HTTP 429) by cycling through multiple DeepSeek accounts using Round-Robin rotation:
# Add a new account
./bin/nexus auth add acc2 --chrome
# List accounts and check their status
./bin/nexus auth list
# Switch active account
./bin/nexus auth switch acc2
# Validate all accounts in the pool
./bin/nexus auth test
9. System Diagnostics (Doctor)
nexus-cli/
├── bin/
│ └── nexus # Compiled binary executable
├── cmd/
│ └── nexus/main.go # CLI command dispatcher
├── pkg/
│ ├── deepseek/
│ │ ├── pow.go # Pure Go parallel DeepSeekHashV1 Keccak PoW solver
│ │ ├── pow_test.go # PoW test suite & benchmarks
│ │ ├── stream.go # SSE JSON patch & OpenAI stream parser
│ │ ├── stream_test.go # Stream tests
│ │ ├── auth.go # Token, session, and profile manager
│ │ ├── chrome_auth.go # Automated Chrome CDP authentication
│ │ ├── client.go # DeepSeek Web API client (Chat, Sessions, Auto-retry)
│ │ └── types.go # Model configs and type definitions
│ ├── server/
│ │ ├── server.go # Local HTTP proxy server (Routing, CORS, Auth)
│ │ ├── server_test.go # Server endpoint unit tests
│ │ ├── openai.go # OpenAI Chat Completions API adapter
│ │ ├── anthropic.go # Anthropic Messages API adapter (for Claude Code)
│ │ └── session.go # Agent session isolation and cleanup
│ ├── launcher/
│ │ └── launcher.go # Launchers for Claude Code, Codex, Goose, Aider, etc.
│ └── cli/
│ ├── terminal.go # ANSI styling, banners, and spinners
│ ├── repl.go # Interactive terminal chat & slash commands
│ ├── runner.go # Single-prompt and Unix pipe runner
│ └── doctor.go # End-to-end system diagnostics
├── main.go # Application entry point
├── go.mod # Go module definition
├── README.md # Main documentation (English)
├── README.ru.md # Russian documentation (Русский)
└── README.uz.md # Uzbek documentation (O'zbekcha)
Distributed under the MIT License.