Last active
April 1, 2026 04:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }, | |
| }; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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" | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup
ModelProfilePlugin.tsfile into your OpenCode plugins directory (e.g.~/.config/opencode/plugins/)profiles.jsonone level up from the plugin (or adjust the import path)profiles.json(e.g.senior) instead of specific modelsprofiles.jsonto your liking and possibly update theDEFAULT_PROFILEconstant.OPENCODE_MODEL_PROFILEenv variable to a name of the profile.