Skip to content

feat(plugins): let Claude Code use saved credentials without seeing them - #7341

Closed
t0saki wants to merge 15 commits into
volcengine:mainfrom
t0saki:feat/plugin-secret-exec
Closed

t0saki wants to merge 15 commits into
volcengine:mainfrom
t0saki:feat/plugin-secret-exec

Conversation

@t0saki

@t0saki t0saki commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Description

Lets Claude Code use a credential saved in OpenViking Privacy without the value entering the conversation, as designed in the RFC at #7335 (section 7 and appendix A).

Today the model has to call privacy_resolve, read the plaintext, and write it into a command. With secretExec on, the model writes the privacy reference straight into a Bash command. A PreToolUse hook hands that command to a runner, which resolves the reference, passes the value to the child process through an environment variable, and replaces any echo of the value in the output with the reference again. The transcript, the permission prompt and OpenViking's capture only ever contain the reference.

The switch is off by default. Commands without a reference are not touched.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

RFC: #7335. Related: #7213, which proposes ov privacy run. That command does the same job as the runner here, so the hook can call it instead once it exists.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • examples/memory-plugin-shared/lib/secret-exec.mjs: the shared logic, so other harnesses only need a thin adapter later.
    • Finds references in a command and rewrites each into an environment-variable expansion that fits its quoting context (unquoted, double-quoted, single-quoted, $'...', unquoted heredoc). A reference inside a quoted-delimiter heredoc is refused. Because values are never spliced into shell text, a scanner mistake cannot become an injection.
    • Masks output as a stream, holding back only a tail that could be the start of a value, so a value split across chunks is still caught.
    • Builds the guard lines described below.
  • Claude Code hook: rewrites a Bash command that contains a reference into guard lines plus one runner call. The hook does no network I/O and never holds a value. It also denies privacy_resolve with a reason that tells the model to write the reference into the command, and adds a usage note at session start.
  • Claude Code runner (scripts/secret-run.mjs): resolves each reference with the user's own key, runs the rewritten script in the shell Claude Code's Bash tool would pick, and masks stdout and stderr. If any reference cannot be resolved it exits non-zero without running the command.
  • Guard lines keep permission rules working. Claude Code matches permission rules against the rewritten command. With only the runner call, the original command sits inside a quoted argument where rules cannot see it, so a deny rule such as Bash(rm:*) would stop applying and allowing the runner once would allow everything. The hook therefore prepends one false && <segment> line per top-level segment of the original command. Those lines never run, but Claude Code checks them like any other, so the permission needed is that of the original command plus that of the runner.
    • Commands the hook cannot split with certainty (heredocs, $( ), backticks, subshells, compound statements) get ask instead of a guess.
    • A command in which the model wrote the runner call itself also gets ask.
    • The hook never returns allow. secretExecApproval: ask asks on every use.
  • Configuration: secretExec can be turned on in the user's own config (ovcli.conf plugin section or OPENVIKING_SECRET_EXEC), not from a file committed to a repository.
  • Docs: agent-integration and guide pages in English and Chinese, the shared-library README, and the RFC document with its figures under bot/docs/zh/design/.
  • Generated copies: the shared module is synced into the plugins that vendor it, which is why the diff touches several plugin directories.

Testing

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes

  • I have tested this on the following platforms:

    • Linux
    • macOS
    • Windows
  • Memory plugin suite, run the way pr.yml runs it, on macOS: 1618 tests, 1600 passed, 9 failed, 9 skipped. The same 9 fail on the base branch without these changes: 5 in install-tui.test.mjs and 4 in the pi extension's takeover-session-manager.test.mjs. secret-exec.test.mjs passes 29 of 29.

  • Installer tests: 24 passed, 0 failed.

  • The shared-copy generator leaves the tree clean.

  • One new test failed on macOS at first: stock macOS bash is 3.2 and cannot parse |&. The last commit runs the non-POSIX cases only on shells that can parse them.

  • End to end on Linux with bash, on Claude Code 2.1.321 in default and bypass modes, with the real hook and runner and a simulated OpenViking server. The scenario table is in the RFC, appendix A.4. In short: allowed commands run and the model sees only references; a deny rule on any segment still denies, in bypass mode too; an unallowed segment or an unallowed runner goes to approval; $( ) and a model-written runner call both get ask.

  • Not done: an end-to-end run on macOS or with zsh as the tool shell, and auto mode.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

