Agent-Bridge + OpenCode


The Just-in-Time Agent: Integrating OpenCode with AgentBridge via ZSH

Some people manage their AI agent environments by maintaining multiple configuration files and manually switching between them… and some folks don’t even bother at all… I think I fall somwhere in the middle lol… I wanted something eode.json`, I have the AgentBridge MCP server defined like this:


## The Problem: The "Missing Variable" Trap

I use **OpenCode** as my primary agentic CLI, and **AgentBridge** to give it deep access to my JetBrains IDE. In my global `openc
"AgentBridge": {
  "type": "remote",
  "url": "http://localhost:{env:AGENTBRIDGE_MCP_PORT}/api/mcp"
}

Notice the {env:AGENTBRIDGE_MCP_PORT}. This is the key. This port is only known and active when the AgentBridge plugin is running inside a JetBrains IDE. If I simply set "enabled": true in my global config, every time I run an agent in a standard terminal, it tries to resolve that environment variable, fails, the agent tries to use IDE tools that aren’t there, leading to errors and noise. This is a compound problem, if I let the whole config load (with a static port) I’ll end up with my CLI app trying to fill in everything. This is a quick way to make a hot mess of your config…

The Solution: Environment Variable Injection

OpenCode allows you to override its configuration via the OPENCODE_CONFIG_CONTENT environment variable. I use this to “flip the switch” only when I launch my IDE.

I keep AgentBridge disabled by default in my global environment. Then, I wrap my IDE launch commands in ZSH functions that inject the “enabled” state only for that specific process.

# 1. Disable AgentBridge by default in the global environment
# This prevents crosstalk in the standard terminal
export OPENCODE_CONFIG_CONTENT='{"mcp": {"AgentBridge": {"enabled": false}}}'
# 2. The "Injection" functions
# When called, these functions export a NEW config content
# that enables the bridge for the IDE process only.
idea() {
    export OPENCODE_CONFIG_CONTENT='{"mcp": {"AgentBridge": {"enabled": true}}}'
    "$HOME/.local/bin/idea" "$@"
}
pycharm() {
    export OPENCODE_CONFIG_CONTENT='{"mcp": {"AgentBridge": {"enabled": true}}}'
    "$HOME/.local/bin/pycharm" "$@"
}

End result

Links


Reply:
Mastodon Bluesky Email
Prev
Less is More: How an AI Agent Taught Me to Write Better systemd Services
Less is More: How an AI Agent Taught Me to Write Better systemd Services
Next
Launchers ... neat?
Launchers ... neat?

Comments




Kudos:



TOC: