Running Claude Code natively on Databricks using Claude Code Router
brew install nvmAdd the following to your shell profile (~/.zshrc or ~/.bash_profile):
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/share/nvm/nvm.sh" ] && \. "/opt/homebrew/share/nvm/nvm.sh"
[ -s "/opt/homebrew/share/nvm/bash_completion" ] && \. "/opt/homebrew/share/nvm/bash_completion"Reload your shell:
source ~/.zshrc # or source ~/.bash_profilenpm install -g @anthropic-ai/claude-codeTo update Claude Code to the latest version:
npm update -g @anthropic-ai/claude-codenpm install -g @musistudio/claude-code-routerClaude Code Router is an open-source project available on GitHub under the MIT license: https://github.com/musistudio/claude-code-router
OpenCode is an alternative interface for Claude Code that provides a VSCode-like experience:
npm install -g opencode-ai@latestOpenCode is an open-source project available on GitHub under the MIT license: https://github.com/sst/opencode
After installation, copy the OpenCode configuration file to the appropriate directory:
mkdir -p ~/.config/opencode
cp opencode/opencode.jsonc ~/.config/opencode/opencode.jsoncNote: Template configuration files are available in the opencode/ folder of this repository.
- Create the plugins directory for Claude Code Router:
mkdir -p ~/.claude-code-router/plugins- Copy the transformer script to the plugins directory:
cp databricks-claude-transformers.js ~/.claude-code-router/plugins/- Copy the configuration file to the Claude Code Router directory:
cp claude_code/config.json ~/.claude-code-router/config.jsonNote: Template configuration files are available in the claude_code/ folder of this repository.
- Edit the configuration file and fill in your Databricks details:
nano ~/.claude-code-router/config.jsonReplace the following placeholders:
<username>: Your system username<workspace-url>: Your Databricks workspace URL<databricks-api-key>: Your Databricks API key
You can also configure debugging options in this file:
LOG: Set totrueto enable loggingLOG_LEVEL: Set todebugfor detailed logstransformers[].options.debug: Set totruefor transformer-specific debugging
You can configure both Claude Code Router and OpenCode to use different Anthropic models provided by Databricks:
Edit the claude_code/config.json file to update the model name and router default:
{
// Other configuration...
"Providers": [
{
"name": "databricks",
"models": [
"databricks-claude-sonnet-4" // Change to your desired model
],
// Other provider settings...
}
],
"Router": {
"default": "databricks,databricks-claude-sonnet-4" // Update both parts
}
}Edit the opencode/opencode.jsonc file to update the model name:
{
// Other configuration...
"provider": {
"anthropic": {
// Other settings...
"models": {
"databricks-claude-3-7-sonnet": { // Change key and name to your desired model
"name": "databricks-claude-3-7-sonnet" // e.g., databricks-claude-opus or databricks-claude-sonnet-4
}
}
}
}
}Common Databricks model names include:
databricks-claude-sonnet-4databricks-claude-3-7-sonnetdatabricks-claude-opus
Ensure that your Databricks serving endpoint is configured with the corresponding model.
The databricks-claude-transformers.js script is a custom transformer that adapts Claude Code requests to work with Databricks serving endpoints. It handles:
- Request format conversion between Claude and Databricks
- Proper handling of image URLs in multimodal requests
- Logging for debugging purposes
The transformer performs several important modifications to ensure compatibility between Claude Code and Databricks serving endpoints:
-
URL Construction: Uses the provider's API base URL to target the correct Databricks serving endpoint
-
Message Content Handling:
- Converts empty string content to
nullfor tool calls compatibility - Processes message arrays to ensure proper formatting
- Removes
cache_controlproperties from messages
- Converts empty string content to
-
Image URL Processing: Transforms image URLs to ensure proper base64 encoding format for multimodal requests
-
Request Cleanup: Removes unnecessary properties like
parallel_tool_callsthat might cause issues with the Databricks API
These transformations ensure that Claude Code requests are properly formatted for the Databricks serving endpoint, allowing seamless integration between the two systems.
This transformer is referenced in the config.json file under the transformers section:
"transformers": [
{
"path": "/Users/<username>/.claude-code-router/plugins/databricks-claude-transformers.js"
}
]To enable debugging for Claude Code Router:
- When copying the configuration file, set the debug options:
cp config.json ~/.claude-code-router/config.json- Edit the configuration file to enable logging:
nano ~/.claude-code-router/config.json- Update the following settings:
{
"LOG": true,
"LOG_LEVEL": "debug",
...
"transformers": [
{
"path": "/Users/<username>/.claude-code-router/plugins/databricks-claude-transformers.js",
"options": {
"debug": true
}
}
],
...
"Router": {
"default": "databricks,databricks-claude-sonnet-4"
}
}Logs will be displayed in the terminal where you run the Claude Code Router. For transformer-specific logs, they will appear in the same terminal output when the transformer script is executed during API calls.
After configuration, you can use Claude Code CLI with your Databricks setup through the router:
ccr codeTo use OpenCode with Claude Code Router:
- Start Claude Code Router in one terminal:
ccr start- In a separate terminal, start OpenCode:
opencode- Once OpenCode is running, use the
/modelscommand in the OpenCode interface and select the appropriatedatabricks-*model from the list.
This setup allows you to use the VSCode-like OpenCode interface while routing requests through Claude Code Router to your Databricks serving endpoint.
This project is licensed under the MIT License - see the LICENSE file for details.
Databricks serving endpoints have default rate limits that may affect your usage of Claude Code. These limits include:
- Requests per minute (RPM) limits
- Maximum concurrent requests
- Maximum tokens per request
If you encounter rate limit errors or need higher throughput for your Claude Code usage, please contact your Databricks account team to discuss increasing these limits. They can help adjust your serving endpoint configuration based on your specific needs and usage patterns.
Typical rate limit errors will appear as HTTP 429 responses or may be indicated in the Claude Code Router logs when debugging is enabled.