r/opencodeCLI • • 1d ago

Native multi-profile support in OpenCode 2 (separate subscriptions & MCPs)?

Does anyone know if native multi-profile support (like a `--profile` flag) is planned or already possible in OpenCode 2?

I want to maintain completely separate setups, work vs. personal where each profile has:

* Its own authenticated subscriptions / providers (`auth.json`)

* Its own set of enabled MCP servers (`opencode.jsonc`)

3 Upvotes

1 comment sorted by

1

u/molovo 1d ago edited 1d ago

Yes, it's possible, but a bit tricky to set up. You can separate out the directories so that two instances have entirely separate databases and config directories. I have a shell function that loads the correct one for me, based on the Github organisation for the repository I'm in, so I don't need to worry about running the wrong command.

Just add this to .zshrc, and then when you run opencode it'll run this function instead.

(( $+functions[opencode] )) || function opencode() {
  if [[ -z $CLAUDE_CONFIG_DIR ]] && { [[ -n $OPENCODE_ENV_WORK ]] || git remote -v 2>/dev/null | grep -qE 'github\.com[:/]myworkorganisation/'; }; then
    local -x CLAUDE_CONFIG_DIR=~/.claude-work
    local -x OPENCODE_DB=~/.local/share/opencode-work/opencode.db
    local -x OPENCODE_CONFIG_DIR=~/.config/opencode-work
    local -x OPENCODE_CONFIG=~/.config/opencode-work/work.jsonc
    local -x XDG_STATE_HOME=~/.local/state/opencode-work

    command opencode "$@"
    return
  fi

  command opencode "$@"
}

Just replace myworkorganisation in the function above with your own work organisation. I use Claude Agent within Opencode, so this also sets up a separate Claude Code directory as well so I get the correct Claude account for each Opencode profile. If you don't use Claude just remove the CLAUDE_CONFIG_DIR bits.

To set up the initial state:

cp -r ~/.local/share/opencode ~/.local/share/opencode-work
cp -r ~/.local/state/opencode ~/.local/state/opencode-work
mkdir -p ~/.config/opencode-work

The way I have it set up, I have a shared config, and then overrides. So my main config in the work directory is symlinked to my personal directory:

ln -s ~/.config/opencode/opencode.jsonc ~/.config/opencode-work/opencode.jsonc

Repeat the above for any other files you want shared, e.g. cli.json, agents, skills, plugins.

And then, I have a second config file at ~/.config/opencode-work/work.jsonc which contains any overrides. In my case, it's just a couple of additional MCP servers. That's all set up in the function at the top of this post.

If you're in a repository for a different organisation, but still want your work profile, just run OPENCODE_ENV_WORK=1 opencode and it'll load your work profile.