OpenCode
Use the SonarQube CLI to install a secrets plugin, the SonarQube MCP Server, and Sonar Vortex analysis and Vortex context for OpenCode.
sonar integrate opencode installs a secrets-scanning plugin for OpenCode and configures the SonarQube MCP Server. On a connection with a Sonar Vortex subscription, it also offers Vortex analysis and Vortex context.
In an interactive terminal, the command prompts you to install each component:
A check before OpenCode reads a file or folder (the
execute.beforehook on thereadtool). When that path contains a secret, the read is blocked, and OpenCode is told not to open it another way.A check on the prompt (the
prompthook) that masks each reported secret, adds a[Sonar]notice to the message, and still sends the message.The SonarQube MCP Server, which lets OpenCode fetch projects, issues, and rules.
Vortex (when your connection has a Vortex subscription: SonarQube Cloud Team (annual) or Enterprise plan, or SonarQube Server 2026.5 or newer Enterprise and Data Center editions): one prompt that installs Vortex analysis and Vortex context. Accepting it adds:
A plugin that runs fast
STANDARDanalysis after eacheditorwriteand appends findings to the tool output. The edit is not blocked.End-of-turn Vortex analysis instructions in
~/.config/opencode/AGENTS.mdthat tell OpenCode to runDEEPanalysis on every file it modified in one command (repeat--filefor each path, or use the git change set)A Vortex context skill at
~/.config/opencode/skills/sonar-context-augmentation/SKILL.md, plus instructions in the sameAGENTS.mdfile that tell OpenCode to load the skill and usesonar context
Choose OpenCode from the bare sonar integrate menu, or run sonar integrate opencode directly.
Pass --non-interactive to accept the secrets plugin, the MCP server, and Vortex when eligible without prompts (see Non-interactive install).
Prerequisites
OpenCode 2.0 or newer is installed. The plugins use the OpenCode 2.0 plugin API and stay inactive on OpenCode 1.x and older.
sonaris on thePATHthat OpenCode uses. If the secrets plugin cannot runsonar, it blocks the read or replaces the message instead of sending the original text.
Install
Install once for this machine:
The command writes ~/.config/opencode/plugins/sonar-secrets.ts and ~/.config/opencode/opencode.json. When you accept Vortex, it also writes ~/.config/opencode/plugins/sonar-sqaa.ts, ~/.config/opencode/skills/sonar-context-augmentation/SKILL.md, and managed snippets in ~/.config/opencode/AGENTS.md. See Project versus global scope.
Earlier CLI versions wrote the secrets plugin as ~/.config/opencode/plugins/sonar.ts. The CLI now writes it as sonar-secrets.ts and does not remove the old file, so delete sonar.ts if it exists.
The plugin files and the Vortex context skill are managed by the CLI. Do not edit them by hand. Re-run sonar integrate opencode to refresh the plugins, the skill, the Vortex instructions, and the MCP server entry. The command keeps your other keys in opencode.json. OpenCode 2.0 does not load plugins written for OpenCode 1.x, and it does not warn you when it ignores them. Re-run the command after you upgrade, then restart OpenCode. Until the plugins are replaced, secrets scanning and Vortex analysis stay inactive.
If opencode --version reports a version before 2.0, the command still finishes setup and then prints one warning that names that version, for example OpenCode 1.19.3 detected. SonarQube setup is complete, but plugins are inactive until you upgrade to OpenCode 2.0. Upgrade OpenCode to activate the plugins this command wrote. The warning does not ask you to run the command again. It is skipped for OpenCode 2.0 or newer, and when the CLI cannot read a version.
What the command does
The integrator runs in three phases:
Discovery and validation. It locates your project's config using the project key auto-detection chain and verifies the token.
Health check and repair. It calls SonarQube to confirm the token, organization, and project are valid. If the token is broken and you're running interactively, it offers to refresh it.
Installation. For each component (secrets plugin, MCP server, and Vortex when eligible), the CLI either prompts you to install it, skips it with an explanation, or accepts it automatically in non-interactive mode. Before writing files, it shows a What will be installed summary. In interactive mode, press Enter to confirm. Then it writes the accepted files.
A common skip reason is that your connection does not have a Vortex subscription (only available with SonarQube Cloud Team (annual) or Enterprise plan, or SonarQube Server 2026.5 or newer Enterprise and Data Center editions).
Secrets plugin
execute.before (read only)
Scans the file or folder before OpenCode reads it. A secret blocks the read and tells OpenCode not to open it another way.
prompt
Scans the prompt. Secrets that can be masked are replaced, a [Sonar] notice is added, and the message is sent.
Both checks fail closed. When any of the following is true, the plugin blocks the read or replaces the message instead of letting it through:
You are not authenticated, or the secrets analyzer is missing
The scan crashes or times out
sonaris missing fromPATH, the plugin cannot read the hook response, or the response does not include a true or falseblockvalueA secret in a message cannot be masked
When a message is blocked, the original text is replaced with a [Sonar] Message blocked: placeholder and is not sent. The placeholder says the original content was not sent. OpenCode 2.0 has no hidden note for the plugin, so this placeholder is the notice you see.
When a secret is masked, the message includes this line: [Sonar] A secret was detected in this message and masked before it was sent.
Any tool other than read is left unchanged. That includes grep and shell, so OpenCode can still reach a blocked file through them. A message with no secrets is left unchanged.
Note: A multi-line private key may only have its first line masked. The scanner reports that line, so the rest of the key can remain in the message until the scanner reports the full span.
Vortex analysis
When you accept Vortex, sonar integrate opencode installs these OpenCode touchpoints:
~/.config/opencode/plugins/sonar-sqaa.tsruns after a completededitorwrite. It analyzes that file atSTANDARDdepth and appends findings to the tool output. OpenCode is told to report the findings and to say they come from Sonar Vortex analysis. The hook never blocks the edit. A missing project, a scan error, orsonarmissing fromPATHstays silent. On HTTP 403, OpenCode can show the same unavailable notice as the other Vortex analysis hooks. See integrations/README.md.A managed snippet in
~/.config/opencode/AGENTS.mdrequires an end-of-turnDEEPrun: onesonar analyze agentic --depth DEEPcommand covering every file OpenCode modified that turn. The CLI auto-detects the current git branch, and each file is analyzed against the project that owns it, so the instructions omit--projectand--branch. In a repository with several projects, they tell OpenCode to run that command from a directory that contains every file changed in the turn, usually the repository root. Re-runsonar integrate opencodeso an existing snippet picks up that paragraph. The edit hook analyzes the edited file against the project that owns it, and stays silent when no project of the active connection owns the file. If analysis reports that no project is configured, the instructions tell the agent to stay silent for the rest of the session instead of repeating a skip notice. See Files and the project root.
For an overview of Vortex analysis, see Vortex analysis.
Vortex context
OpenCode has no session-start hook. When you accept Vortex, the CLI installs Vortex context as a skill and instructions:
~/.config/opencode/skills/sonar-context-augmentation/SKILL.mdtells OpenCode how to callsonar contextfor this project's guidelines, architecture, navigation, and dependencies.A second managed snippet in
~/.config/opencode/AGENTS.mdtells OpenCode to load that skill at the start of a task that reads or changes code, to runsonar context guidelines getbefore writing or editing code, and to prefersonar context navigationwhen locating symbols, callers, or usages. It also tells OpenCode to ask any subagent to load the skill first.
In a repository with several SonarQube projects, that snippet says sonar context works on one project at a time. Run it from inside a project's directory. If a command cannot determine a single project, run sonar link list --path <path> for the file or directory, then retry from that project's directory. Re-run sonar integrate opencode to add this sentence to an existing snippet. See Vortex context in a monorepo.
The CLI installs the Vortex context binary under ~/.sonar/sonarqube-cli/bin/. After that, sonar context forwards to the binary.
Note: OpenCode reads
AGENTS.mdand usesCLAUDE.mdonly whenAGENTS.mdis absent at that level. Installing Vortex creates~/.config/opencode/AGENTS.md, so OpenCode no longer readsCLAUDE.mdat that level (for example~/.claude/CLAUDE.md). To keep those instructions, copy them into~/.config/opencode/AGENTS.md.
For an overview of Vortex context, see Vortex context.
MCP server
The command adds a sonarqube entry under mcp in ~/.config/opencode/opencode.json:
OpenCode starts that local command. The file does not include a project key. sonar run mcp resolves the project when it runs.
The command leaves an existing opencode.jsonc file untouched. OpenCode merges opencode.json and opencode.jsonc, so comments in opencode.jsonc stay in place. Other keys in opencode.json, including other MCP servers, are kept.
When SONAR_USER_HOME is set before you run the command, the entry also includes an environment object with that path.
Options
--non-interactive
Non-interactive mode (no prompts).
--global, -g
Deprecated since 1.9.0. The install is already global; using the flag prints a warning and does not change the installation scope.
Where files are installed
User home
~/.config/opencode/plugins/sonar-secrets.ts, ~/.config/opencode/opencode.json, and, when Vortex is installed, ~/.config/opencode/plugins/sonar-sqaa.ts, ~/.config/opencode/skills/sonar-context-augmentation/SKILL.md, plus snippets in ~/.config/opencode/AGENTS.md
Shared binaries
~/.sonar/sonarqube-cli/bin/ (the secrets analyzer, and the Vortex context binary when Vortex is installed)
State for the integration is recorded in ~/.sonar/sonarqube-cli/state.json. See State and storage.
Restart OpenCode
OpenCode loads plugins and MCP configuration when it starts. Restart OpenCode after you install or remove them.
Verify it works
Test a file read
Create a file in your project with a fake-looking but secret-shaped value:
Ask OpenCode to read it: "Read secrets.js."
OpenCode should block the read and explain that the file contains a secret.
After you've confirmed the plugin is active, delete the test file.
Test a message
Send OpenCode a message that includes the same kind of fake token. The token should be masked before the message is sent, and the message should include a [Sonar] line that a secret was masked.
Test the MCP server
In OpenCode, ask: "Use the SonarQube MCP Server to list my open projects." OpenCode should call SonarQube and return your project list. If it does not, run sonar auth status to confirm the token is healthy and restart OpenCode.
sonar system status lists the OpenCode integration and reports MCP server status as CONFIGURED, NOT CONFIGURED, or CONFIGURED / INVALID CONFIG. It does not print a separate secrets-hook health line for this plugin. When the MCP entry is invalid, status recommends sonar integrate opencode. See Check system status.
Test Vortex analysis
Make a code change through OpenCode (for example, ask it to edit a file). After the edit, OpenCode should receive the analysis on the tool output. Before ending the turn, it should run DEEP analysis on the modified files. This requires a Sonar Vortex analysis subscription.
Test Vortex context
After you accept Vortex, ask OpenCode to look up a coding guideline or a symbol in this project. It should load the sonar-context-augmentation skill and call sonar context. This requires a Sonar Vortex context subscription.
Non-interactive install
For provisioning scripts, dotfiles, and onboarding automation:
In non-interactive mode the CLI does not prompt for feature selection, install confirmation, token repair, or feature removal. When you authenticate with environment variables, integrate commands also run in non-interactive mode even without the flag. Every component that is not explicitly skipped is installed automatically, including Vortex when your connection has a Vortex subscription. Run sonar auth status afterward to confirm everything is configured correctly.
Uninstall
Run sonar integrate opencode again in an interactive terminal. For each installed feature, the CLI asks Keep?: answer No, confirm Proceed with removal?, and the CLI removes that feature and its state. Remove the secrets plugin, Vortex, and the MCP server separately. Vortex is removed as one unit (the analysis plugin, the Vortex context skill, and the managed snippets in AGENTS.md). See integrations/README.md for the full flow.
For a manual cleanup or non-interactive environments:
Delete
~/.config/opencode/plugins/sonar-secrets.ts. If Vortex was installed, also delete~/.config/opencode/plugins/sonar-sqaa.tsand~/.config/opencode/skills/sonar-context-augmentation/SKILL.md. Also delete~/.config/opencode/plugins/sonar.tsif an earlier CLI left it there.Remove the managed Vortex snippets from
~/.config/opencode/AGENTS.md(analysis and context). Leave any other content in that file.Remove the
sonarqubeentry undermcpin~/.config/opencode/opencode.json. Leave other keys, other MCP servers, and anyopencode.jsoncfile in place.Remove the OpenCode entry from
~/.sonar/sonarqube-cli/state.json(underintegrations.installed).
See Uninstalling for the full removal procedure.
Related pages
Last updated
Was this helpful?

