Add xAI Grok as a new API provider. Reuses OpenAI-compatible message/tool
converters and stream adapter with Grok-specific client and model mapping.
Default model mapping:
opus → grok-4.20-reasoning
sonnet → grok-3-mini-fast
haiku → grok-3-mini-fast
Users can customize mapping via:
- GROK_MODEL env var (override all)
- GROK_MODEL_MAP env var (JSON family map, e.g. {"opus":"grok-4"})
- GROK_DEFAULT_{FAMILY}_MODEL env vars
Activation: CLAUDE_CODE_USE_GROK=1 or modelType: "grok" in settings.json
Also integrates with /provider command for runtime switching.
Two fixes for OpenAI-compatible provider compatibility:
1. Sanitize JSON Schema `const` → `enum` in tool parameters.
Many OpenAI-compatible endpoints (Ollama, DeepSeek, vLLM, etc.)
do not support the `const` keyword in JSON Schema. Recursively
convert `const: value` to `enum: [value]` which is semantically
equivalent.
2. Force stop_reason to `tool_use` when tool_calls are present.
Some backends incorrectly return finish_reason "stop" even when
the response contains tool_calls. Without this fix, the query
loop treats the response as a normal end_turn and never executes
the requested tools.