Files
opencode-manager/docs/features/ai-config.md
Chris Scott 295d24ced7 refactor(config): make on-disk opencode.json the single source of truth (#354)
* refactor(config): make on-disk opencode.json the single source of truth

Make <workspace>/.config/opencode/opencode.json the only store for the active OpenCode configuration. One owner (opencode-config-file.ts) reads, validates, writes, archives, and seeds the file; one owner (opencode-config-apply.ts) decides how an edit is applied: restart pending, or a live patch with recovery. Settings routes, the internal assistant API, the health-watch supervisor, boot, and host import all go through them, so an edit that lands on the file without going through the database is visible immediately instead of at the next Manager boot.

Remove the named-config profiles. Migration 019 archives every opencode_configs row to .config/opencode-configs-archive/<name>.json, restores the default row to opencode.json when no file exists, then drops the table, its indexes, and repos.opencode_config_name. The /opencode-configs* and config/switch routes and the CreateConfigDialog/SwitchConfigDialog dialogs are gone, and the ocm tool gains GET/PUT /opencode-config backed by the same apply owner.

Harden the write path: serialize and atomically write config updates while preserving the file mode, keep withFileLock usable after a rejection, route reloadConfig's cleaned-config write through the file owner, stop boot from rewriting an existing valid config when importing state, prune the health-watch directory to its newest 20 entries, resolve archive paths with realpath, and share one frontend config query across dialogs.

* fix(mirror): canonicalize worktree paths before branch ownership check

* refactor(config): unify opencode config apply and rollback paths

- share one config route factory between public and internal mounts
- capture last-known-good before every config write and restore via one helper
- stop auto-restarting on save; flag restart-required fields and live-patch the rest
- add CONFIG_PATCH_TIMEOUT_MS for config patch requests
- extract canonicalPath helpers, health-watch artifact writer, and useProvidersWithModels hook

* refactor(model-state): use OpenCode state file as model state source of truth
2026-09-19 00:28:34 -04:00

146 lines
4.6 KiB
Markdown

# AI Configuration
Configure AI models, providers, and custom agents.
## Model Selection
### Quick Model Switcher
A compact model switcher is embedded directly in the chat interface. Click the **model name** in the prompt area or chat header to open the quick-select popover:
| Item | Description |
|------|-------------|
| **Active model** | Shown at the top with a checkmark. Click the star icon to add or remove from favorites. |
| **Favorites** | Pinned models always appear first in the list. |
| **Recents** | Last 10 used models appear below favorites (excluding the active one and any favorites). |
| **Variants** | Some models offer tier options (e.g., fast or pro). Variant items are highlighted and show a checkmark on the active selection. |
| **All Models…** | Opens the full model browser when you need a model not in recents or favorites. |
Favorites, recents, and variant choices are stored in OpenCode's own state file (`.opencode/state/opencode/model.json` in the workspace), so they are shared with the OpenCode TUI and survive Manager restarts. The active model itself is not persisted: on page load it resolves the same way the OpenCode TUI does — the `model` set in `opencode.json`, otherwise your most recent valid model, otherwise the provider default. A model you pick during a session stays active until the page is reloaded.
### Per-Agent and Per-Session Models
Each agent can declare its own `model` in `opencode.json`, which becomes that agent's default. When you open an existing session, the model, agent, and variant used by its last message are restored from the session itself, so switching between sessions keeps each one's selection.
### Full Model Browser
To browse all available models:
1. Click **All Models…** in the quick-select popover
2. Filter by provider or search by name
3. Click a model to select it
### Changing Models Mid-Session
You can switch models at any point during a session without losing context. The new model is used for all subsequent messages.
## Providers
Configure API keys or OAuth for AI providers.
![Providers Settings](../images/ai-config-providers.png)
### API Key Method
1. Go to **Settings > Providers**
2. Select a provider (OpenAI, Anthropic, etc.)
3. Enter your API key
4. Click **Save**
### OAuth Method
For providers that support OAuth (Anthropic, GitHub Copilot):
1. Go to **Settings > Providers**
2. Select a provider with the OAuth badge
3. Click **Add OAuth**
4. Choose authorization method:
- **Open Authorization Page** - Opens browser for sign-in
- **Use Authorization Code** - Provides code for manual entry
5. Complete the authorization flow
### Testing Credentials
After adding credentials:
1. Open a chat session and click the model selector
2. Models from that provider should appear
3. Select a model and try sending a message
If models don't appear, verify your API key and check for errors.
## Custom Agents
Create specialized AI agents with custom configurations.
### Creating an Agent
1. Go to **Settings > Agents**
2. Click **Create Agent**
3. Configure:
- **Name** - Display name for the agent
- **Description** - What this agent does
- **System Prompt** - Instructions for the AI
- **Default Model** - Model to use
- **Allowed Tools** - Which MCP tools it can access
4. Click **Save**
### System Prompt Tips
Write effective system prompts:
```
You are a code review expert specializing in TypeScript and React.
When reviewing code:
1. Check for type safety issues
2. Look for potential bugs
3. Suggest performance improvements
4. Ensure consistent code style
Be concise but thorough. Prioritize issues by severity.
```
### Tool Permissions
Control which MCP tools an agent can use:
- **All Tools** - Access to everything
- **Selected Tools** - Only specific tools
- **No Tools** - Pure conversation, no tool access
This is useful for:
- Security-focused agents that shouldn't modify files
- Research agents that only need read access
- Specialized agents for specific tasks
### Using Custom Agents
1. Start a new session
2. Click the agent selector
3. Choose your custom agent
4. Chat with the specialized agent
## Context Usage
Monitor token usage with the context indicator:
- Progress bar shows current usage
- Updates as conversation grows
- Warning when approaching limits
### Managing Context
When context is running low:
1. Use `/compact` to summarize history
2. Start a new session with `/new`
3. Be more concise in prompts
4. Remove unnecessary file mentions
### Context Limits
Different models have different context limits. Check your provider's documentation for exact limits per model.