Skip to content

Instantly share code, notes, and snippets.

@mjrdnk
Created May 4, 2026 11:16
Show Gist options
  • Select an option

  • Save mjrdnk/701815e9e3a0da34f99d7e50c49d8586 to your computer and use it in GitHub Desktop.

Select an option

Save mjrdnk/701815e9e3a0da34f99d7e50c49d8586 to your computer and use it in GitHub Desktop.
claude-omlx
#!/usr/bin/env bash
# claude-omlx — run Claude Code as a UI for a local omlx server.
#
# Builds on the env-var profile from https://github.com/vitorallo/claude-code-local
# (the 15 problems it documents), but keeps omlx as the backend instead of
# vllm-mlx (omlx is forked from vllm-mlx, adds paged-SSD KV cache, and is
# actively maintained for Claude Code).
#
# Token lives in macOS Keychain — service "claude-omlx", account "omlx":
# security add-generic-password -s claude-omlx -a omlx -w '<token>' -U
#
# Override at call time:
# OMLX_BASE_URL=http://127.0.0.1:8001 OMLX_MODEL=other claude-omlx
set -euo pipefail
# Drop any real Anthropic creds inherited from the parent shell so they
# cannot leak to the local server.
unset ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN || true
if [[ -z "${OMLX_TOKEN:-}" ]]; then
if ! OMLX_TOKEN="$(security find-generic-password -s claude-omlx -a omlx -w 2>/dev/null)"; then
echo "claude-omlx: token not in Keychain (service=claude-omlx, account=omlx)." >&2
echo " add it with: security add-generic-password -s claude-omlx -a omlx -w '<token>' -U" >&2
exit 1
fi
fi
# Defaults to http://127.0.0.1:8000
OMLX_BASE_URL="${OMLX_BASE_URL:-http://127.0.0.1:8000}"
OMLX_MODEL="${OMLX_MODEL:-Qwen3.6-35B-A3B-6bit}"
# Anthropic SDK routing. Set AUTH_TOKEN only — also setting API_KEY triggers
# Claude Code's "Auth conflict" warning and can shadow the token at runtime.
export ANTHROPIC_BASE_URL="$OMLX_BASE_URL"
export ANTHROPIC_AUTH_TOKEN="$OMLX_TOKEN"
# Route every Claude Code model tier at the local model. Without these,
# Claude Code calls claude-opus-*, claude-sonnet-*, claude-haiku-* by
# canonical name — your local server 404s on those and the UI falls back
# to displaying "Sonnet".
export ANTHROPIC_MODEL="$OMLX_MODEL"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$OMLX_MODEL"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$OMLX_MODEL"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$OMLX_MODEL"
export CLAUDE_CODE_SUBAGENT_MODEL="$OMLX_MODEL"
# Disable cloud-only behaviors that hang or break against a local server.
export CLAUDE_CODE_ATTRIBUTION_HEADER=0 # otherwise KV cache invalidates per request
export DISABLE_PROMPT_CACHING=1
export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
export DISABLE_AUTOUPDATER=1
export DISABLE_TELEMETRY=1
export DISABLE_ERROR_REPORTING=1
# Empty MCP config so plugins don't flood the local model with hundreds of
# tool defs (a 35B-A3B MoE with 3B active params collapses into bad tool
# calling under that load, regardless of quant).
MCP_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/claude-omlx"
MCP_CONFIG_FILE="$MCP_CONFIG_DIR/mcp-local.json"
mkdir -p "$MCP_CONFIG_DIR"
[[ -f "$MCP_CONFIG_FILE" ]] || printf '{"mcpServers":{}}\n' > "$MCP_CONFIG_FILE"
exec claude --strict-mcp-config --mcp-config "$MCP_CONFIG_FILE" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment