Skip to content

OpenCode plugin to switch agent models between performance and economy modes

License

Notifications You must be signed in to change notification settings

j4rviscmd/opencode-agent-modes

Repository files navigation

opencode-agent-modes

npm license npm downloads npm version OpenCode Plugin TypeScript

OpenCode plugin to switch agent models between performance and economy modes.

Note

Primary Use Case: When approaching your token limit, switch to pre-defined economy models to extend your session until your quota resets. Changes take effect after restarting opencode.

Change mode example

Features

  • Switch between different model presets (performance, economy, or custom)
  • Configurable presets with user-defined models
  • Toast notifications for mode changes

Supported Agents

Agent Type Description
opencode agents Standard agents (build, plan, etc.)
oh-my-opencode agents Optional - applies if oh-my-opencode is installed

Installation

Add the plugin to your opencode.json:

{
  "plugin": ["opencode-agent-modes@latest"]
}

The following command files are automatically copied to ~/.config/opencode/command/ when the plugin initializes:

  • mode-performance.md
  • mode-economy.md
  • mode-status.md
  • mode-list.md

Usage

Available Commands

  • /mode-performance - Switch to high-performance models
  • /mode-economy - Switch to cost-efficient free models
  • /mode-status - Show current mode and configuration
  • /mode-list - List all available mode presets

Available Tools

  • mode_switch - Switch to a specified mode preset
  • mode_status - Display current mode settings
  • mode_list - List all available presets

Configuration

The plugin configuration is stored at ~/.config/opencode/agent-mode-switcher.json.

On first run, the plugin automatically generates this file by:

  1. Reading current models from opencode.json for the "performance" preset
  2. Setting opencode/glm-4.7-free for the "economy" preset

Example Configuration

Tip

The oh-my-opencode section is optional. Omit it if you don't use oh-my-opencode.

{
  "currentMode": "performance",
  "showToastOnStartup": true,
  "presets": {
    "performance": {
      "description": "High-performance models for complex tasks",
      "opencode": {
        "build": { "model": "github-copilot/gpt-5.2" },
        "plan": { "model": "github-copilot/gpt-5.2" }
      },
      "oh-my-opencode": {
        "Sisyphus": { "model": "anthropic/claude-opus-4-5-20251101" }
      }
    },
    "economy": {
      "description": "Cost-efficient free model for routine tasks",
      "opencode": {
        "build": { "model": "opencode/glm-4.7-free" }
      },
      "oh-my-opencode": {
        "Sisyphus": { "model": "opencode/glm-4.7-free" }
      }
    }
  }
}

Model Priority

When both global model and agent-specific opencode settings are configured, the priority is:

agent.<name>.model > model (global)

Agent-specific settings override the global model setting.

Custom Presets

To add a custom preset (e.g., "premium"):

  1. Add the preset to ~/.config/opencode/agent-mode-switcher.json:

    {
      "presets": {
        "premium": {
          "description": "High-end models for critical tasks",
          "opencode": {
            "build": { "model": "anthropic/claude-opus-4-5-20251101" }
          }
        }
      }
    }
  2. Create a command file at ~/.config/opencode/command/mode-premium.md:

    ---
    description: "Switch to premium mode (high-end models)"
    ---
    
    Use mode_switch tool to switch agent mode to "premium".
  3. Restart opencode to apply changes.

[!INFO]

  • Changes require an opencode restart to take effect
  • Custom mode presets can be added by editing the configuration file

Development

This project uses Bun as the runtime and package manager.

Prerequisites

  • Bun v1.0 or later

Setup

# Clone the repository
git clone https://github.com/j4rviscmd/opencode-agent-modes.git
cd opencode-agent-modes

# Install dependencies
bun install

# Run tests
bun test

# Type check
bun run typecheck

# Lint & format
bun run lint
bun run format

# Build
bun run build

About

OpenCode plugin to switch agent models between performance and economy modes

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •