@@ -14,6 +14,44 @@ runtime_install() {
1414 _opencode_register_runtime_signature
1515}
1616
17+ opencode_claude_code_auth_enabled () {
18+ [ " ${WITH_CLAUDE_CODE_AUTH:- false} " = true ] || return 1
19+ [ " ${RUNTIME:- } " = " opencode" ] && return 0
20+
21+ local runtime
22+ for runtime in " ${DETECTED_RUNTIMES[@]:- } " ; do
23+ [ " $runtime " = " opencode" ] && return 0
24+ done
25+ return 1
26+ }
27+
28+ opencode_claude_code_auth_plugins_dir () {
29+ printf ' %s/.opencode/plugins' " $SITE_PATH "
30+ }
31+
32+ opencode_claude_code_auth_plugin_path () {
33+ printf ' %s/claude-code-auth.ts' " $( opencode_claude_code_auth_plugins_dir) "
34+ }
35+
36+ opencode_install_claude_code_auth_plugin () {
37+ opencode_claude_code_auth_enabled || return 0
38+
39+ local plugins_dir plugin_path source_path
40+ plugins_dir=" $( opencode_claude_code_auth_plugins_dir) "
41+ plugin_path=" $( opencode_claude_code_auth_plugin_path) "
42+ source_path=" $SCRIPT_DIR /runtimes/opencode/plugins/claude-code-auth.ts"
43+
44+ if [ " $DRY_RUN " = true ]; then
45+ echo -e " ${BLUE} [dry-run]${NC} Would install Claude Code auth OpenCode plugin at $plugin_path "
46+ return 0
47+ fi
48+
49+ mkdir -p " $plugins_dir "
50+ cp " $source_path " " $plugin_path "
51+ chmod 644 " $plugin_path "
52+ UPDATED_ITEMS+=(" OpenCode Claude Code auth plugin ($plugin_path )" )
53+ }
54+
1755# _opencode_register_runtime_signature
1856#
1957# Publish opencode's worktree session-attribution env-var contract for the
@@ -169,6 +207,8 @@ runtime_generate_config() {
169207 fi
170208 fi
171209
210+ opencode_install_claude_code_auth_plugin
211+
172212 # On existing opencode.json, delegate to the repair helper in --additive
173213 # mode. This adds managed plugin entries the user is missing and applies
174214 # the prompt → instructions migration (fixes Anthropic Claude Max OAuth,
@@ -191,18 +231,17 @@ runtime_generate_config() {
191231 OPENCODE_JSON=" $OPENCODE_JSON ,\n \" small_model\" : \" ${OPENCODE_SMALL_MODEL} \" "
192232 fi
193233
194- # OpenCode plugins. wp-coding-agents only manages plugins it owns end to
195- # end: dm-context-filter.ts and dm-agent-sync.ts on Kimaki bridges. The sync
196- # plugin refreshes composed memory files without mutating config.agent slots.
197- # opencode-claude-auth plugin is intentionally NOT installed on any bridge:
198- # Kimaki ships a built-in AnthropicAuthPlugin and non-kimaki bridges use
199- # opencode's native auth flow (`opencode auth login anthropic`). See
200- # Extra-Chill/wp-coding-agents#117.
234+ # OpenCode plugins. The Data Machine prompt/memory plugins are managed on
235+ # Kimaki bridges. Claude Code OAuth auth is an explicit OpenCode runtime
236+ # opt-in so direct opencode sessions can use Claude Pro/Max subscription auth.
201237 OPENCODE_PLUGINS=" "
202238 if [ " $CHAT_BRIDGE " = " kimaki" ]; then
203239 OPENCODE_PLUGINS=" ${OPENCODE_PLUGINS} \n \" ${KIMAKI_PLUGINS_DIR} /dm-context-filter.ts\" ,"
204240 OPENCODE_PLUGINS=" ${OPENCODE_PLUGINS} \n \" ${KIMAKI_PLUGINS_DIR} /dm-agent-sync.ts\" ,"
205241 fi
242+ if opencode_claude_code_auth_enabled; then
243+ OPENCODE_PLUGINS=" ${OPENCODE_PLUGINS} \n \" $( opencode_claude_code_auth_plugin_path) \" ,"
244+ fi
206245
207246 if [ -n " $OPENCODE_PLUGINS " ]; then
208247 # Remove trailing comma from last plugin entry
@@ -273,6 +312,8 @@ _runtime_repair_opencode_json_additive() {
273312
274313 local BRIDGE_ARG=" ${CHAT_BRIDGE:- none} "
275314 local PLUGINS_DIR=" ${KIMAKI_PLUGINS_DIR:-/ opt/ kimaki-config/ plugins} "
315+ local CLAUDE_CODE_AUTH_PLUGIN=" "
316+ local claude_code_auth_args=()
276317 local SUFFIX
277318 SUFFIX=" $( date +%Y%m%d-%H%M%S) "
278319 local MANAGED_INSTRUCTIONS_FILE=" "
@@ -282,6 +323,10 @@ _runtime_repair_opencode_json_additive() {
282323 printf ' %s\n' " $DM_AGENT_FILES " > " $MANAGED_INSTRUCTIONS_FILE "
283324 managed_args=(--managed-instructions-file " $MANAGED_INSTRUCTIONS_FILE " )
284325 fi
326+ if opencode_claude_code_auth_enabled; then
327+ CLAUDE_CODE_AUTH_PLUGIN=" $( opencode_claude_code_auth_plugin_path) "
328+ claude_code_auth_args=(--claude-code-auth-plugin " $CLAUDE_CODE_AUTH_PLUGIN " )
329+ fi
285330
286331 log " opencode.json already exists — running additive repair..."
287332
@@ -291,6 +336,7 @@ _runtime_repair_opencode_json_additive() {
291336 --runtime opencode \
292337 --chat-bridge " $BRIDGE_ARG " \
293338 --kimaki-plugins-dir " $PLUGINS_DIR " \
339+ " ${claude_code_auth_args[@]} " \
294340 " ${managed_args[@]} " \
295341 --additive \
296342 --backup-suffix " $SUFFIX " 2>&1 ) && repair_rc=0 || repair_rc=$?
0 commit comments