How to Create and Switch Pi and OpenCode Agent Profiles with Mise

Use Mise to manage multiple agent profiles for OpenCode and Pi Coding Agent, keeping your tools, prompts, and configurations organized by task.

Problem: I want different agents for different types of work. For example, researching bike security is much different from building a web app which is much different from configuring my homelab.

Solution: Mise is a polyglot tool manager that can switch environment variables per-project or per-session. I use it to set up different OpenCode and Pi Coding Agent harnesses that I can select for the task at hand. I want to set up the context, model, tools and prompts to fit the work. OpenCode and Pi Coding Agent allow you to specify your config paths with environment variables, Mise provides a mechanism to easily switch on the fly. This allows you to use different skills, tools, system prompts and plugins/extensions in your harness.

Here’s how to set it up:

  • Install mise
  • Option 1: Manually configure your profiles
    • Create profile directories and base config
      • OpenCode:
        PROFILE="my_profile"
        mkdir -p ~/.config/opencode/profiles/$PROFILE/{agents,commands,plugins,tools,modes,themes,skills}
        cat > ~/.config/opencode/profiles/$PROFILE/opencode.json << 'EOF'
        {
          "$schema": "https://opencode.ai/config.json"
        }
        EOF
        
      • Pi:
        PROFILE="my_profile"
        mkdir -p ~/.pi/profiles/$PROFILE/{skills,extensions,prompt-templates}
        cp ~/.pi/agent/settings.json ~/.pi/profiles/$PROFILE/settings.json
        ln -sf ~/.pi/agent/auth.json ~/.pi/profiles/$PROFILE/auth.json
        
    • Create mise.{profile}.toml files:
      cat > ~/.config/mise/mise.${PROFILE}.toml << EOF
      [env]
      OPENCODE_CONFIG = "$HOME/.config/opencode/profiles/$PROFILE/opencode.json"
      OPENCODE_CONFIG_DIR = "$HOME/.config/opencode/profiles/$PROFILE"
      PI_CODING_AGENT_DIR = "$HOME/.pi/profiles/$PROFILE"
      PI_CODING_AGENT_SESSION_DIR = "$HOME/.pi/agent/sessions"
      EOF
      
    • Use mise to launch a session with your profile:
      mise exec -E ${PROFILE} -- opencode
      mise exec -E ${PROFILE} -- pi
      
    • (Optional) Add aliases to .zshrc
  • Option 2: Run this script (zsh required):
#!/usr/bin/env bash
set -euo pipefail

PROFILE="${1:-}"

if [[ -z "$PROFILE" ]]; then
  echo "Usage: $(basename "$0") <profile-name>"
  echo ""
  echo "Creates a new profile for opencode and pi with mise integration."
  echo ""
  echo "Example: $(basename "$0") design"
  exit 1
fi

if [[ "$PROFILE" =~ [^a-zA-Z0-9_-] ]]; then
  echo "Error: profile name must only contain letters, numbers, hyphens, and underscores"
  exit 1
fi

if [[ -d "$HOME/.config/opencode/profiles/$PROFILE" || -d "$HOME/.pi/profiles/$PROFILE" ]]; then
  echo "Error: profile '$PROFILE' already exists"
  exit 1
fi

# --- OpenCode ---
mkdir -p "$HOME/.config/opencode/profiles/$PROFILE"/{agents,commands,plugins,tools,modes,themes,skills}

cat > "$HOME/.config/opencode/profiles/$PROFILE/opencode.json" << 'EOF'
{
  "$schema": "https://opencode.ai/config.json"
}
EOF

echo "[ok] opencode profile: ~/.config/opencode/profiles/$PROFILE/"

# --- Pi ---
mkdir -p "$HOME/.pi/profiles/$PROFILE"/{skills,extensions,prompt-templates}

cp "$HOME/.pi/agent/settings.json" "$HOME/.pi/profiles/$PROFILE/settings.json"
ln -sf "$HOME/.pi/agent/auth.json" "$HOME/.pi/profiles/$PROFILE/auth.json"

echo "[ok] pi profile: ~/.pi/profiles/$PROFILE/"

# --- Mise env file ---
cat > "$HOME/.config/mise/mise.${PROFILE}.toml" << EOF
[env]
OPENCODE_CONFIG = "$HOME/.config/opencode/profiles/$PROFILE/opencode.json"
OPENCODE_CONFIG_DIR = "$HOME/.config/opencode/profiles/$PROFILE"
PI_CODING_AGENT_DIR = "$HOME/.pi/profiles/$PROFILE"
PI_CODING_AGENT_SESSION_DIR = "$HOME/.pi/agent/sessions"
EOF

echo "[ok] mise env file: ~/.config/mise/mise.${PROFILE}.toml"

# --- Shell aliases ---
ZSHRC="$HOME/.zshrc"

add_alias() {
  local alias_line="$1"
  if ! grep -qxF "$alias_line" "$ZSHRC" 2>/dev/null; then
    echo "$alias_line" >> "$ZSHRC"
    echo "[ok] added alias: $alias_line"
  else
    echo "[skip] alias already exists: $alias_line"
  fi
}

add_alias "alias oc-${PROFILE}='mise exec -E ${PROFILE} -- opencode'"
add_alias "alias pi-${PROFILE}='mise exec -E ${PROFILE} -- pi'"

echo ""
echo "Profile '$PROFILE' created successfully."
echo "Run 'source ~/.zshrc' to activate the new aliases."

The script makes it easy to create new profiles on the fly if I want to test out a combination of plugins, skills, tools or system prompt. These directories hold the agent’s configuration files, extensions, and reusable prompt templates.

Once this is set up, you can modify the profiles by hand or use the agent to sculpt itself.

I have started with the following profiles:

  • dev
  • devops
  • admin
  • general
  • design
  • experiment

This command launches opencode using the dev profile:

oc-dev

I can then install something like oh-my-openagent which will live exclusively in this profile, which allows me to mix and match my CMTP (context, model, tools, prompts) in multiple different ways!

Profiles let you tailor your agent to the work at hand without cluttering a single global configuration. Give it a try and see how much cleaner your workflow becomes.