|
| 1 | +# Ory Agent Plugin: Claude Code |
| 2 | + |
| 3 | +[Ory](https://ory.com) bundled into [Claude Code](https://docs.anthropic.com/en/docs/claude-code): skills and slash commands that scaffold Ory authentication into your codebase, a local Ory stack you can spin up in one command, and (when pointed at an Ory project) authentication, authorization, and audit for every tool Claude runs. |
| 4 | + |
| 5 | +You don't need an Ory account or any prior Ory experience to start. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) installed and signed in |
| 10 | +- Node.js **≥ 24** |
| 11 | +- [Docker](https://docs.docker.com/get-docker/) (only needed for the local Ory stack) |
| 12 | +- macOS or Linux. Windows works via WSL2. |
| 13 | + |
| 14 | +## Install |
| 15 | + |
| 16 | +Inside Claude Code: |
| 17 | + |
| 18 | +``` |
| 19 | +/plugin install ory-agent-plugin |
| 20 | +``` |
| 21 | + |
| 22 | +That's it — skills, slash commands, hooks, and the Ory MCP server are now registered. |
| 23 | + |
| 24 | +<details> |
| 25 | +<summary>Alternative install paths</summary> |
| 26 | + |
| 27 | +If the public marketplace install above isn't available, either of these registers the same plugin: |
| 28 | + |
| 29 | +``` |
| 30 | +# Ory-hosted marketplace |
| 31 | +/plugin marketplace add ory/claude-plugins |
| 32 | +/plugin install ory-agent-plugin@ory-plugins |
| 33 | +``` |
| 34 | + |
| 35 | +```bash |
| 36 | +# Direct installer, no prior npm install required |
| 37 | +npx @ory/claude-code install # current project |
| 38 | +npx @ory/claude-code install --global # all projects (user scope) |
| 39 | +npx @ory/claude-code uninstall |
| 40 | +``` |
| 41 | + |
| 42 | +</details> |
| 43 | + |
| 44 | +## Quickstart (≈ 3 minutes) |
| 45 | + |
| 46 | +From any project where you'd like Ory authentication, inside Claude Code: |
| 47 | + |
| 48 | +1. **Start a local Ory instance.** Ask Claude *"start the local Ory stack"* or run: |
| 49 | + |
| 50 | + ``` |
| 51 | + /ory:local-up |
| 52 | + ``` |
| 53 | + |
| 54 | + A banner prints the seeded test user's email and password. Note them — you'll log in with them in step 3. |
| 55 | + |
| 56 | +2. **Scaffold Ory into your project.** Ask Claude *"add Ory auth to this app"* or run: |
| 57 | + |
| 58 | + ``` |
| 59 | + /ory:auth-setup |
| 60 | + ``` |
| 61 | + |
| 62 | + Claude installs Ory Elements, wires the SDK, generates the login / registration / recovery / verification / settings pages, and sets up session middleware. It targets the local stack from step 1, so no signup or API key is needed. |
| 63 | + |
| 64 | +3. **Sign in.** Start your app, visit the login page Claude added, and sign in with the seeded credentials. You now have a real Ory session backed by a real Ory stack — locally, offline, with zero configuration. |
| 65 | + |
| 66 | +That's the full Ory DX path. Stop here if you're just evaluating the plugin. Continue to [Agent security](#agent-security) when you're ready to enforce. |
| 67 | + |
| 68 | +## What's included |
| 69 | + |
| 70 | +### Skills for scaffolding Ory into your application |
| 71 | + |
| 72 | +Each skill is a vetted, end-to-end playbook. Ask Claude in natural language or invoke the slash command directly: |
| 73 | + |
| 74 | +- **`/ory:auth-setup`** — full project setup. Install the Ory CLI, create an Ory Network project (or use the local one), add Ory Elements, configure the SDK, build the auth pages, wire session middleware. |
| 75 | +- **`/ory:login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants. |
| 76 | +- **`/ory:social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers. |
| 77 | +- **`/ory:local-dev`** — drive the local Ory stack from within Claude to prototype and test without a remote project. |
| 78 | + |
| 79 | +### Ory MCP server |
| 80 | + |
| 81 | +Bundled and registered automatically. Exposes the Ory CLI and the Ory Network REST API as MCP tools so Claude can manage identities, OAuth2 clients, projects, permission tuples, and configuration without ever leaving the chat. Useful for seeding test data, verifying a scaffolded integration, or running one-off admin tasks. |
| 82 | + |
| 83 | +### Local Ory stack |
| 84 | + |
| 85 | +``` |
| 86 | +/ory:local-up # start a local Ory instance in Docker |
| 87 | +/ory:local-down # tear it all down |
| 88 | +``` |
| 89 | + |
| 90 | +`local-up` brings up Ory Identities, OAuth2, and Permissions, plus a login UI on `:3000` and Jaeger on `:16686`, all reachable through `http://localhost:4000`. A test user identity is seeded and the credentials are printed for you. Use it to: |
| 91 | + |
| 92 | +- **Learn Ory hands-on** without signing up for a hosted project. |
| 93 | +- **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend. |
| 94 | +- **Test** an auth integration end-to-end before pushing anything to a real environment. |
| 95 | +- **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with. |
| 96 | + |
| 97 | +## Pointing at a real Ory project |
| 98 | + |
| 99 | +The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it: |
| 100 | + |
| 101 | +```bash |
| 102 | +npx -y -p @ory/claude-code ory-claude configure \ |
| 103 | + --project-url https://<id>.projects.oryapis.com \ |
| 104 | + --api-key ory_pat_... |
| 105 | +``` |
| 106 | + |
| 107 | +Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine. |
| 108 | + |
| 109 | +Without configuration the plugin still loads cleanly and runs in **pass-through mode**: skills and commands work, but nothing is blocked. You can stay in pass-through mode indefinitely if you only want the DX features. |
| 110 | + |
| 111 | +## Agent security |
| 112 | + |
| 113 | +Once the plugin is pointed at an Ory project (local or hosted), Claude's session and every tool call can be governed by Ory. |
| 114 | + |
| 115 | +- **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1` is set. The Claude process (the **agent**) gets its own OAuth2 identity, self-registered via [Dynamic Client Registration (RFC 7591)](https://datatracker.ietf.org/doc/html/rfc7591) on first run. Sub-agents launched by the `Task` tool each receive their own typed identity. |
| 116 | +- **Authorization.** Before any tool runs, the plugin checks [Ory Permissions](https://www.ory.sh/docs/keto) (Zanzibar-style relation tuples) against the user's subject and blocks the call on `deny`. MCP tool calls additionally get a server-level check. |
| 117 | +- **Audit.** Every decision (allow, deny, fallback) is recorded as a structured trace span: NDJSON file output and/or OTLP/HTTP export to Jaeger, Honeycomb, Grafana, and similar collectors. The user → agent (and agent → subagent) delegation chain is written to Ory as relation tuples so *"agent X acting on behalf of user Y"* stays queryable after tokens expire. |
| 118 | + |
| 119 | +The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config), so enforcement is only as strong as your tuples — grant explicit `invoke` relations for the tools each user should be able to run. |
| 120 | + |
| 121 | +### Enable enforcement |
| 122 | + |
| 123 | +After install the plugin runs in **observe mode**: every tool call is checked against Ory Permissions, but a deny is recorded as a `permission.observe_deny` audit span and the tool runs anyway. This lets you see what *would* be blocked before turning on hard blocking. |
| 124 | + |
| 125 | +1. **Turn on the user gate.** In your shell: |
| 126 | + |
| 127 | + ```bash |
| 128 | + export ORY_AUTH_GATE=1 |
| 129 | + ``` |
| 130 | + |
| 131 | + The next Claude session opens a browser for PKCE login. Subsequent sessions reuse the persisted token until it expires. |
| 132 | + |
| 133 | +2. **Bootstrap tuples for the built-in tools.** One idempotent command grants the current user `use` on every tool Claude ships with (Read, Write, Bash, …): |
| 134 | + |
| 135 | + ```bash |
| 136 | + npx -y -p @ory/claude-code ory-claude permissions bootstrap |
| 137 | + ``` |
| 138 | + |
| 139 | + If a user identity is already cached at install time, the installer runs this for you automatically — re-run after adding tools, switching subjects, or changing the namespace. |
| 140 | + |
| 141 | +3. **Check coverage.** `permissions status` probes every tool in the harness's catalog and prints allowed / denied per tool: |
| 142 | + |
| 143 | + ```bash |
| 144 | + npx -y -p @ory/claude-code ory-claude permissions status |
| 145 | + ``` |
| 146 | + |
| 147 | + Add tuples for any MCP server tools or custom commands by hand, or via the Ory MCP server from inside Claude (*"grant me use on the Bash tool"*). |
| 148 | + |
| 149 | +4. **Promote to enforce.** Once the observe-mode logs look right, switch over: |
| 150 | + |
| 151 | + ```bash |
| 152 | + npx -y -p @ory/claude-code ory-claude permissions enforce |
| 153 | + ``` |
| 154 | + |
| 155 | + Denies now block the tool call; Claude shows the denial reason and the decision is recorded as a `tool.block` trace span with `blocked: true`. Switch back any time with `permissions observe`. |
| 156 | + |
| 157 | +## CLI reference |
| 158 | + |
| 159 | +``` |
| 160 | +npx -y -p @ory/claude-code ory-claude install | uninstall [--global] |
| 161 | +npx -y -p @ory/claude-code ory-claude configure [--project-url <url>] [--api-key <key>] [--audit-only] |
| 162 | +npx -y -p @ory/claude-code ory-claude agent <status|unregister> Manage the agent's OAuth2 identity |
| 163 | +npx -y -p @ory/claude-code ory-claude permissions <status|bootstrap|observe|enforce> |
| 164 | +npx -y -p @ory/claude-code ory-claude local <up|down|status|seed|logs|env|configure|reset> |
| 165 | +npx -y -p @ory/claude-code ory-claude status |
| 166 | +``` |
| 167 | + |
| 168 | +Highlights: |
| 169 | + |
| 170 | +- `agent status` — show the current persisted DCR identity for the agent. |
| 171 | +- `permissions observe` / `permissions enforce` — switch between "log denies, allow through" (the install default) and "block denies." `permissions bootstrap` writes `use` tuples for the harness's built-in tools so the promotion path doesn't require hand-writing relationships. |
| 172 | +- `configure --audit-only` — kill switch that disables Ory entirely (no auth, no permission checks; only audit logging of tool invocations). For phased rollouts, prefer `permissions observe` over `--audit-only`. |
| 173 | +- `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack. |
| 174 | + |
| 175 | +## Troubleshooting |
| 176 | + |
| 177 | +- **`/ory:local-up` fails.** Make sure Docker is running and ports `3000`, `4000`, `4100`, and `16686` are free. |
| 178 | +- **PKCE login loops.** Clear persisted state with `npx -y -p @ory/claude-code ory-claude agent unregister` and retry. |
| 179 | +- **`npx` fetches an old version.** Force a fresh fetch: `npx -y -p @ory/claude-code@latest ory-claude …`. |
| 180 | +- **Need more signal.** Set `ORY_AGENT_DEBUG=true` and `ORY_AGENT_LOG_FILE=/tmp/ory.log` to capture structured logs. |
| 181 | + |
| 182 | +## Links |
| 183 | + |
| 184 | +- [Ory documentation](https://www.ory.com/docs/) |
| 185 | +- [Ory Network console](https://console.ory.sh) |
| 186 | +- [Ory Elements](https://github.com/ory/elements) |
| 187 | +- [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code) |
| 188 | + |
| 189 | +## License |
| 190 | + |
| 191 | +Apache-2.0 |
0 commit comments