Claude Code plugin

Stops your coding agent from deleting, leaking or dropping things. Records everything else.

This repo is also a Claude Code plugin marketplace named shield-kya. It ships one plugin, kya.

What the plugin does, and does not do

Install (one user)

/plugin marketplace add The-Pixel-Boys/shield-kya
/plugin install kya@shield-kya

Or from a shell: claude plugin marketplace add The-Pixel-Boys/shield-kya, then claude plugin install kya@shield-kya.

The plugin ships three things:

  1. SessionStart runs node ${CLAUDE_PLUGIN_ROOT}/scripts/bootstrap.mjs. It installs @shield-agent/kya at the version of the plugin manifest (.claude-plugin/plugin.json, equal to the kya release) once into ${CLAUDE_PLUGIN_DATA} (about 6 s) and checks it on later sessions (files, version, and a load check). It never edits your settings or permissions.
  2. PreToolUse (every tool) runs node ${CLAUDE_PLUGIN_ROOT}/scripts/kya.mjs hook --host claude. kya.mjs finds the installed copy in ${CLAUDE_PLUGIN_DATA} and runs it in the same process. No npx and no npm or registry traffic at hook time. The hook costs about 0.2 s per tool call.
  3. MCP server shield-kya, started the same way (node ${CLAUDE_PLUGIN_ROOT}/scripts/kya.mjs serve-mcp --stdio).

Every command line names one literal script path under ${CLAUDE_PLUGIN_ROOT} as the first argument, with no shell, no inline code and no computed path. This is the shape the Claude plugin directory validator accepts. The installed copy path lives inside kya.mjs, not in a command. kya.mjs removes KYA_API_KEY and SHIELD_API_KEY from its environment before kya starts, so the plugin never uses a hosted-plane key from your machine. Before it removes them, it sets KYA_HOSTED_LINKED=1 when either one was non-empty. That flag says only that a key existed on your machine; the key itself is never copied, stored or sent. The opt-in usage telemetry reads the flag, so a plugin user with a key still reports hostedLinked=true. Hosted users are not affected: the hosted hook needs --plane-config, not this plugin. The MCP config also passes CLAUDE_PLUGIN_DATA in the server env, because older Claude Code versions may not export it to MCP servers.

The MCP server in this plugin sets KYA_OFFLINE=1 and KYA_BASE_URL=http://127.0.0.1:1. What that guarantees: neither the hook nor the server makes hosted-plane calls, because the only control-plane URL they know is an unroutable loopback port and kya.mjs gives them no credential. kya.session_ingest and the Hold-request tool still try that URL and fail locally; they do not stay offline by themselves (making --offline refuse them in serve-mcp is a CLI follow-up). What it does not guarantee: no network at all. A notify webhook in the user config or in a project’s .kya/config.json receives record fields (tool id, decision, reason, session) when a call is denied, from both the hook and the MCP server; OTLP export and opt-in telemetry can also send. Review .kya/config.json in repositories you open, and see telemetry.md and otlp.md. For the hosted plane, connect it yourself (see claude.md).

Every manifest version follows package.json; pnpm sync:version rewrites them and node scripts/check-version-pins.mjs checks them. The Claude plugin hooks carry no version pin of their own: the bootstrap reads the manifest version. (Codex, Copilot and Gemini pass an explicit pin argument to the same script.)

Install hardening and limits

The bootstrap runs npm install into a staging directory inside the plugin data directory with an exact version pin (strict semver, no ranges), --registry=https://registry.npmjs.org/, empty --userconfig and --globalconfig files (fresh, mode 0600), every npm_config_* variable and NODE_OPTIONS removed from the npm process, and --ignore-scripts --omit=optional. It checks the staged copy (version, dist/cli.js, and a --help load check) and only then swaps it into place. The swap is a pair of renames, so a hook that starts in that instant fails open once; hooks never see a half-written tree, and a failed upgrade leaves the working copy in place (you get an update failed, keeping the previous version notice instead of NOT recording). A lock keeps concurrent sessions from installing twice; it is released on exit and on SIGTERM/SIGINT, and a lock older than 150 s is treated as stale.

Known limits: there is no sha512 integrity pin and no npm-shrinkwrap.json inside the kya package yet (planned follow-up), so transitive dependency ranges resolve fresh on each machine. HTTPS_PROXY, HTTP_PROXY and NODE_EXTRA_CA_CERTS are honored, because corporate hosts need them, and until the integrity pin lands they are part of the trust you place in the host environment. A corporate registry mirror is not honored (the install goes to the public registry).

Requirements and what you see when something is wrong

Node.js 22+ (24 recommended) and npm on the PATH of the machine that runs Claude Code. Claude Code itself does not need Node, but this plugin does: its hooks run node from that PATH. A Claude Code started from a GUI (Dock, Start menu) may not see the PATH your shell gets from nvm or fnm, so check there first. On Node 20 or 21 the plugin installs and the hook runs, with a one-line unsupported but works notice at every session start; on Node 18 or older the notice says it is not supported. Node 22 and newer print nothing.

Host trust assumption: the hook and bootstrap run under whatever node and environment Claude Code gives them. NODE_OPTIONS or a PATH shim in that environment acts on node itself, before any plugin script runs, so no command hook can defend against it. Keep the process environment under your control.

Roll out to a team (project settings)

Run kya team init at the repository root and commit the .claude/settings.json it writes. It merges these two keys and keeps the rest of the file (--dry-run shows the change first):

{
  "extraKnownMarketplaces": {
    "shield-kya": {
      "source": { "source": "github", "repo": "The-Pixel-Boys/shield-kya", "ref": "vX.Y.Z" }
    }
  },
  "enabledPlugins": { "kya@shield-kya": true }
}

vX.Y.Z is the release tag that matches the kya you ran (needs the first kya release that includes kya team; kya help --all lists team init when yours has it). Write a tag here, never a branch: this file decides what runs on every teammate’s machine. A tag is still not fixed: anyone with write access to the public repository can move it, Claude Code’s GitHub marketplace source has no commit sha pin, and the public repository has no tag protection rule today (a v* tag ruleset is recommended). The command makes no network call; check the tag exists with git ls-remote https://github.com/The-Pixel-Boys/shield-kya refs/tags/vX.Y.Z (if it does not, the plugin is skipped, not reported as an error).

What a teammate sees:

Full guide (refusals, pin upgrades, supply-chain notes, undo): team-rollout.md.

Roll out to an organization (managed settings)

kya team managed-settings prints the same two keys with the same tag pin. Admins deploy them on every machine with managed-settings.json (macOS /Library/Application Support/ClaudeCode/, Linux and WSL /etc/claude-code/, Windows C:\Program Files\ClaudeCode\), MDM, or server-managed settings. Users cannot disable a managed plugin.

To restrict users to your marketplace, pair this with strictKnownMarketplaces, copying the exact source including its ref; see team-rollout.md and the organization guide. This rollout is advisory like the plugin itself.

Hosted-plane hook for a fleet (preview, managed settings)

The plugin hook above is local only. For the hosted-plane hook, wire it per user with kya connect claude --hooks --hosted --plane-config <absolute path>, or deploy it in managed settings. A repository’s .claude/settings.json can set "disableAllHooks": true, which turns off user and plugin hooks but not managed ones. allowManagedHooksOnly (managed settings only) blocks every hook that managed settings did not deploy, including this plugin’s hooks unless the plugin is force-enabled there.

{
  "allowManagedHooksOnly": true,
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "\"/usr/local/bin/node\" \"/usr/local/lib/node_modules/@shield-agent/kya/dist/cli.js\" hook --host claude --plane-config \"/Users/you/.kya/hosted.json\"",
            "timeout": 5,
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

onFailure needs Claude Code 2.1.295 or later. The config file format, the preview limits and the full behaviour table are in hosted-hook.md.

Already ran kya start?

kya start writes a user-level hook. With the plugin enabled too, Claude Code runs both copies for each tool call. kya 0.23.2 and later write one record row per tool_use_id (a marker under ~/.kya/hook-seen/), so you get one row. Known limit: a global kya at 0.23.1 or older never creates the marker, so you get two rows per call until you update it (npm i -g @shield-agent/kya). Decisions are identical, so a deny is never lost.

GitHub Copilot CLI

Do not install this plugin in Copilot CLI. Copilot CLI 1.0.98 runs its hooks in a way that fails, and then denies every tool call (“hook errored”). In every release before the one that ships plugins/kya-copilot, that is what copilot plugin install kya@shield-kya gives you, because Copilot reads .claude-plugin/marketplace.json when nothing else is there. Releases that ship plugins/kya-copilot add .plugin/marketplace.json, which Copilot reads first, so the same command gives a Copilot-specific plugin. See copilot.md. Until then, use kya connect copilot.

Uninstall

/plugin uninstall kya@shield-kya
/plugin marketplace remove shield-kya

Uninstalling from the last scope deletes ${CLAUDE_PLUGIN_DATA} (the installed kya copy). Your local record under ~/.kya/ stays; delete it if you want it gone. A repository that lists the plugin in .claude/settings.json re-enables it for teammates until the entry is removed there.

Troubleshooting