Skip to content

Instantly share code, notes, and snippets.

@krystofrezac
Last active April 1, 2026 04:47
Show Gist options
  • Select an option

  • Save krystofrezac/7f16ba252279f889eb750a866b257a1d to your computer and use it in GitHub Desktop.

Select an option

Save krystofrezac/7f16ba252279f889eb750a866b257a1d to your computer and use it in GitHub Desktop.
OpenCode plugin that applies named model profiles, remapping configured model IDs based on a selected provider profile. Useful for switching between LLM providers without changing your main config.
import type {Plugin} from "@opencode-ai/plugin";
import rawProfiles from '../profiles.json'
type Profile = Record<string, string>
const profiles: Record<string, Profile> = rawProfiles
const DEFAULT_PROFILE = "github-copilot";
const MODEL_PROFILE_ENV = "OPENCODE_MODEL_PROFILE"
export const ModelProfilePlugin: Plugin = async () => {
return {
config: async (config) => {
const profileName = process.env[MODEL_PROFILE_ENV] ?? DEFAULT_PROFILE;
const profile = profiles[profileName];
if (!profile) return;
const substitute = (model?: string) => (model && profile[model]) ?? model;
config.model = substitute(config.model);
for (const agent of Object.values(config.agent ?? {}))
if (agent) agent.model = substitute(agent.model);
for (const command of Object.values(config.command ?? {}))
if (command) command.model = substitute(command.model);
},
};
};
{
"github-copilot": {
"senior": "github-copilot/claude-opus-4.6",
"medior": "github-copilot/claude-sonnet-4.6",
"junior": "github-copilot/gpt-4.1"
},
"amazon-bedrock-claude": {
"senior": "amazon-bedrock/eu.anthropic.claude-opus-4-6-v1",
"medior": "amazon-bedrock/eu.anthropic.claude-sonnet-4-6",
"junior": "amazon-bedrock/eu.anthropic.claude-haiku-4-5-20251001-v1:0"
}
}
@krystofrezac

Copy link
Copy Markdown
Author

Setup

  1. Copy the ModelProfilePlugin.ts file into your OpenCode plugins directory (e.g. ~/.config/opencode/plugins/)
  2. Place profiles.json one level up from the plugin (or adjust the import path)
  3. In your agents and commands, reference the model aliases in profiles.json (e.g. senior) instead of specific models
    ---
    description: My custom agent
    model: senior
    ---
    
    <instructions>
  4. Update the profiles.json to your liking and possibly update the DEFAULT_PROFILE constant.
  5. To change the profile used, set a OPENCODE_MODEL_PROFILE env variable to a name of the profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment