I ran Claude Code on Grok 4.5 — here's the 3-line setup
I ran Claude Code on Grok 4.5 — here’s the 3-line setup
我在 Grok 4.5 上运行了 Claude Code —— 只需 3 行配置
I’ve basically lived inside Claude Code for the last few months. Opus 4.8 is my daily driver and I’m not looking to leave it. But when xAI dropped Grok 4.5 on July 8, two things nagged at me enough that I wanted it in the exact same terminal I already had open. This is the write-up of that afternoon — what pulled me in, the three lines that actually did the job, and where I landed on Grok vs Opus after living with both for a week. 过去几个月,我基本上一直生活在 Claude Code 中。Opus 4.8 是我的主力模型,我暂时没有更换的打算。但当 xAI 在 7 月 8 日发布 Grok 4.5 时,有两件事让我非常在意,以至于我想在当前打开的终端里直接使用它。这篇文章记录了那个下午的经历——是什么吸引了我,实现这一目标的 3 行代码,以及在同时使用两者一周后,我对 Grok 和 Opus 的最终评价。
Why I even bothered
我为什么折腾这个?
Two reasons, and neither of them is “it’s the smartest model in the world,” because it isn’t. 有两个原因,但都不是因为“它是世界上最聪明的模型”,因为它确实不是。
One: it’s built for coding. Grok 4.5 is the first xAI model explicitly aimed at coding and agentic work — xAI says it was trained on real developer sessions from Cursor, so the pitch is “long stretches of work inside an actual repo,” which is exactly what Claude Code does all day. 第一:它是为编程而生的。Grok 4.5 是 xAI 首个明确针对编程和智能体(Agentic)工作设计的模型。xAI 表示它是在 Cursor 的真实开发者会话数据上训练的,因此其卖点在于“在实际代码库中进行长时间的工作”,这正是 Claude Code 全天候在做的事情。
Two: the token efficiency number stuck with me. In the third-party write-ups going around, Grok 4.5 finished the same agentic indexing task in roughly 14k output tokens where a frontier flagship burned closer to 67k. When you run an agent that loops and re-reads files for twenty minutes, output tokens are the bill. A model that says the same thing in a quarter of the tokens is interesting even before you look at the per-token rate. Official rate, for the record: xAI lists Grok 4.5 at $2 / $6 per million input/output, and claims it comes in 60%+ under the current flagship tier. Fewer tokens and a lower rate stacks. That was enough to make me curious. 第二:它的 Token 效率数字让我印象深刻。在流传的第三方测评中,Grok 4.5 完成同样的智能体索引任务仅需约 1.4 万个输出 Token,而顶级旗舰模型则消耗了近 6.7 万个。当你运行一个循环并反复读取文件长达 20 分钟的智能体时,输出 Token 就是你的账单。一个能用四分之一的 Token 量表达同样内容的模型,即便不看单价也已经足够吸引人。顺便提一下官方定价:xAI 将 Grok 4.5 定价为每百万输入/输出 Token 2 美元/6 美元,并声称比目前的旗舰级模型便宜 60% 以上。更少的 Token 加上更低的费率,优势叠加。这足以让我产生好奇心。
The thing I kept forgetting
我一直忽略的一点
Here’s the part that took me embarrassingly long to internalize: Claude Code doesn’t actually care what model is on the other end. It’s a CLI that speaks Anthropic’s /v1/messages protocol to whatever ANTHROPIC_BASE_URL points at. If something answers in that shape, Claude Code will happily drive it.
这是让我感到尴尬且花了很长时间才领悟的一点:Claude Code 其实并不关心后端连接的是什么模型。它只是一个 CLI 工具,通过 Anthropic 的 /v1/messages 协议与 ANTHROPIC_BASE_URL 指向的任何地址通信。只要对方能以该格式响应,Claude Code 就能愉快地驱动它。
So I didn’t need a Grok-specific client. I needed an endpoint that (a) speaks Anthropic-native and (b) has grok-4.5 sitting behind it. I already had an account on byesu, an API gateway that exposes both an OpenAI-compatible and an Anthropic-native endpoint over a pile of models — pay-as-you-go, and Grok 4.5 was already listed. That’s the whole trick: the gateway translates, Claude Code never knows the difference. 所以我不需要专门的 Grok 客户端。我只需要一个 (a) 支持 Anthropic 原生协议,且 (b) 后端接入了 Grok 4.5 的端点。我已经在 byesu 上有一个账户,这是一个 API 网关,它为多种模型提供了兼容 OpenAI 和 Anthropic 原生的端点,采用按量付费模式,且已经列出了 Grok 4.5。这就是全部诀窍:网关负责转换,而 Claude Code 根本察觉不到区别。
The three lines
那 3 行代码
That’s it. Literally three environment variables: 就是这样。实际上只需要三个环境变量:
export ANTHROPIC_BASE_URL=https://byesu.com
export ANTHROPIC_API_KEY=sk-your-own-key
export ANTHROPIC_MODEL=grok-4.5
Then, in any project directory: claude
然后在任何项目目录下运行:claude
ANTHROPIC_MODEL=grok-4.5 is the line doing the interesting work — it pins every request to Grok instead of the default Claude model, so you don’t have to remember to switch each session. If you’d rather flip between models mid-session, drop that third line and use /model inside the REPL instead.
ANTHROPIC_MODEL=grok-4.5 这一行是关键——它将所有请求固定为 Grok 而不是默认的 Claude 模型,这样你就不用在每次会话时手动切换。如果你更喜欢在会话中切换模型,可以去掉第三行,改在 REPL 中使用 /model 命令。
Two gotchas so you skip my afternoon
两个避坑指南,让你少走弯路
-
No /v1 on the base URL. The Anthropic-native endpoint is the bare root —
https://byesu.com, nothttps://byesu.com/v1. I pasted in a/v1out of muscle memory from OpenAI-style setups and got a wall of connection errors. Strip it. -
基础 URL 不要加
/v1。 Anthropic 原生端点是根目录——即https://byesu.com,而不是https://byesu.com/v1。我因为习惯了 OpenAI 风格的配置,肌肉记忆地加上了/v1,结果收到了一堆连接错误。去掉它。 -
If auth won’t take, swap the key variable. On one machine my first call kept bouncing on auth. The fix was replacing
ANTHROPIC_API_KEYwithANTHROPIC_AUTH_TOKEN(same value) — some Claude Code versions prefer one over the other. Thirty seconds once you know; a genuinely confusing ten minutes if you don’t. -
如果认证失败,尝试更换 Key 变量名。 在一台机器上,我的首次调用一直认证失败。解决方法是将
ANTHROPIC_API_KEY替换为ANTHROPIC_AUTH_TOKEN(值相同)——某些版本的 Claude Code 对这两个变量的偏好不同。知道这一点只需 30 秒,但不知道的话会让你困惑十分钟。
Sanity check before you trust it: run claude, ask it something trivial, and confirm the model line in the status bar reads grok-4.5. If it still says a Claude model, your ANTHROPIC_MODEL export didn’t make it into that shell — re-source it or reopen the terminal.
信任前先做个检查: 运行 claude,问它一个简单的问题,确认状态栏中的模型名称显示为 grok-4.5。如果显示的仍然是 Claude 模型,说明你的 ANTHROPIC_MODEL 环境变量没有生效——请重新加载配置文件或重启终端。
The one-line vibe check
简短的体验总结
It’s fast, and it’s terse in a way I ended up liking. Grok 4.5 doesn’t pad. It reads the files, makes the edit, and moves on with noticeably less “let me explain my reasoning at length” preamble — which, combined with the token-efficiency thing, means the agent loop just feels tighter. For mechanical work — wiring up a route, refactoring a module, chasing a stack trace across a few files — it kept pace with what I’d normally reach for. 它很快,而且简洁的风格让我很喜欢。Grok 4.5 不会废话。它读取文件、进行修改,然后继续工作,明显减少了“让我详细解释一下我的推理过程”这类前言——结合其 Token 效率,整个智能体循环感觉更加紧凑。对于机械性工作——比如配置路由、重构模块、在几个文件中追踪堆栈跟踪——它的表现与我通常使用的模型不相上下。
Where I actually landed: Grok vs Opus 4.8
我的最终结论:Grok 与 Opus 4.8
I’m not going to tell you Grok 4.5 replaces Opus 4.8, because after a week it clearly doesn’t — for me they split by task, not by “better/worse.” Opus 4.8 is still where I go for the gnarly stuff: ambiguous architecture calls, “read this whole subsystem and tell me what’s actually wrong,” the reasoning-heavy work where I want the model to sit and think. It’s the frontier flagship and it feels like it. 我不会说 Grok 4.5 取代了 Opus 4.8,因为经过一周的使用,显然并没有——对我来说,它们是按任务分工的,而不是简单的“好坏”之分。Opus 4.8 仍然是我处理棘手问题的首选:模糊的架构决策、“阅读整个子系统并告诉我哪里出了问题”、以及需要深度推理、我希望模型能静下心来思考的工作。它确实是顶级旗舰,用起来感觉也确实如此。
Grok 4.5 is where I go for volume. The high-frequency, well-specified, mechanical passes where I know roughly what needs to happen and I just want it done in fewer tokens and fewer words. On independent coding benchmarks it lands in the same neighborhood as the top-tier models at a fraction of the per-task cost, and Artificial Analysis had it at #4 on their intelligence index at launch — which is a lot of “good enough” for the kind of work that eats most of my day. Grok 4.5 是我处理大量任务时的选择。那些高频、需求明确、机械性的任务,我知道大概要做什么,只想用更少的 Token 和更少的字数完成。在独立的编程基准测试中,它的表现与顶级模型处于同一梯队,但任务成本却低得多。Artificial Analysis 在其发布时将其排在智能指数第 4 位——对于占据我大部分工作时间的任务来说,这已经足够“好”了。
So it’s complementary, not a swap. The nice part of the gateway setup is I don’t have to commit: same three env vars, change the model line (or /model), and I’m on whichever one fits the task. Opus for the thinking, Grok for the grinding.
所以它们是互补的,而不是替代关系。这种网关设置的好处是我不需要做死选择:同样的三个环境变量,改一下模型名称(或使用 /model),我就能切换到适合当前任务的模型。Opus 负责思考,Grok 负责搬砖。
If you want the reference version of the setup — supported models, endpoints, the OpenAI-compatible side — it’s documented over at docs.byesu.com. But honestly, the three lines above are the whole story. Export, claude, go. 如果你需要参考配置——包括支持的模型、端点、OpenAI 兼容侧的说明——可以在 docs.byesu.com 查看文档。但老实说,上面那三行代码就是全部了。导出变量,运行 claude,开工。