|
| 1 | +--- |
| 2 | +title: Use Claude Code with Docker Model Runner |
| 3 | +description: Configure Claude Code to use Docker Model Runner so you can code with local models. |
| 4 | +summary: | |
| 5 | + Connect Claude Code to Docker Model Runner with the Anthropic-compatible API, |
| 6 | + package `gpt-oss` with a larger context window, and inspect requests. |
| 7 | +keywords: ai, claude code, docker model runner, anthropic, local models, coding assistant |
| 8 | +tags: [ai] |
| 9 | +params: |
| 10 | + time: 10 minutes |
| 11 | +--- |
| 12 | + |
| 13 | +This guide shows how to run Claude Code with Docker Model Runner as the backend |
| 14 | +model provider. You'll point Claude Code at the local Anthropic-compatible API, |
| 15 | +run a coding model, and package `gpt-oss` with a larger context window for |
| 16 | +longer repository prompts. |
| 17 | + |
| 18 | +In this guide, you'll learn how to: |
| 19 | + |
| 20 | +- Pull a coding model and start Claude Code with Docker Model Runner |
| 21 | +- Make the endpoint configuration persistent |
| 22 | +- Verify the local API endpoint and inspect requests |
| 23 | +- Package `gpt-oss` with a larger context window for longer prompts |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +Before you start, make sure you have: |
| 28 | + |
| 29 | +- [Docker Desktop](../get-started/get-docker.md) or Docker Engine installed |
| 30 | +- [Docker Model Runner enabled](../manuals/ai/model-runner/get-started.md#enable-docker-model-runner) |
| 31 | +- [Claude Code installed](https://code.claude.com/docs/en/quickstart) |
| 32 | + |
| 33 | +If you use Docker Desktop, turn on TCP access in **Settings** > **AI**, or run: |
| 34 | + |
| 35 | +```console |
| 36 | +$ docker desktop enable model-runner --tcp 12434 |
| 37 | +``` |
| 38 | + |
| 39 | +## Step 1: Pull a coding model |
| 40 | + |
| 41 | +Pull a model before you start Claude Code: |
| 42 | + |
| 43 | +```console |
| 44 | +$ docker model pull ai/devstral-small-2 |
| 45 | +``` |
| 46 | + |
| 47 | +You can also use `ai/qwen3-coder` if you want another coding-focused model with |
| 48 | +a large context window. |
| 49 | + |
| 50 | +## Step 2: Start Claude Code with Docker Model Runner |
| 51 | + |
| 52 | +Set `ANTHROPIC_BASE_URL` to your local Docker Model Runner endpoint when you run |
| 53 | +Claude Code. |
| 54 | + |
| 55 | +On macOS or Linux: |
| 56 | + |
| 57 | +```console |
| 58 | +$ ANTHROPIC_BASE_URL=http://localhost:12434 claude --model ai/devstral-small-2 |
| 59 | +``` |
| 60 | + |
| 61 | +On Windows PowerShell: |
| 62 | + |
| 63 | +```powershell |
| 64 | +$env:ANTHROPIC_BASE_URL="http://localhost:12434" |
| 65 | +claude --model ai/devstral-small-2 |
| 66 | +``` |
| 67 | + |
| 68 | +Claude Code now sends requests to Docker Model Runner instead of Anthropic's |
| 69 | +hosted API. |
| 70 | + |
| 71 | +## Step 3: Troubleshoot your first launch |
| 72 | + |
| 73 | +If Claude Code can't connect, check Docker Model Runner status: |
| 74 | + |
| 75 | +```console |
| 76 | +$ docker model status |
| 77 | +``` |
| 78 | + |
| 79 | +If Claude Code can't find the model, list local models: |
| 80 | + |
| 81 | +```console |
| 82 | +$ docker model ls |
| 83 | +``` |
| 84 | + |
| 85 | +If the model is missing, pull it first. If needed, use the fully qualified |
| 86 | +model name, such as `ai/devstral-small-2`. |
| 87 | + |
| 88 | +## Step 4: Make the endpoint persistent |
| 89 | + |
| 90 | +To avoid setting the environment variable each time, add it to your shell |
| 91 | +profile: |
| 92 | + |
| 93 | +```bash {title="~/.bashrc or ~/.zshrc"} |
| 94 | +export ANTHROPIC_BASE_URL=http://localhost:12434 |
| 95 | +``` |
| 96 | + |
| 97 | +On Windows PowerShell, add it to your PowerShell profile: |
| 98 | + |
| 99 | +```powershell {title="$PROFILE"} |
| 100 | +$env:ANTHROPIC_BASE_URL = "http://localhost:12434" |
| 101 | +``` |
| 102 | + |
| 103 | +After you reload your shell, you can run Claude Code with only the model flag: |
| 104 | + |
| 105 | +```console |
| 106 | +$ claude --model ai/devstral-small-2 |
| 107 | +``` |
| 108 | + |
| 109 | +## Step 5: Verify the API endpoint |
| 110 | + |
| 111 | +Send a test request to confirm the Anthropic-compatible API is reachable: |
| 112 | + |
| 113 | +```console |
| 114 | +$ curl http://localhost:12434/v1/messages \ |
| 115 | + -H "Content-Type: application/json" \ |
| 116 | + -d '{ |
| 117 | + "model": "ai/devstral-small-2", |
| 118 | + "max_tokens": 32, |
| 119 | + "messages": [{"role": "user", "content": "Say hello"}] |
| 120 | + }' |
| 121 | +``` |
| 122 | + |
| 123 | +For more details about the request format, see the |
| 124 | +[Anthropic-compatible API reference](../manuals/ai/model-runner/api-reference.md#anthropic-compatible-api). |
| 125 | + |
| 126 | +## Step 6: Inspect Claude Code requests |
| 127 | + |
| 128 | +To inspect the requests Claude Code sends to Docker Model Runner, run: |
| 129 | + |
| 130 | +```console |
| 131 | +$ docker model requests --model ai/devstral-small-2 | jq . |
| 132 | +``` |
| 133 | + |
| 134 | +This helps you debug prompts, context usage, and compatibility issues. |
| 135 | + |
| 136 | +## Step 7: Package `gpt-oss` with a larger context window |
| 137 | + |
| 138 | +`ai/gpt-oss` defaults to a smaller context window than coding-focused models. If |
| 139 | +you want to use it for repository-scale prompts, package a larger variant: |
| 140 | + |
| 141 | +```console |
| 142 | +$ docker model pull ai/gpt-oss |
| 143 | +$ docker model package --from ai/gpt-oss --context-size 32000 gpt-oss:32k |
| 144 | +``` |
| 145 | + |
| 146 | +Then run Claude Code with the packaged model: |
| 147 | + |
| 148 | +```console |
| 149 | +$ ANTHROPIC_BASE_URL=http://localhost:12434 claude --model gpt-oss:32k |
| 150 | +``` |
| 151 | + |
| 152 | +## Learn more |
| 153 | + |
| 154 | +- [Docker Model Runner overview](../manuals/ai/model-runner/_index.md) |
| 155 | +- [Docker Model Runner API reference](../manuals/ai/model-runner/api-reference.md) |
| 156 | +- [IDE and tool integrations](../manuals/ai/model-runner/ide-integrations.md) |
0 commit comments