Wire up GPT & GLM in minutes. 几分钟接入 GPT & GLM。
Connect OpenCode, Codex, and Claude Code to Hachimi Cloud through one OpenAI-compatible endpoint — then cut your token bill. 通过一个 OpenAI 兼容端点,将 OpenCode、Codex 和 Claude Code 接入 Hachimi Cloud,再顺手省下 token 开销。
01Available Models可用模型
GPT — OpenAI models.GPT — OpenAI 模型。
| Model | Context上下文 | Output输出 |
|---|---|---|
gpt-5.4-mini GPT-5.4-Mini | 400K | 128K |
gpt-5.6-luna GPT-5.6-Luna | 400K | 128K |
gpt-5.6-terra GPT-5.6-Terra | 400K | 128K |
gpt-5.6-sol GPT-5.6-Sol | 400K | 128K |
Context limits vary by model. All GPT models pass store: false to prevent API-side conversation storage.上下文上限因模型而异。所有 GPT 模型均设置 store: false 以阻止 API 端存储对话。
Claude — Anthropic models.Claude — Anthropic 模型。
| Model | Context上下文 | Output输出 |
|---|---|---|
claude-haiku-4-5 Anthropic | 200K | 64K |
claude-sonnet-5 Anthropic | 1M | 128K |
claude-opus-4-8 Anthropic | 1M | 128K |
claude-fable-5 Anthropic | 1M | 128K |
02Connect to Hachimi Cloud接入 Hachimi Cloud
Recommended: Use CC Switch — a cross-platform desktop app that configures OpenCode, Codex, and Claude Code in one click.推荐方式:使用 CC Switch —— 跨平台桌面工具,一键配置 OpenCode、Codex 和 Claude Code。
- Base URL:
https://api.hachimi.cloud/v1 - API Key: your Hachimi Cloud key你的 Hachimi Cloud 密钥
- Base URL:
https://api.hachimi.cloud - API Key: your Hachimi Cloud key你的 Hachimi Cloud 密钥
Links:链接: ccswitch.io · GitHub
Manual Configuration手动配置
Config file:配置文件: ~/.config/opencode/opencode.json
{
"provider": {
"hachimi-cloud": {
"options": {
"baseURL": "https://api.hachimi.cloud/v1",
"apiKey": "sk-your-api-key-here",
"store": false
},
"models": {
"gpt-5.4-mini": {
"name": "GPT-5.4-Mini",
"limit": { "context": 400000, "output": 128000 },
"variants": {
"low": { "reasoningEffort": "low" },
"medium": { "reasoningEffort": "medium" },
"high": { "reasoningEffort": "high" },
"xhigh": { "reasoningEffort": "xhigh" }
}
},
"gpt-5.6-luna": {
"name": "GPT-5.6-Luna",
"limit": { "context": 400000, "output": 128000 },
"variants": {
"low": { "reasoningEffort": "low" },
"medium": { "reasoningEffort": "medium" },
"high": { "reasoningEffort": "high" },
"xhigh": { "reasoningEffort": "xhigh" },
"max": { "reasoningEffort": "max" }
}
},
"gpt-5.6-terra": {
"name": "GPT-5.6-Terra",
"limit": { "context": 400000, "output": 128000 },
"variants": {
"low": { "reasoningEffort": "low" },
"medium": { "reasoningEffort": "medium" },
"high": { "reasoningEffort": "high" },
"xhigh": { "reasoningEffort": "xhigh" },
"max": { "reasoningEffort": "max" }
}
},
"gpt-5.6-sol": {
"name": "GPT-5.6-Sol",
"limit": { "context": 400000, "output": 128000 },
"variants": {
"low": { "reasoningEffort": "low" },
"medium": { "reasoningEffort": "medium" },
"high": { "reasoningEffort": "high" },
"xhigh": { "reasoningEffort": "xhigh" },
"max": { "reasoningEffort": "max" }
}
}
}
}
},
"plugin": [
"@tarquinen/opencode-dcp@latest"
]
}
To use GPT as the default model:将 GPT 设为默认模型:
{
"model": "hachimi-cloud/gpt-5.6-terra",
"small_model": "hachimi-cloud/gpt-5.4-mini"
}
Run opencode and use /model to switch.运行 opencode,使用 /model 命令切换模型。
Config file:配置文件: ~/.codex/config.toml
model_provider = "hachimi"
model = "gpt-5.6-terra"
model_reasoning_effort = "high"
[model_providers.hachimi]
name = "hachimi"
base_url = "https://api.hachimi.cloud/v1"
wire_api = "responses"
requires_openai_auth = true
experimental_bearer_token = "sk-your-api-key-here"
[features]
image_generation = false
[features] image_generation = false to avoid 403 Forbidden: Image generation is not enabled for this group. Sub2API bug: Codex CLI auto-injects image_generation tool into every request. See #3196.
⚠️ 必需 — 添加 [features] image_generation = false 以避免 403 Forbidden: Image generation is not enabled for this group 错误。Sub2API 已知 Bug:Codex CLI 会在每个请求中自动注入 image_generation 工具。详见 #3196。
After saving, restart Codex CLI. The model name at the top should reflect your config.保存后重启 Codex CLI,顶部的模型名应显示为你的配置。
Config file:配置文件: ~/.claude/settings.json (global)
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-your-claude-api-key",
"ANTHROPIC_BASE_URL": "https://api.hachimi.cloud",
"ANTHROPIC_MODEL": "claude-opus-4-8"
}
}
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-your-api-key-here",
"ANTHROPIC_BASE_URL": "https://api.hachimi.cloud",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5.4-mini",
"ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME": "GPT-5.4-Mini",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "gpt-5.5",
"ANTHROPIC_DEFAULT_OPUS_MODEL_NAME": "GPT-5.5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
"ANTHROPIC_DEFAULT_SONNET_MODEL_NAME": "GPT-5.4",
"ANTHROPIC_MODEL": "gpt-5.5"
}
}
403 Forbidden: Image generation is not enabled for this group when using GPT models via Sub2API, this is a known Sub2API bug. Codex CLI auto-injects image_generation tool, and Sub2API may incorrectly charge plain text requests as image generation. See #3196.
⚠️ 注意 — 如果你在通过 Sub2API 使用 GPT 模型时遇到 403 Forbidden: Image generation is not enabled for this group 错误,这是 Sub2API 的已知 Bug。Codex CLI 会自动注入 image_generation 工具,且 Sub2API 可能会错误地将纯文本请求按图片计费。详见 #3196。
Run /status in Claude Code to verify the active route.在 Claude Code 中运行 /status 验证当前路由。
03Save Tokens省 Token 技巧
Big context windows are convenient, but every turn re-sends the whole conversation. These three habits keep your context lean and your bill low.大上下文很方便,但每一轮都会重发整段对话。下面三个习惯能让上下文保持精简、账单更低。
Compact at the right moment把握 Compact 时机
- Compact proactively as you near the context limit — don't wait for auto-compact to truncate mid-task and lose the thread.
- 主动在接近上下文上限前 compact —— 别等自动 compact 在关键处截断、丢失思路。
- Before compacting, have the model pin the key conclusions (current goal, confirmed facts, next step), then compress. Compaction is lossy.
- compact 前先让模型固化关键结论(当前目标、已确认事实、下一步),再压缩。压缩是有损的。
- Work in phases: when one sub-task is done and the next is unrelated, compact to drop now-irrelevant tool output.
- 分阶段推进:一个子任务完成、下一个无关时就 compact,丢掉已无关的工具输出。
- Both Claude Code and OpenCode expose
/compact; trigger it yourself rather than relying on the automatic threshold. - Claude Code 与 OpenCode 都提供
/compact;主动触发,而不是依赖自动阈值。
DCP — Dynamic Context PruningDCP — 动态上下文裁剪
DCP is an OpenCode plugin that automatically shrinks context — replacing stale content with placeholders before each request, without ever modifying your session history. It compresses closed spans into technical summaries, deduplicates repeated tool calls, and purges errored tool inputs.DCP 是一个 OpenCode 插件,在每次请求前用占位符替换陈旧内容来自动压缩上下文,且从不改写你的会话历史。它把已结束的片段压缩成技术摘要、去重重复的工具调用、清理报错工具的输入。
opencode plugin @tarquinen/opencode-dcp@latest --global
Config lives in ~/.config/opencode/dcp.jsonc (global) or .opencode/dcp.jsonc (project). Set compress.maxContextLimit / minContextLimit as a percentage of the model's context window so the thresholds auto-scale:配置位于 ~/.config/opencode/dcp.jsonc(全局)或 .opencode/dcp.jsonc(项目级)。把 compress.maxContextLimit / minContextLimit 设为模型上下文窗口的百分比,阈值即可按模型自动缩放:
{
"enabled": true,
"compress": {
"mode": "range",
"maxContextLimit": "70%",
"minContextLimit": "30%"
}
}
Handy slash commands:常用斜杠命令:
/dcp context— token breakdown for the current session + how much was saved当前会话的 token 明细 + 已节省量/dcp compress [focus]— trigger one compression pass手动触发一次压缩/dcp sweep [n]— prune tool calls since the last user message裁剪自上条用户消息以来的工具调用/dcp manual [on|off]— toggle autonomous context management开关自动上下文管理
Delegate exploration to a subagent把探索交给子代理
Read-only codebase exploration is the biggest token sink in the main thread. Hand searching and file-reading to a cheaper explore subagent, and let the main agent read only the files it will actually edit. The exploration tokens stay in the subagent's context, not yours.只读的代码库探索是主线程里最大的 token 消耗。把检索和读文件交给更便宜的探索子代理,主代理只读真正要改的文件。探索产生的 token 留在子代理的上下文里,而不进入你的主上下文。
| Tool | Explore subagent探索子代理 |
|---|---|
| OpenCode | @explore |
| Codex | explorer |
| Claude Code | explore |
When to delegate: finding a symbol's usages across many files, mapping a subsystem, locating the owner file for unfamiliar behavior, or gathering root-cause evidence — anything where you only need the conclusion, not the raw file dumps.何时委派:跨多文件查找符号用法、梳理子系统、定位陌生行为的归属文件、收集根因证据 —— 凡是你只需要结论、不需要原始文件内容的场景。
Make it automatic — write the delegation policy into your rules file so the main agent always offloads exploration: Claude Code reads ~/.claude/CLAUDE.md (or per-agent .claude/agents/*.md), while OpenCode and Codex read AGENTS.md. Spell out when to delegate and demand locator-only output (path · symbol · line range · one-line reason) so the subagent never dumps whole files back.让它自动发生 — 把「委派探索」的规则写进你的规则文件,主代理就会始终把探索外包出去:Claude Code 读取 ~/.claude/CLAUDE.md(或单个 .claude/agents/*.md),OpenCode 与 Codex 读取 AGENTS.md。在规则里写清何时委派、并要求只返回定位信息(路径 · 符号 · 行号范围 · 一句话理由),子代理就不会把整段文件回灌给你。
Pin a cheaper model — all three let you set the subagent's model explicitly. Point the explorer at a small, cheap model while the main agent keeps a stronger one — exploration runs cost a fraction:指定更便宜的模型 — 三家都支持显式设置子代理的模型。让探索子代理用小而便宜的模型,主代理仍用更强的模型 —— 探索的开销可以低一个量级:
.claude/agents/explore.md
---
name: explore
description: Read-only codebase exploration (locator mode)
tools: Read, Grep, Glob
model: haiku
---
Return only: file path, symbol, line range, one-line reason.
~/.config/opencode/opencode.json
{
"agent": {
"explore": {
"mode": "subagent",
"model": "hachimi-cloud/glm-5.2"
}
}
}
Or run exploration for free with one of OpenCode Zen's built-in free models (rotating — e.g. opencode/glm-5.2-free, opencode/deepseek-v4-flash-free) so your explore agent costs nothing:或者用 OpenCode Zen 自带的免费模型来跑探索(会轮换 —— 如 opencode/glm-5.2-free、opencode/deepseek-v4-flash-free),让探索子代理零成本:
{
"agent": {
"explore": {
"mode": "subagent",
"model": "opencode/deepseek-v4-flash-free"
}
}
}
.codex/agents/explorer.toml
name = "explorer"
description = "Read-only codebase explorer for gathering evidence."
model = "glm-5.2"
model_reasoning_effort = "low"
sandbox_mode = "read-only"
developer_instructions = """
Stay in exploration mode. Cite files and symbols; don't propose fixes.
"""