forked from affaan-m/everything-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
642 lines (518 loc) · 15.1 KB
/
llms.txt
File metadata and controls
642 lines (518 loc) · 15.1 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# OpenCode Documentation for LLMs
> OpenCode is an open-source AI coding agent available as a terminal interface, desktop application, or IDE extension. It helps developers write code, add features, and understand codebases through conversational interactions.
## Installation
Multiple installation methods are available:
```bash
# curl script (recommended)
curl -fsSL https://opencode.ai/install | bash
# Node.js package managers
npm install -g opencode
bun install -g opencode
pnpm add -g opencode
yarn global add opencode
# Homebrew (macOS/Linux)
brew install anomalyco/tap/opencode
# Arch Linux
paru -S opencode
# Windows
choco install opencode # Chocolatey
scoop install opencode # Scoop
# Or use Docker/WSL (recommended for Windows)
```
## Configuration
Configuration file: `opencode.json` or `opencode.jsonc` (with comments)
Schema: `https://opencode.ai/config.json`
### Core Settings
```json
{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5",
"default_agent": "build",
"instructions": [
"CONTRIBUTING.md",
"docs/guidelines.md"
],
"plugin": [
"opencode-helicone-session",
"./.opencode/plugins"
],
"agent": { /* agent definitions */ },
"command": { /* command definitions */ },
"permission": {
"edit": "ask",
"bash": "ask",
"mcp_*": "ask"
},
"tools": {
"write": true,
"bash": true
}
}
```
### Environment Variables
Use `{env:VAR_NAME}` for environment variables and `{file:path}` for file contents in configuration values.
## Agents
OpenCode supports two agent types:
### Primary Agents
Main assistants you interact with directly. Switch between them using Tab or configured keybinds.
### Subagents
Specialized assistants that primary agents invoke automatically or through `@` mentions (e.g., `@general help me search`).
### Built-in Agents
| Agent | Type | Description |
|-------|------|-------------|
| build | primary | Default agent with full tool access for development work |
| plan | primary | Restricted agent for analysis; file edits and bash set to "ask" |
| general | subagent | Full tool access for multi-step research tasks |
| explore | subagent | Read-only agent for rapid codebase exploration |
| compaction | system | Hidden agent for context compaction |
| title | system | Hidden agent for title generation |
| summary | system | Hidden agent for summarization |
### Agent Configuration
JSON format in `opencode.json`:
```json
{
"agent": {
"code-reviewer": {
"description": "Reviews code for best practices",
"mode": "subagent",
"model": "anthropic/claude-opus-4-5",
"prompt": "{file:.opencode/prompts/agents/code-reviewer.txt}",
"temperature": 0.3,
"tools": {
"write": false,
"edit": false,
"read": true,
"bash": true
},
"permission": {
"edit": "deny",
"bash": {
"*": "ask",
"git status": "allow"
}
},
"steps": 10
}
}
}
```
Markdown format in `~/.config/opencode/agents/` or `.opencode/agents/`:
```markdown
---
description: Expert code review specialist
mode: subagent
model: anthropic/claude-opus-4-5
temperature: 0.3
tools:
write: false
read: true
bash: true
permission:
edit: deny
steps: 10
---
You are an expert code reviewer. Review code for quality, security, and maintainability...
```
### Agent Configuration Options
| Option | Purpose | Values |
|--------|---------|--------|
| description | Required field explaining agent purpose | string |
| mode | Agent type | "primary", "subagent", or "all" |
| model | Override default model | "provider/model-id" |
| temperature | Control randomness | 0.0-1.0 (lower = focused) |
| tools | Enable/disable specific tools | object or wildcards |
| permission | Set tool permissions | "ask", "allow", or "deny" |
| steps | Limit agentic iterations | number |
| prompt | Reference custom prompt file | "{file:./path}" |
| top_p | Alternative randomness control | 0.0-1.0 |
## Commands
### Built-in Commands
- `/init` - Initialize project analysis (creates AGENTS.md)
- `/undo` - Undo last change
- `/redo` - Redo undone change
- `/share` - Generate shareable conversation link
- `/help` - Show help
- `/connect` - Configure API providers
### Custom Commands
**Markdown files** in `~/.config/opencode/commands/` (global) or `.opencode/commands/` (project):
```markdown
---
description: Create implementation plan
agent: planner
subtask: true
---
Create a detailed implementation plan for: $ARGUMENTS
Include:
- Requirements analysis
- Architecture review
- Step breakdown
- Testing strategy
```
**JSON configuration** in `opencode.json`:
```json
{
"command": {
"plan": {
"description": "Create implementation plan",
"template": "Create a detailed implementation plan for: $ARGUMENTS",
"agent": "planner",
"subtask": true
},
"test": {
"template": "Run tests with coverage for: $ARGUMENTS\n\nOutput:\n!`npm test`",
"description": "Run tests with coverage",
"agent": "build"
}
}
}
```
### Template Variables
| Variable | Description |
|----------|-------------|
| `$ARGUMENTS` | All command arguments |
| `$1`, `$2`, `$3` | Positional arguments |
| `!`command`` | Include shell command output |
| `@filepath` | Include file contents |
### Command Options
| Option | Purpose | Required |
|--------|---------|----------|
| template | Prompt text sent to LLM | Yes |
| description | UI display text | No |
| agent | Target agent for execution | No |
| model | Override default LLM | No |
| subtask | Force subagent invocation | No |
## Tools
### Built-in Tools
| Tool | Purpose | Permission Key |
|------|---------|---------------|
| bash | Execute shell commands | "bash" |
| edit | Modify existing files using exact string replacements | "edit" |
| write | Create new files or overwrite existing ones | "edit" |
| read | Read file contents from codebase | "read" |
| grep | Search file contents using regular expressions | "grep" |
| glob | Find files by pattern matching | "glob" |
| list | List files and directories | "list" |
| lsp | Access code intelligence (experimental) | "lsp" |
| patch | Apply patches to files | "edit" |
| skill | Load skill files (SKILL.md) | "skill" |
| todowrite | Manage todo lists during sessions | "todowrite" |
| todoread | Read existing todo lists | "todoread" |
| webfetch | Fetch and read web pages | "webfetch" |
| question | Ask user questions during execution | "question" |
### Tool Permissions
```json
{
"permission": {
"edit": "ask",
"bash": "allow",
"webfetch": "deny",
"mcp_*": "ask"
}
}
```
Permission levels:
- `"allow"` - Tool executes without restriction
- `"deny"` - Tool cannot be used
- `"ask"` - Requires user approval before execution
## Custom Tools
Location: `.opencode/tools/` (project) or `~/.config/opencode/tools/` (global)
### Tool Definition
```typescript
import { tool } from "@opencode-ai/plugin"
export default tool({
description: "Execute SQL query on the database",
args: {
query: tool.schema.string().describe("SQL query to execute"),
database: tool.schema.string().optional().describe("Target database")
},
async execute(args, context) {
// context.worktree - git repository root
// context.directory - current working directory
// context.sessionID - current session ID
// context.agent - active agent identifier
const result = await someDbQuery(args.query)
return { result }
}
})
```
### Multiple Tools Per File
```typescript
// math.ts - creates math_add and math_multiply tools
export const add = tool({
description: "Add two numbers",
args: {
a: tool.schema.number(),
b: tool.schema.number()
},
async execute({ a, b }) {
return { result: a + b }
}
})
export const multiply = tool({
description: "Multiply two numbers",
args: {
a: tool.schema.number(),
b: tool.schema.number()
},
async execute({ a, b }) {
return { result: a * b }
}
})
```
### Schema Types (Zod)
```typescript
tool.schema.string()
tool.schema.number()
tool.schema.boolean()
tool.schema.array(tool.schema.string())
tool.schema.object({ key: tool.schema.string() })
tool.schema.enum(["option1", "option2"])
tool.schema.optional()
tool.schema.describe("Description for LLM")
```
## Plugins
Plugins extend OpenCode with custom hooks, tools, and behaviors.
### Plugin Structure
```typescript
import { tool } from "@opencode-ai/plugin"
export const MyPlugin = async ({ project, client, $, directory, worktree }) => {
// project - Current project information
// client - OpenCode SDK client for AI interaction
// $ - Bun's shell API for command execution
// directory - Current working directory
// worktree - Git worktree path
return {
// Hook implementations
"file.edited": async (event) => {
// Handle file edit event
},
"tool.execute.before": async (input, output) => {
// Intercept before tool execution
},
"session.idle": async (event) => {
// Handle session idle
}
}
}
```
### Loading Plugins
1. **Local files**: Place in `.opencode/plugins/` (project) or `~/.config/opencode/plugins/` (global)
2. **npm packages**: Specify in `opencode.json`:
```json
{
"plugin": [
"opencode-helicone-session",
"@my-org/custom-plugin",
"./.opencode/plugins"
]
}
```
### Available Hook Events
**Command Events:**
- `command.executed` - After a command is executed
**File Events:**
- `file.edited` - After a file is edited
- `file.watcher.updated` - When file watcher detects changes
**Tool Events:**
- `tool.execute.before` - Before tool execution (can modify input)
- `tool.execute.after` - After tool execution (can modify output)
**Session Events:**
- `session.created` - When session starts
- `session.compacted` - After context compaction
- `session.deleted` - When session ends
- `session.idle` - When session becomes idle
- `session.updated` - When session is updated
- `session.status` - Session status changes
**Message Events:**
- `message.updated` - When message is updated
- `message.removed` - When message is removed
- `message.part.updated` - When message part is updated
**LSP Events:**
- `lsp.client.diagnostics` - LSP diagnostic updates
- `lsp.updated` - LSP state updates
**Shell Events:**
- `shell.env` - Modify shell environment variables
**TUI Events:**
- `tui.prompt.append` - Append to TUI prompt
- `tui.command.execute` - Execute TUI command
- `tui.toast.show` - Show toast notification
**Other Events:**
- `installation.updated` - Installation updates
- `permission.asked` - Permission request
- `server.connected` - Server connection
- `todo.updated` - Todo list updates
### Hook Event Mapping (Claude Code → OpenCode)
| Claude Code Hook | OpenCode Plugin Event |
|-----------------|----------------------|
| PreToolUse | `tool.execute.before` |
| PostToolUse | `tool.execute.after` |
| Stop | `session.idle` or `session.status` |
| SessionStart | `session.created` |
| SessionEnd | `session.deleted` |
| N/A | `file.edited`, `file.watcher.updated` |
| N/A | `message.*`, `permission.*`, `lsp.*` |
### Plugin Example: Auto-Format
```typescript
export const AutoFormatPlugin = async ({ $, directory }) => {
return {
"file.edited": async (event) => {
if (event.path.match(/\.(ts|tsx|js|jsx)$/)) {
await $`prettier --write ${event.path}`
}
}
}
}
```
### Plugin Example: TypeScript Check
```typescript
export const TypeCheckPlugin = async ({ $, client }) => {
return {
"tool.execute.after": async (input, output) => {
if (input.tool === "edit" && input.args.filePath?.match(/\.tsx?$/)) {
const result = await $`npx tsc --noEmit`.catch(e => e)
if (result.exitCode !== 0) {
client.app.log("warn", "TypeScript errors detected")
}
}
}
}
}
```
## Providers
OpenCode integrates 75+ LLM providers via AI SDK and Models.dev.
### Supported Providers
- OpenCode Zen (recommended for beginners)
- Anthropic (Claude)
- OpenAI (GPT)
- Google (Gemini)
- Amazon Bedrock
- Azure OpenAI
- GitHub Copilot
- Ollama (local)
- And 70+ more
### Provider Configuration
```json
{
"provider": {
"anthropic": {
"options": {
"baseURL": "https://api.anthropic.com/v1"
}
},
"custom-provider": {
"npm": "@ai-sdk/openai-compatible",
"name": "Display Name",
"options": {
"baseURL": "https://api.example.com/v1",
"apiKey": "{env:CUSTOM_API_KEY}"
},
"models": {
"model-id": { "name": "Model Name" }
}
}
}
}
```
### Model Naming Convention
Format: `provider/model-id`
Examples:
- `anthropic/claude-sonnet-4-5`
- `anthropic/claude-opus-4-5`
- `anthropic/claude-haiku-4-5`
- `openai/gpt-4o`
- `google/gemini-2.0-flash`
### API Key Setup
```bash
# Interactive setup
opencode
/connect
# Environment variables
export ANTHROPIC_API_KEY=sk-...
export OPENAI_API_KEY=sk-...
```
Keys stored in: `~/.local/share/opencode/auth.json`
## MCP (Model Context Protocol)
Configure MCP servers in `opencode.json`:
```json
{
"mcp": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "{env:GITHUB_TOKEN}"
}
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
}
}
}
```
MCP tool permissions use `mcp_*` wildcard:
```json
{
"permission": {
"mcp_*": "ask"
}
}
```
## Ecosystem Plugins
### Authentication & Provider Plugins
- Alternative model access (ChatGPT Plus, Gemini, Antigravity)
- Session tracking (Helicone headers)
- OAuth integrations
### Development Tools
- Sandbox isolation (Daytona integration)
- Type injection for TypeScript/Svelte
- DevContainer multi-branch support
- Git worktree management
### Enhancement Plugins
- Web search with citations
- Markdown table formatting
- Dynamic context token pruning
- Desktop notifications
- Persistent memory (Supermemory)
- Background process management
### Plugin Discovery
- opencode.cafe - Community plugin registry
- awesome-opencode - Curated list
- GitHub search for "opencode-plugin"
## Quick Reference
### Key Shortcuts
| Key | Action |
|-----|--------|
| Tab | Toggle between Plan and Build modes |
| @ | Reference files or mention agents |
| / | Execute commands |
### Common Commands
```bash
/init # Initialize project
/connect # Configure API providers
/share # Share conversation
/undo # Undo last change
/redo # Redo undone change
/help # Show help
```
### File Locations
| Purpose | Project | Global |
|---------|---------|--------|
| Configuration | `opencode.json` | `~/.config/opencode/config.json` |
| Agents | `.opencode/agents/` | `~/.config/opencode/agents/` |
| Commands | `.opencode/commands/` | `~/.config/opencode/commands/` |
| Plugins | `.opencode/plugins/` | `~/.config/opencode/plugins/` |
| Tools | `.opencode/tools/` | `~/.config/opencode/tools/` |
| Auth | - | `~/.local/share/opencode/auth.json` |
### Troubleshooting
```bash
# Verify credentials
opencode auth list
# Check configuration
cat opencode.json | jq .
# Test provider connection
/connect
```
---
For more information: https://opencode.ai/docs/