4.0 KiB
llm, status
| llm | status |
|---|---|
| openai/gpt-5.4 | done |
Multi-model launcher plan
Goal
Create an OpenCode project-local custom tool that:
- accepts a tmux session name plus one or more model names
- validates that the required tools and arguments are present
- validates each requested model against
opencode models - creates one tmux session and one window per model
- launches
opencode --model <model>in each window - prints a reliable attach instruction for the user
The right OpenCode primitive for this is a project-local custom tool in .opencode/tools/, not a slash command. Custom tools support typed argument schemas and programmatic execution, which makes validation sturdier, faster, and less dependent on prompt following.
Recommended implementation shape
- File:
.opencode/tools/multi-model.ts - Tool name:
multi-model - Arguments:
sessionName: stringmodels?: string[]
Proposed tool behavior
The tool should do the following in order:
- Verify
sessionNameexists and at least one model was supplied. - Verify
tmuxis installed withcommand -v tmux. - Verify
opencodeis installed withcommand -v opencode. - Run
opencode modelsand build an allowlist of valid model ids. - Reject any requested model that is not in the allowlist.
- Reject duplicate model ids in the same invocation.
- Check whether tmux session
sessionNamealready exists. - If a requested model is invalid, compute close matches from the allowlist and return a error message with instruction to fix the tool call.
- If no models are provided, return error.
- Create tmux session detached.
- Create one window per validated model.
- In each window, launch
opencode --model <model>. - Return
tmux attach -t <session-name>. - If any launch step fails after session creation, return exactly what succeeded and what failed.
Reliability and edge cases
Missing dependencies
tmuxnot installed: abort before any work.opencodenot installed or not onPATH: abort before any work.
Example:
const tmuxExists = await Bun.$`command -v tmux`.quiet().nothrow()
This is non-obvious because the tool should detect the environment first instead of failing halfway through tmux setup.
Suggested implementation notes
- Use shell-safe quoting for all user-provided values.
- Long model names may be truncated by tmux window naming: use a short sanitized label for the window name, but keep the full model id in the command.
Example:
Window name: gpt-5-4
Launch command: opencode --model openai/gpt-5.4
Example tool outline
import { tool } from "@opencode-ai/plugin"
export default tool({
description: "Launch multiple OpenCode models in tmux",
args: {
sessionName: tool.schema.string().min(1),
models: tool.schema.array(tool.schema.string().min(1)).min(1),
},
async execute(args, context) {
// 1. verify tmux and opencode exist
// 2. load valid models from `opencode models`
// 3. reject invalid or duplicate models
// 4. fail if session already exists
// 5. create session and windows
// 6. return structured success payload with attach command
return "Use `tmux attach -t sessionName` to join session.";
},
})
This example is intentionally minimal; the real implementation should return structured errors and partial-success details.
Return value
The tool should return freeform text.
For success - "Use tmux attach -t sessionName to join session."
For failures: "Error: Session already exists. Use a different sessionName.",
For invalid model name: "Error: Model name 'openai/gpt5.4' not found. Did you mean 'openai/gpt-5.4' or 'openai/gpt-5.4-mini'?",
For missing models array: "Error: Model names must not be empty."
Future ideas
- Add a project-local plugin wrapper for logging, richer UI integration, or event hooks while keeping the tool as the execution engine.
- Package the tool or plugin as an npm-distributed OpenCode plugin for reuse across multiple repositories and machines.