Hosted-plane hook (preview)

Preview. Hosted mode is new and its limits are listed below. Read them before you rely on it. Any API key you create today has write scope, not just evaluate scope. A key that can only evaluate is planned and not available yet.

By default kya hook evaluates locally, makes no network calls, and fails open: if kya breaks, the tool call goes ahead. Hosted mode changes that. Each tool call is evaluated by your Shield KYA workspace (POST /api/v1/kya/policy/evaluate). When the plane cannot answer, the call is denied.

kya hook --host claude --plane-config /Users/you/.kya/hosted.json

What it does

Plane answer or condition Hosted (default) --strict --plane-shadow
Local never-list match (for example mcp__postgres__drop_table) deny deny deny
Local guard pack match (for example terraform destroy, a read of ~/.kube/config) deny deny deny
ALLOW allow allow allow
DENY (registered DENY tool, workspace policy, session clearance) deny deny allow, recorded
REQUIRE_APPROVE (hold; every unregistered tool such as Read or Bash today) allow, recorded deny, with a console link allow, recorded
Agent killed or revoked (AGENT_NOT_ACTIVE) deny deny allow, recorded
Agent id unknown to the workspace (AGENT_UNKNOWN) deny deny allow, recorded
Plane unreachable, 5xx, no decision (PLANE_UNREACHABLE) deny deny allow, recorded
Key rejected, 401 or 403 (PLANE_AUTH_REJECTED) deny deny allow, recorded
No answer within the budget (PLANE_TIMEOUT) deny deny allow, recorded
Rate limited, 429 (PLANE_RATE_LIMITED) deny deny allow, recorded
Config file missing or unsafe (PLANE_CONFIG) deny deny allow, recorded
TLS, CA, proxy or code-loading env override (PLANE_ENV_REFUSED) deny deny allow, recorded
Unreadable hook payload (FAIL_CLOSED) deny deny allow, recorded

Retries and the latency budget

The plane call has one total budget: 3000 ms by default, set with --plane-budget-ms (100 to 4000). That leaves room under Claude Code’s 5 s hook timeout for node start and the record write.

The config file

--plane-config takes an absolute path to a JSON file:

{
  "baseUrl": "https://shield-agent.com",
  "apiKey": "sk_live_...",
  "agentId": "00000000-0000-0000-0000-000000000000"
}
chmod 600 ~/.kya/hosted.json

Environment: what is ignored and what is refused

A repository can set environment variables for hooks. Claude Code applies the env block of a project’s committed .claude/settings.json once you trust the folder, and hook processes inherit that environment. A .env loaded by your shell or tooling does the same. Hosted mode therefore reads its key, URL and agent from the config file only, and treats the environment as untrusted.

Ignored (the hook prints one stderr line and the record row carries "configIgnored": true):

The record goes to $HOME/.kya/trail.jsonl. User-level notify and OTLP settings in $HOME/.kya/config.json still apply. Proxy variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY and their lowercase forms) are removed: the plane call never goes through a proxy, so a plane that is reachable only through a proxy fails closed (denies the call).

Refused (deny PLANE_ENV_REFUSED; the message names the variable and never prints its value). These either change who the hook trusts or load code into node before kya starts, and some are read at process start, so they cannot be undone from inside the hook:

What the refusal cannot do. A NODE_OPTIONS preload (--require, --import), NODE_PATH/OPENSSL_CONF code, or a loader-level injection (DYLD_INSERT_LIBRARIES, LD_PRELOAD) has already run before the hook’s own check, before any JavaScript, so the check can only refuse to send the key and deny the call afterwards; it cannot stop that code from running. This is the same class as anyone who controls the process environment. Do not let repositories or users set env overrides for agent sessions (prefer managed settings).

A corporate setup that needs a custom CA or a proxy cannot use hosted mode in this preview. Managed settings can also set env for every session; if an administrator puts one of the refused variables there, every hosted hook call is denied. That is the administrator’s responsibility to avoid.

Privacy opt-outs are still honoured, because they can only send less. KYA_SEND_PREVIEWS=0 keeps summary, diffPreview and targetPath off the wire.

Transport

The plane call uses its own HTTPS client: certificates are always verified, SNI comes from the configured host, there is no keep-alive and no proxy, and redirects are never followed (a 3xx is PLANE_UNREACHABLE, so the key is never sent to a second URL). The answer is capped at 64 KiB (a larger or endless body fails closed). The plane’s reason code must be an upper-case identifier ([A-Z0-9_], at most 64 characters); anything else is shown as PLANE_BAD_RESPONSE. The hold console link is always built from your configured baseUrl, never from the plane’s answer. An uncaught error never lowers a decision: the local never-list is evaluated before any plane code and still denies (exit 2) after a crash, even in shadow; a crash before the payload is understood also denies in shadow; otherwise a crash denies (exit 2), except in shadow for a tool known to be off the never-list (exit 0).

onFailure: "block" is required. Some failures kill node before kya runs at all: an invalid NODE_OPTIONS value, a heap too small to start, or a signal. Those exit with node’s own code (for example 9, or SIGABRT), not 2. On a Node that does not know --use-env-proxy (Node 20, and Node 22 before 22.21.0), NODE_OPTIONS=--use-env-proxy is one of them: node exits 9 before kya can answer with the PLANE_ENV_REFUSED deny, and only onFailure: "block" stops the call. Use Node 22.21+ (or 24) for hosted mode. Only the host’s onFailure: "block" turns them into a block, so hosted mode depends on it; kya connect --hosted and the managed snippet below set it. After the answer is written the hook exits at once, so a lingering socket cannot hold it past the host timeout.

What leaves your machine

The same fields connected mode sends, plus four record fields:

Wire it

One user, Claude Code:

kya connect claude --hooks --hosted --plane-config /Users/you/.kya/hosted.json

This validates the file first, then writes the PreToolUse hook into ~/.claude/settings.json with "onFailure": "block" (Claude Code 2.1.295 or later), so a crash or a host timeout also blocks. It replaces an existing kya hook instead of adding a second copy. --plane-config without --hosted is refused rather than silently wiring the local hook. The reverse is also refused: kya connect claude --hooks without --hosted (even with --force) will not swap a hosted hook back to the local one; remove the entry by hand if that is what you want. Add --strict or --plane-shadow to put that flag on the hook command. The key is never written to the settings file. Only Claude Code is supported for hosted wiring in this preview.

A fleet (managed settings): a user-level hook can be removed by the user. Worse, a repository’s committed .claude/settings.json can set "disableAllHooks": true, which turns off user, project and plugin hooks; only managed hooks keep running. For enforcement that a repository or the agent cannot switch off, deploy the hook in Claude Code managed settings. The file goes at /Library/Application Support/ClaudeCode/managed-settings.json on macOS, /etc/claude-code/managed-settings.json on Linux and WSL, or through MDM or server-managed settings. Add allowManagedHooksOnly so that only managed hooks run:

{
  "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"
          }
        ]
      }
    ]
  }
}

Adjust the node and kya paths for your machines (which node, npm root -g). With allowManagedHooksOnly, the kya plugin’s own hooks are blocked unless your managed settings force-enable the plugin. See the Claude Code settings reference and managed settings.

Honest limits