None.

Additional Notes

  • This branch carries the RFC document commits as its base, so the diff includes bot/docs/zh/design/rfc-agent-secret-use.md and five figures. The gateway PR carries the same commits.
  • The guard lines rely on Claude Code statically matching rules against branches that never execute. That is observed behaviour on 2.1.321, not a documented guarantee.
  • The plugin alone does not stop pasted keys or other tools' output from reaching the model provider. That guarantee needs the gateway side.
  • The runner masks stdout and stderr only. A value the child writes to a file and a later command prints is not masked by the plugin.
  • Commands run through the runner do not carry cd over to later commands, and shell aliases and functions are unavailable.

t0saki and others added 13 commits November 10, 2026 04:24
Draft RFC for keeping registered credentials out of model upstreams while
agents can still use them: seal values into privacy references on the wire
(gateway), unseal only at the tool execution boundary (harness runner).
The hook gives no permission decision unless secretExecApproval is ask, and
never returns allow.
Lead with a one-minute summary and a running example, explain terms on
first use, and replace the mermaid sketch with five SVG figures. Move the
RFC next to the existing one under bot/docs/zh/design.
…ew findings

Wrapping a command in the runner hides it from Claude Code's permission
rules, so the hook now prepends never-executed guard lines that expose
each original segment to rule matching (verified on Claude Code 2.1.321).
Also corrects overstated claims found by cold readers, defines gateway
terms on first use, and redraws the figures accordingly.
…ttled

Gateway: its own additions (recall, tool results) are sealed before they
are stored, with the egress sweep as the second line; unsealing needs a
tools-bearing request, the canonical spelling and a value of 6+
characters; exemptions and JSON spellings as implemented; server 0.5.2.

Plugin: the hook also asks when a command names the runner itself, the
runner line is written so a rule for it is easy, and the guard lines were
verified end to end on Claude Code 2.1.321 (scenario table in section 11).
Lead with goals, non-goals, the three switches and the behaviour changes they bring. Gateway and plugin internals follow as detailed design, and the Claude Code guard line, the harness hook comparison and the acceptance notes move to appendices.

Settle the open questions: privacy_resolve stays as is on the server with a recommendation to stop exposing it, new profiles keep seal_secrets off, and the skill category stays out of sealing with the consequence listed under known limitations. The two laws become invariants I1 and I2, in the text and in the architecture figure.
Add secret exec, the plugin layer of the agent-secret-use RFC (section 7).
It is off unless secretExec is set, and no workspace file can set it.

A separate PreToolUse hook wraps a Bash command that carries a credential
reference as '<node>' '<secret-run.mjs>' '<command>', keeping every other
input field. It never reaches the network or a value, gives no permission
decision unless secretExecApproval is ask, never allows, and denies
privacy_resolve. The runner resolves every reference through
/api/v1/privacy-configs/resolve and runs nothing unless all of them
resolve. It hands the values over as OV_SECRET_<n>, expanded for the
quoting each reference sat in so no value becomes shell code, and masks
them back to their references on stdout and stderr. Session start tells
the model how to write references.

The logic lives in memory-plugin-shared/lib/secret-exec.mjs as pure
functions, so another host needs only an envelope. The URI guard no
longer takes the viking:// URI inside a privacy reference for a path.
The hook skipped a command that already named the runner before it
looked at secretExecApproval, so under `ask` a command the model wrapped
itself, or one that assembled its reference at run time, ran without
confirmation. A command that starts a runner is still never wrapped
again, but `ask` now confirms it. The runner also resolves nothing while
secretExec is off, whoever starts it.

A value the environment cannot carry (a NUL byte) made spawn() throw
with the value in its message, past the masker. The spawn error now
reports only its code, and the resolver refuses such a value, and any
non-text one, with a reason that says so instead of "no value is stored".

The scanner read the `<<` of `$((1<<4))` as a here-document, so every
later line counted as its body and got an unquoted expansion that split
a value holding blanks past the masker. `$(( ))` and `(( ))` are now
arithmetic, and a here-document body is a frame of its own, so `$( )` and
backticks inside one get a quoted expansion too.

