1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# OpenCode Setup on Hyperstack with Ollama
This document outlines the steps to install and configure OpenCode to work with local Ollama models on a remote A100-80GB server.
## Prerequisites
- SSH access to the remote server (e.g., `ubuntu@IPHERE`)
- Ollama installed on the remote server
## Installation Steps
### 0. Install Ollama
Install Ollama on the remote server:
```bash
ssh ubuntu@IPHERE "curl -fsSL https://ollama.ai/install.sh | sh"
```
Start Ollama service:
```bash
ssh ubuntu@IPHERE "sudo systemctl start ollama && sudo systemctl status ollama"
```
### 1. Kill Unattended Upgrade Lock
If the package manager is locked by unattended-upgrades:
```bash
ssh ubuntu@IPHERE "sudo kill -9 3523 && sleep 2"
```
### 2. Verify Node.js is Installed
```bash
ssh ubuntu@IPHERE "npm --version && node --version"
```
If not installed, install Node.js:
```bash
ssh ubuntu@IPHERE "sudo apt install -y nodejs npm"
```
### 3. Download and Install OpenCode CLI
Get the latest release from GitHub releases and install to `/usr/local/bin`:
```bash
ssh ubuntu@IPHERE "cd /tmp && wget -q https://github.com/anomalyco/opencode/releases/download/v1.1.32/opencode-linux-x64.tar.gz && tar -xzf opencode-linux-x64.tar.gz && sudo mv opencode /usr/local/bin/ && opencode --version"
```
This installs OpenCode v1.1.32. Check [GitHub releases](https://github.com/anomalyco/opencode/releases) for the latest version.
### 4. Create OpenCode Configuration Directory
```bash
ssh ubuntu@IPHERE "mkdir -p ~/.config/opencode"
```
### 5. Configure OpenCode to Use Ollama
Create `~/.config/opencode/opencode.json` with Ollama as the provider:
```bash
ssh ubuntu@IPHERE "cat > ~/.config/opencode/opencode.json << 'EOF'
{
\"provider\": {
\"ollama\": {
\"npm\": \"@ai-sdk/openai-compatible\",
\"name\": \"Ollama\",
\"api\": \"http://localhost:11434/v1\",
\"models\": {
\"qwen3-coder:30b-a3b-q4_K_M\": {
\"name\": \"Qwen3 Coder 30B A3B Q4_K_M\"
},
\"qwen2.5-coder:32b\": {
\"name\": \"Qwen2.5 Coder 32B\"
},
\"mistral-large\": {
\"name\": \"Mistral Large 123B\"
},
\"deepseek-coder\": {
\"name\": \"Deepseek Coder\"
}
}
}
}
}
EOF"
```
**Key configuration fields:**
- `npm`: AI SDK package for OpenAI-compatible APIs
- `api`: Ollama endpoint (defaults to localhost:11434)
- `models`: Map of model IDs to display names
### 6. Clean Up Disk Space (if needed)
Check disk usage:
```bash
ssh ubuntu@IPHERE "df -h / && ollama list"
```
For A100-80GB, ensure sufficient space (~120GB free). Remove unused models if needed:
```bash
ssh ubuntu@IPHERE "ollama rm model_name"
```
### 7. Pull Models into Ollama
Pull Qwen3 Coder 30B (~20GB):
```bash
ssh ubuntu@IPHERE "ollama pull qwen3-coder:30b-a3b-q4_K_M"
```
Pull Qwen2.5 Coder 32B (~19GB):
```bash
ssh ubuntu@IPHERE "ollama pull qwen2.5-coder:32b"
```
Pull Mistral Large (~73GB):
```bash
ssh ubuntu@IPHERE "ollama pull mistral-large"
```
Pull Deepseek Coder (776MB - lightweight option):
```bash
ssh ubuntu@IPHERE "ollama pull deepseek-coder"
```
Verify models are available:
```bash
ssh ubuntu@IPHERE "ollama list"
```
## Using OpenCode
Navigate to your project and start OpenCode:
```bash
ssh ubuntu@IPHERE
cd ~/git/aitest
opencode
```
Then:
1. Press Tab to enter Plan mode (recommended for new features)
2. Use `/models` command to select which Ollama model to use
3. Ask OpenCode to help with your code
## Configuration Details
### Provider Configuration Schema
The `provider` object in `opencode.json` uses this structure:
```json
{
"provider": {
"provider_id": {
"npm": "@ai-sdk/openai-compatible",
"name": "Display Name",
"api": "http://localhost:11434/v1",
"models": {
"model_id": {
"name": "Model Display Name"
}
}
}
}
}
```
### Available Models
#### Qwen3 Coder 30B A3B Q4_K_M
- **Size**: ~20GB (optimized quantization)
- **Strengths**: Advanced coding capabilities, good tool calling, specialized for programming
- **Tool Support**: Function calling support
- **Use Case**: Primary coding assistant for complex tasks
#### Qwen2.5 Coder 32B
- **Size**: ~19GB
- **Strengths**: Optimized for function calling and coding, better than earlier versions
- **Tool Support**: Strong function calling support
- **Use Case**: Reliable coding assistant for general-purpose tasks
#### Mistral Large 123B
- **Size**: 73GB
- **Strengths**: Excellent tool/function calling support, strong reasoning, balanced for coding
- **Tool Support**: Native function calling
- **Use Case**: Most capable model for complex reasoning and coding tasks
#### Deepseek Coder
- **Size**: 776MB (very lightweight)
- **Strengths**: Specialized for coding tasks, fast inference
- **Tool Support**: Function calling support
- **Use Case**: Fast responses for code generation and analysis on limited resources
### Ollama Endpoint
OpenCode communicates with Ollama via the OpenAI-compatible API:
- Default: `http://localhost:11434/v1`
- Ollama models endpoint: `http://localhost:11434/api/tags`
## Troubleshooting
### Configuration Error: "Unrecognized key"
Ensure the config uses correct structure:
- Top-level key should be `provider` (not `providers`)
- Provider ID (e.g., `ollama`) is a key under `provider` object
- Each provider has `npm`, `name`, `api`, and `models` fields
### Out of Disk Space
Check available space:
```bash
df -h /
```
Remove models:
```bash
ollama rm model_name
```
For A100-80GB, budget ~120GB for models + system (account for OS and dependencies).
### Ollama Connection Issues
Verify Ollama is running and accessible:
```bash
curl -s http://localhost:11434/api/tags | jq '.models[].name'
```
If using remote SSH, ensure:
- Ollama is listening on 0.0.0.0 (not just localhost)
- Port 11434 is not firewalled
- Use SSH port forwarding: `ssh -L 11434:localhost:11434 ubuntu@server`
## References
- [OpenCode Documentation](https://opencode.ai/docs)
- [OpenCode Providers Configuration](https://opencode.ai/docs/providers)
- [OpenCode GitHub](https://github.com/anomalyco/opencode)
- [Ollama Documentation](https://ollama.ai)
|