Use the Claude Code plugin

There are two ways to govern Claude Code with Unyform, and they are not the same thing:

  • Gateway routing โ€” you set ANTHROPIC_BASE_URL so Claude Code's inference traffic flows through Unyform. The gateway injects context, applies policy, and audits every request because it sits on the wire.
  • The local plugin (this page) โ€” Claude Code keeps talking directly to api.anthropic.com. Unyform's mx cc-plugin runs locally as a Claude Code hook: it pulls your org's blueprints into the session at startup and reports the session afterward. Context and audit, without re-routing a single byte of inference.

Tip

Use the local plugin when you must keep Claude Code's official client identity โ€” for example Opus on a Max subscription, which Anthropic only serves to the real Claude Code binary, never to an HTTP proxy. The gateway remains the right answer for API-key tenants, Bedrock/Vertex, and CI agents.

What the plugin does

mx cc-plugin install writes two hook entries into your ~/.claude/settings.json:

Claude Code eventHandlerWhat happens
SessionStartmx cc-plugin sessionResolves your gateway's blueprints from /v1/cc/session, prints a <system-reminder> block to stdout, and Claude Code injects it into the session preamble.
Stopmx cc-plugin stopReports the finished session to /v1/cc/audit, recording which blueprints were injected (and best-effort token usage) as a gateway_usage row โ€” the same table your gateway traffic lands in.

Both handlers fail soft: any error (offline, bad key, slow network) exits cleanly and changes nothing, so a misconfigured plugin never breaks your claude.

Prerequisites

  • The mx CLI installed and on your PATH (the same binary used for the rest of the Unyform toolchain).
  • A gateway API key (uny_gw_...) โ€” the same per-gateway key you'd use for the gateway passthrough. It resolves to exactly one gateway, so the plugin knows which blueprints to serve with no extra config.

Set up

Install the hooks and store your key in one step:

mx cc-plugin install --api-key uny_gw_your_key_here โœ“ installed 2 Unyform CC hook(s) in ~/.claude/settings.json โœ“ wrote cc-plugin auth config to ~/.config/unyform/cc-plugin.json (mode 0600)

The key is written to a config file (cc-plugin.json, mode 0600 on Unix), so it stays out of settings.json. Confirm the install:

mx cc-plugin status Unyform CC hook status (settings: ~/.claude/settings.json) โœ“ SessionStart โ†’ mx cc-plugin session โœ“ Stop โ†’ mx cc-plugin stop Auth config (~/.config/unyform/cc-plugin.json): โœ“ configured โ€” base_url = https://gateway.unyform.ai, api_key = uny_gw_abcโ€ฆ1234

Note

Install is idempotent and additive โ€” re-running it won't duplicate entries, and your existing hooks (codegraph, formatters, etc.) are left untouched. If you have a key set in UNYFORM_API_KEY, you can omit --api-key.

Start and stop a session

There's no separate "start" command โ€” the hooks fire automatically. Just run Claude Code as you always do:

claude

On startup the SessionStart hook fetches your blueprints and Claude Code injects them as a <system-reminder> preamble โ€” the same authoritative context the gateway would prepend, delivered locally. When the session ends, the Stop hook posts the audit event. Both are invisible in normal use; the only sign is that Claude Code now knows your codebase's conventions from the first prompt.

What gets audited

The Stop hook records each plugin session as a gateway_usage row tagged with your gateway and API key. It captures:

  • the blueprint IDs injected into the session (the governance signal โ€” proof of which context reached the model),
  • the estimated blueprint token cost,
  • best-effort prompt / completion tokens and model, parsed from Claude Code's local transcript,
  • the session duration.

Because Claude Code talks to Anthropic directly, this POST is the only way Unyform learns a plugin session happened โ€” there's no upstream request to piggyback on. These rows appear in the same dashboard surface as your gateway traffic.

Remove the plugin

mx cc-plugin uninstall โœ“ removed 2 Unyform CC hook(s) from ~/.claude/settings.json โœ“ removed cc-plugin auth config at ~/.config/unyform/cc-plugin.json

Pass --keep-config to leave the API key in place for a quick re-install.

Warning

Today the plugin injects blueprint context (SessionStart) and audits sessions (Stop). Input-side policy checks and per-tool egress redaction are planned for a later phase and are not yet wired into the hooks โ€” for those, use gateway routing, which enforces policy on the wire.

Edit this page on GitHub