Smaller fixes: a value saved under two fields masks to the smaller
reference, as the Gateway seals it; enum settings match in any case, so
`ASK` no longer falls back to `inherit`; the runner uses the shell
Claude Code's Bash tool picks (CLAUDE_CODE_SHELL or SHELL when bash or
zsh, else zsh or bash from PATH) instead of dash for SHELL=/bin/sh; and
session start adds the usage note even when memory is off. The docs fix
the hook count, a duplicate README anchor, and claims that went past
what masking and `ask` do.
Claude Code matches permission rules against the rewritten command, where
the original sits inside a quoted string. A Bash(rm:*) deny rule did not
see it, and allowing the runner allowed every command with a reference.

The hook now puts one `false && <pipeline>` line per top-level pipeline in
front of the runner. The line never runs, but Claude Code checks it like
the original, so the rewritten command needs what the original needs plus
the runner. Checked end to end on Claude Code 2.1.321, default and bypass
modes: allowed runs unprompted, a deny rule on any part denies, an
unlisted part or runner goes to approval.

The hook asks instead when it cannot vouch for guard lines (here-document,
$( ), subshell, compound command) and when the command names the runner
itself. The runner's node and script paths go unquoted where they can, so
a rule for the runner is easy to write.
@t0saki
t0saki marked this pull request as ready for review November 11, 2026 11:38
Copilot AI balanced review requested due to automatic review settings November 11, 2026 11:38
# Conflicts:
#	examples/magpie-memory-plugin/package.json

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical shell-parsing flaws allow premature command execution and permission-guard bypasses, while an exhausted session-start budget can permit uncapped archive injection.

3 open issues
2 files not reviewed
  • examples/dsh-memory-plugin/package-lock.json: Generated file
  • examples/pi-coding-agent-extension/package-lock.json: Generated file
What changed in this PR

Adds opt-in secret execution to the Claude Code memory plugin, using shared infrastructure to resolve saved credential references at execution time and mask matching values in command output.

Changes:

  • Adds command rewriting, permission guards, credential resolution, and streaming output masking.
  • Integrates Claude Code hooks, session guidance, configuration controls, and regression tests.
  • Updates English and Chinese documentation, architecture diagrams, generated modules, and plugin versions.
