Run Grok with Claude Code in two ways:
| Mode | What | Harness | Entry |
|---|---|---|---|
| B (recommended) | Grok is the model; Claude Code is the agent | Claude Code | harness-proxy.mjs + claude-with-grok.sh |
| A | Claude Code delegates to Grok Build CLI | Grok Build (nested) | server.mjs (MCP) |
Mode B is a thin local proxy in front of xAI’s native Anthropic-compatible POST /v1/messages API (tools + streaming). It does not start the Grok Build CLI harness.
- xAI expects
Authorization: Bearer; Claude Code’sANTHROPIC_API_KEYis sent asx-api-key - xAI tool JSON Schema requires
requiredto be an array ([]if empty); Claude often omits it - Auth can reuse
~/.grok/auth.jsonfromgrok login(orXAI_API_KEY)
- Node.js 18+
- Claude Code CLI (
claude) - Grok auth:
grok loginorexport XAI_API_KEY=...
git clone https://github.com/Dremig/grok2cc.git
cd grok2cc
npm install # only needed for Mode A (MCP); Mode B is zero-deps
# Interactive Claude Code, model = Grok
./claude-with-grok.sh
# Headless
./claude-with-grok.sh -p "hello" --dangerously-skip-permissions
# Coding model
GROK_HARNESS_DEFAULT_MODEL=grok-build-0.1 ./claude-with-grok.shThe launcher starts harness-proxy.mjs on 127.0.0.1:8790 if it is not already up.
Manual proxy:
node harness-proxy.mjs
# or: npm run proxyHealth: curl http://127.0.0.1:8790/health
Yes — same Mode B path works. Use the installer:
git clone https://github.com/Dremig/grok2cc.git
cd grok2cc
./install-vscode.sh
# optional model:
# MODEL=grok-build-0.1 ./install-vscode.shWhat it does:
- Patches VS Code / Cursor / Insiders
settings.json(claudeCode.environmentVariables+disableLoginPrompt) - Patches
~/.claude/settings.json(gateway env; backs up previous file) - Approves the dummy key
grok-harnessin~/.claude.json - Starts
harness-proxy.mjsand installs a macOS LaunchAgent so it survives reboot
Then: Developer: Reload Window → open Claude Code panel.
./install-vscode.sh --uninstall # restore latest backups, stop LaunchAgent
./install-vscode.sh --no-launchd # config only; no LaunchAgentManual JSON (if you prefer): vscode-settings.example.json.
Notes:
- Real auth:
grok login(~/.grok/auth.json) orXAI_API_KEY - Extension gateway vars: LLM gateway connect
- Still Claude Code harness; only the model is Grok
- Plain text reply via Claude Code → Grok
- Full tool loop (e.g. Bash) inside Claude Code harness with model
grok-4.5
| Variable | Meaning |
|---|---|
GROK_HARNESS_PORT |
Proxy port (default 8790) |
GROK_HARNESS_HOST |
Bind host (default 127.0.0.1) |
GROK_HARNESS_DEFAULT_MODEL |
Default model (default grok-4.5) |
GROK_HARNESS_UPSTREAM |
Upstream base (default https://api.x.ai) |
GROK_AUTH_JSON |
Path to Grok auth file |
XAI_API_KEY / GROK_HARNESS_TOKEN |
Override token instead of auth.json |
GROK_HARNESS_LOG=1 |
Log each proxied request (LaunchAgent already sets this) |
| Path | What |
|---|---|
~/Library/Logs/grok2cc/harness-proxy.err.log |
Request log: method, path, status, latency, 4xx error body |
/tmp/grok2cc-last-request.json |
Last rewritten body sent upstream |
/tmp/grok2cc-last-raw-request.json |
Last raw Claude request (on 4xx) |
/tmp/grok2cc-last-error.json |
Last upstream error body (on 4xx) |
tail -f ~/Library/Logs/grok2cc/harness-proxy.err.log
curl -s http://127.0.0.1:8790/healthKnown Claude Code + Grok quirks (handled by proxy):
stop/stop_sequences— auto-mode Bash safety classifier sends these; xAI rejects → Claude may say “model temporarily unavailable”- invalid roles (
system/toolinmessages) — normalized - tool JSON Schema
requiredmust be an array
Exposes grok_delegate / grok_ask / grok_review by wrapping grok -p.
npm install
claude mcp add --scope user grok \
--env GROK_BIN="$HOME/.grok/bin/grok" \
-- node "$(pwd)/server.mjs"
claude mcp list # should show grok ✓ ConnectedOptional reverse direction (Grok Build → Claude tools):
# ~/.grok/config.toml
[mcp_servers.claude-code]
command = "claude"
args = ["mcp", "serve"]
enabled = trueSet [compat.claude] mcps = false on the Grok side if Claude’s user config also registers this MCP (avoids recursion).
| Tool | Purpose |
|---|---|
grok_delegate |
Agentic coding (--always-approve) |
grok_ask |
Consult / second opinion (plan mode) |
grok_review |
Code review focus |
| Variable | Meaning |
|---|---|
GROK_BIN |
Path to grok |
GROK_DEFAULT_MODEL |
Default -m |
GROK_DEFAULT_CWD |
Default working directory |
GROK_TIMEOUT_MS |
Subprocess timeout (default 600000) |
grok2cc/
harness-proxy.mjs # Mode B: Anthropic→xAI local proxy
claude-with-grok.sh # Mode B: launch Claude Code through the proxy
server.mjs # Mode A: MCP server wrapping grok CLI
scripts/probe.mjs # list MCP tools
MIT