🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
ADR 506: plugin secrets through userConfig with sensitive: true
Status: Accepted (implemented in PR #4587, 2026-10-29)
Issue: #4581 follow-up 1.
1. Context
Today ruflo plugins read their credentials from the process environment, and therefore from shell profiles or .env files. The main ones:
| Variable | Used by |
|---|---|
OPENROUTER_API_KEY |
ruflo-cost-tracker, metaharness redblue, bench solvers |
PINATA_API_KEY / PINATA_API_SECRET / PINATA_API_JWT |
plugin registry publishing |
RUFLO_ADMIN_TOKEN |
ruflo-x-gateway |
CGF_CALLER_TOKEN |
x-gateway federation |
SERAPHINA_METALLM_KEY |
meta-llm gateway calls |
OLLAMA_API_KEY |
local model endpoints |
No ruflo plugin declares a userConfig option with sensitive: true (none of 40+ plugin manifests).
The Claude Code plugin reference describes what userConfig with sensitive: true does:
- The value is masked as it is entered.
- It is stored in the platform's secure credential store; non-sensitive values go under
pluginConfigsin settings. - Hooks receive it as the environment variable
CLAUDE_PLUGIN_OPTION_<KEY>. - MCP and exec-form hook
argscan use${user_config.KEY}. - Shell-form hook commands, monitor commands and MCP
headersHelperrefuse${user_config.*}substitution. - Monitor processes do not receive the
CLAUDE_PLUGIN_OPTION_*variables.
2. Decision
2.1 Declare the keys
Each plugin that needs a credential, and has a path that can deliver it (2.2), declares it as a userConfig option with "sensitive": true and "required": false:
- ruflo-cost-tracker:
openrouterApiKey; - ruflo-metaharness:
openrouterApiKey.
The description says what the key is for and that it is stored in the credential store. An option that no Claude Code process of the declaring plugin can receive is not declared: it would ask users for a secret that never arrives.
2.2 Deliver it to the code that uses it
Claude Code hands an option only to the declaring plugin's own hooks and MCP servers. The OpenRouter consumers are scripts that a skill or command runs through the Bash tool, which gets no CLAUDE_PLUGIN_OPTION_* variable. So each of the two plugins carries a SessionStart command hook that runs scripts/_secret-env.cjs. The hook appends export OPENROUTER_API_KEY='…' to CLAUDE_ENV_FILE, the file whose lines Claude Code loads into every later Bash command of the session. It does so only when the option is filled in and OPENROUTER_API_KEY is not already set. The scripts then read OPENROUTER_API_KEY as before.
The trade-off is stated plainly: the key then sits in the session's environment file under ~/.claude (the bridge creates it owner-only when it is absent; a file Claude Code created keeps Claude Code's mode) and in the environment of that session's Bash commands, the same exposure as exporting it in a shell profile. What the option adds is masked entry and credential-store storage in place of a plain-text profile or .env file.
2.3 Read it through one helper
A shared helper, readSecret(name, envFallbacks), is copied into each plugin's scripts folder; plugins may not import across folders. It reads, in order:
CLAUDE_PLUGIN_OPTION_<NAME>, which is set when the code runs as one of the plugin's own hooks or servers with the option filled in;- the existing environment variables, kept for backward compatibility, for standalone CLI use, and for the variable the bridge (2.2) writes.
It never logs or echoes the value. Its error text names the option and the variable, never the value.
2.4 Never put a secret in a command line
Plugin hooks and MCP entries that need a secret take it from the environment. They never use ${user_config.KEY} substitution into argv: the value would be visible in ps, and the shell forms refuse it anyway.
2.5 Guard against regressions
A new audit, scripts/audit-plugin-secrets.mjs, runs in the existing plugin-package-audit CI job. It reads .claude-plugin/plugin.json, hooks/hooks.json, .mcp.json and .lsp.json, and fails when:
- a plugin declares a
userConfigkey whose name matches/(key|token|secret|password|jwt)/iwithoutsensitive: true; - any string, object keys included, matches a secret shape: the mods' secret screen patterns plus an OpenRouter key shape;
- a credential-named entry under an
envorheadersobject holds a literal of 16 or more characters instead of a${…}reference; ${user_config.appears in acommand,headersHelperorargsentry.
It never prints a matched value. A key shaped like a secret is shown as <redacted-key> in every path.
3. What does not change
- The npm publish token and the helpers signing key stay in GCP Secret Manager. They belong to maintainer tooling, not to plugins.
- Environment variables keep working, so no user is broken. A variable the user exported always wins over the option.
- ruflo-x-gateway keeps
RUFLO_ADMIN_TOKENfrom the environment of the deployed gateway (see 5).
4. Verification
- The audit is unit-tested with fixtures for each rule, including negative controls (
${user_config.…}and${VAR}references, short and non-credential values) and a secret in key position whose output must not contain it. - The helper and the bridge are unit-tested: option over environment, fallback order, no value in error text, shell quoting that round-trips through bash, refusal of multi-line values, owner-only env file, and byte-identical copies.
- Live: with
openrouterApiKeysupplied as a plugin option, a Bash tool command in the same session resolves the key fromOPENROUTER_API_KEY.
5. Implementation notes
- Review fix (PR #4587). The first version declared the options and read
CLAUDE_PLUGIN_OPTION_*in the scripts, but no consumer was launched in a way that receives it: the Bash tool gets no plugin options, themetaharness_redblueMCP tool runs inside ruflo-core's server (another plugin), and the gateway runs as a deployed service. The SessionStart bridge (2.2) was added, and the x-gatewayadminTokenoption was removed. - x-gateway. The gateway reads
RUFLO_ADMIN_TOKENin a server started from its Dockerfile and reached athttps://x.ruv.ioover HTTP MCP. No Claude Code process of the plugin ever runs that server, so no option can reach it. Its admin token stays an environment variable of the deployment. - Where the helpers live.
scripts/_secret.mjs(readSecret,secretSource,secretHint,optionEnvName) andscripts/_secret-env.cjs(bridge,bridgeLines) in ruflo-cost-tracker and ruflo-metaharness. Tests keep each pair of copies byte-identical. - Env var name. Claude Code 2.1.289 derives the variable as
CLAUDE_PLUGIN_OPTION_+ the key with non-identifier characters replaced by_and upper-cased, soopenrouterApiKeyarrives asCLAUDE_PLUGIN_OPTION_OPENROUTERAPIKEY.optionEnvNamedoes the same. - Consumers. cost-tracker
openrouter.mjsusesreadSecret('openrouterApiKey', ['OPENROUTER_API_KEY'])forkeyandgeneration. Through the Bash tool it finds the bridgedOPENROUTER_API_KEY.creditsneeds a management key, which has no option, and stays environment-only. metaharness_redblue.mjshands the option to the redblue child asOPENROUTER_API_KEYin its environment (never argv) only when that variable is not already set. A redblue run started from a skill gets the bridged variable. - What the bridge does not reach.
CLAUDE_ENV_FILEfeeds the Bash tool only; MCP servers do not load it. So themetaharness_redblueMCP tool (ruflo-core's server) still needsOPENROUTER_API_KEYexported before Claude Code starts. A plugin-owned stdio MCP server withenv: {"OPENROUTER_API_KEY": "${user_config.openrouterApiKey}"}would be the confined alternative. It would also keep the key out of the Bash environment. It is left for a follow-up because it adds a server and a tool surface. The bridge was verified on Linux only; where the Bash tool does not loadCLAUDE_ENV_FILE, the environment variable remains the path. - Bridge rules. The hook command is a
node -ebootstrap (no shell expansion, no${user_config}), prints nothing, and never fails the session. Values are single-quoted with'\''escaping; a value containing a newline, carriage return or NUL is refused rather than written. When the bridge creates the file it uses mode0600; it does not change the mode of a file Claude Code already created. - Audit patterns. The audit parses
COMMON_SECRETSout ofplugins/ruflo-agentdb/hooks/screen.tsinstead of copying it (a.mjscannot import the.ts), and fails when it parses no rules or finds no manifests.LOCAL_SECRETSaddssk-or-v1-…(OpenRouter), which the shared screen does not know. The env/headers rule covers tokens with no recognisable shape (admin, CGF, Seraphina). Its 16-character floor mirrors the screen'skey assignmentrule and leaves values like"TOKEN_MODE": "readonly"alone. - Name rule false positives.
/(key|token|secret|password|jwt)/iwill also match future non-secret option names such as a token budget (maxTokens). No current option matches; such an option must be renamed or declared sensitive. - Live checks. Two haiku runs (Claude Code 2.1.289), each with the option supplied through
--settingspluginConfigsandOPENROUTER_API_KEYunset. The first used a probe plugin with this SessionStart hook. The second used the realplugins/ruflo-cost-tracker. In both, a Bash tool command resolved the key withsecretSource=OPENROUTER_API_KEY, and the value matched. An earlier run showedCLAUDE_PLUGIN_OPTION_OPENROUTERAPIKEYin the SessionStart and Stop hook environments. Storing the value in the credential store needs the interactive/pluginprompt, which a headless run cannot drive.