File Description
examples/​pi-coding-agent-extension/​package.json Bumps extension version.
examples/​pi-coding-agent-extension/​package-lock.json Synchronizes lockfile version.
examples/​opencode-plugin/​package.json Bumps plugin version.
examples/​memory-plugin-shared/​uri-guard.test.mjs Tests credential-reference exclusions.
examples/​memory-plugin-shared/​secret-exec.test.mjs Tests rewriting, guards, masking, and execution.
examples/​memory-plugin-shared/​README.md Documents shared secret-exec APIs.
examples/​memory-plugin-shared/​plugin-known-keys.test.mjs Tests workspace restrictions on secret settings.
examples/​memory-plugin-shared/​plugin-config.test.mjs Tests secret-exec configuration sources.
examples/​memory-plugin-shared/​lib/​uri-guard.mjs Excludes privacy references from URI notices.
examples/​memory-plugin-shared/​lib/​secret-exec.mjs Implements shared secret-exec functionality.
examples/​memory-plugin-shared/​lib/​config-schema.mjs Adds secret settings and case-insensitive enums.
examples/​magpie-memory-plugin/​package.json Bumps plugin version.
examples/​dsh-memory-plugin/​package.json Bumps plugin version.
examples/​dsh-memory-plugin/​package-lock.json Synchronizes lockfile version.
examples/​codex-memory-plugin/​scripts/​shared/​config-schema.mjs Synchronizes shared configuration schema.
examples/​codex-memory-plugin/​.codex-plugin/​plugin.json Bumps plugin manifest version.
examples/​claude-code-memory-plugin/​scripts/​shared/​uri-guard.mjs Synchronizes privacy-reference exclusions.
examples/​claude-code-memory-plugin/​scripts/​shared/​secret-exec.mjs Vendors the shared secret-exec implementation.
examples/​claude-code-memory-plugin/​scripts/​shared/​config-schema.mjs Synchronizes shared configuration schema.
examples/​claude-code-memory-plugin/​scripts/​session-start.mjs Adds secret-exec guidance to startup context.
examples/​claude-code-memory-plugin/​scripts/​secret-run.mjs Connects the runner to configuration and transport.
examples/​claude-code-memory-plugin/​scripts/​secret-exec.test.mjs Tests hook and runner integration.
examples/​claude-code-memory-plugin/​scripts/​secret-exec.mjs Adds the PreToolUse adapter.
examples/​claude-code-memory-plugin/​scripts/​marketplace.test.mjs Verifies hook registration and entrypoints.
examples/​claude-code-memory-plugin/​README.md Documents setup, permissions, and limitations.
examples/​claude-code-memory-plugin/​README_CN.md Adds Chinese setup and limitation guidance.
examples/​claude-code-memory-plugin/​package.json Bumps plugin package version.
examples/​claude-code-memory-plugin/​hooks/​hooks.json Registers the secret-exec hook.
examples/​claude-code-memory-plugin/​.claude-plugin/​plugin.json Bumps marketplace plugin version.
examples/​agent-hook-plugin/​plugin.json Bumps shared host-plugin version.
examples/​agent-hook-plugin/​hosts/​zcode/​openviking.integration.json Synchronizes ZCode integration version.
examples/​agent-hook-plugin/​hosts/​trae/​openviking.integration.json Synchronizes TRAE integration version.
examples/​agent-hook-plugin/​hosts/​kimicode/​openviking.integration.json Synchronizes Kimi integration version.
examples/​agent-hook-plugin/​hosts/​kimicode/​kimi.plugin.json Synchronizes Kimi plugin version.
examples/​agent-hook-plugin/​hosts/​cursor/​openviking.integration.json Synchronizes Cursor integration version.
examples/​agent-hook-plugin/​hosts/​codebuddy/​plugin.json Synchronizes CodeBuddy plugin version.
docs/​zh/​guides/​06-mcp-integration.md Explains reference-based credential use in Chinese.
docs/​zh/​agent-integrations/​18-plugin-development.md Documents adapter responsibilities in Chinese.
docs/​zh/​agent-integrations/​16-capability-reference.md Updates Chinese capability and hook listings.
docs/​zh/​agent-integrations/​02-claude-code.md Adds Chinese secret-exec integration guidance.
docs/​en/​guides/​06-mcp-integration.md Explains reference-based credential use.
docs/​en/​agent-integrations/​18-plugin-development.md Documents adapter responsibilities.
docs/​en/​agent-integrations/​16-capability-reference.md Updates capability and hook listings.
docs/​en/​agent-integrations/​02-claude-code.md Adds secret-exec integration guidance.
bot/​docs/​zh/​design/​images/​secret-use-plugin.zh.svg Illustrates hook and runner execution.
bot/​docs/​zh/​design/​images/​secret-use-gateway.zh.svg Illustrates gateway credential handling.
bot/​docs/​zh/​design/​images/​secret-use-deployments.zh.svg Compares deployment protection boundaries.
bot/​docs/​zh/​design/​images/​secret-use-before-after.zh.svg Compares plaintext and reference-based workflows.
bot/​docs/​zh/​design/​images/​secret-use-architecture.zh.svg Illustrates plugin and gateway responsibilities.

Review effort: Balanced

…rchive cap

- A `#` right after a backslash escape is part of a word, not a comment, in both the splitter and the rewriter, so `a\;#x; rm target` still guards `rm target`.
- Continue a pipeline across a newline only after a real `|` operator, not an escaped `\|`.
- Never pass 0 (no cap) to the archive section when sessionStartMaxBytes is set and the secret-exec note has used the budget.
@t0saki

t0saki commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #8384. The hook that rewrote commands into a runner is no longer needed: ov privacy run is in main and the model calls it itself, and the Claude Code plugin (and now the Pi extension) seals user input and tool results and unseals tool arguments at the harness's own events. Details are in the RFC supplement: #7335 (comment)

@t0saki t0saki closed this Nov 24, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants