feat: add opencode plugin support - #46
Conversation
Adds a native opencode plugin that routes Snowflake prompts to Cortex Code CLI, bringing opencode to parity with the existing Claude Code and Codex integrations. New files: - plugins/cortex-code/.opencode/plugins/snowflake-cortex.ts Custom tool (cortex_run) using @opencode-ai/plugin's tool() helper. Calls execute_cortex.py via Bun shell in --codex mode. Also exports a tool.execute.before hook that intercepts direct snow sql / snowsql bash calls and redirects them through cortex. Script dir resolved via multi-location fallback (repo dev vs installed). - plugins/cortex-code/.opencode/rules/snowflake.md LLM routing rules that replace the UserPromptSubmit hook (opencode has no pre-LLM hook equivalent). Mirrors prompt_filter.py keyword logic. Instructs the LLM to call cortex_run for Snowflake work. Modified files: - execute_cortex.py: detect OPENCODE env var, set CORTEX_CODE_ENTRYPOINT="OpenCode Plugin" for analytics/tracking. - install.sh: --with-opencode flag; copies plugin TS + router scripts to ~/.config/opencode/plugins/ and rules to ~/.config/opencode/rules/. - tests/run-tests.sh: new "OpenCode plugin" section with 8 checks. - README.md + plugins/cortex-code/README.md: opencode quick-start and install instructions. .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <noreply@snowflake.com>
There was a problem hiding this comment.
Hi!
Thanks for your contribution. Overall it's a solid addition; opencode parity makes sense and the architecture (rules file + hook) is pragmatic given no UserPromptSubmit equivalent.
Questions / Concerns:
-
Bun dependency — snowflake-cortex.ts uses Bun.$ shell syntax. Does opencode always run on Bun? If someone has opencode on Node, this breaks silently. Should document or add a Node fallback.
-
Router script duplication — install.sh --with-opencode copies entire scripts/router/ to ~/.config/opencode/plugins/cortex-code-router/. Updates require re-running installer. No auto-update. Worth noting in docs.
-
No functional tests for TS plugin — 8 structural checks verify files exist, but nothing tests actual cortex_run execution or hook behavior.
-
Type assertion in hook — (output as { args?: { command?: string } }).args?.command is a blind cast. If opencode changes hook shapes, this silently fails.
-
Version sync — PR doesn't bump version. Since v3.3.1 just landed, rebase and bump needed.
-
Hook UX — tool.execute.before throws an error on direct snow sql calls. Would silent re-route (calling cortex_run internally) be better UX than erroring?
Cheers,
Dash
Summary
cortex_runcustom tool (TypeScript,@opencode-ai/plugin) callsexecute_cortex.pyin--codexmode via Bun shell — reusing all existing Python router scripts unchangedUserPromptSubmithook) + atool.execute.beforehook that intercepts directsnow sql/snowsqlbash callsbash install.sh --with-opencodeinstalls globally to~/.config/opencode/plugins/and~/.config/opencode/rules/Files changed
plugins/cortex-code/.opencode/plugins/snowflake-cortex.tscortex_runtool +tool.execute.beforehookplugins/cortex-code/.opencode/rules/snowflake.mdUserPromptSubmithook)plugins/cortex-code/scripts/router/execute_cortex.pyOPENCODEenv var detection →CORTEX_CODE_ENTRYPOINT="OpenCode Plugin"install.sh--with-opencodeflag +install_opencode_plugin()functiontests/run-tests.shplugins/cortex-code/README.mdREADME.mdArchitecture note
opencode has no pre-LLM hook equivalent to Claude Code's
UserPromptSubmit, so the keyword filter cannot intercept prompts before the LLM sees them. The routing is instead:snowflake.md) — loaded globally, instructs the LLM when to callcortex_runusing the same keyword set asprompt_filter.pytool.execute.beforehook — hard-blocks directsnow sql/snowsqlbash calls, redirecting tocortex_run(hard enforcement layer)In practice the LLM reliably routes to
cortex_rungiven the rules file. The hook catches the edge case where it tries to use Snowflake CLI directly.Test plan
bash tests/run-tests.sh— all 37 structural checks pass (8 new opencode checks included)bash tests/run-tests.sh --unit— envelope policy + plugin unit tests passbash install.sh --with-opencode→ confirm files land in~/.config/opencode/plugins/and~/.config/opencode/rules/cortex_runis calledbashwithsnow sql -q "SELECT 1"→ hook blocks and redirects.... Generated with Cortex Code