@ory/claude-code 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,10 +60,11 @@ From any project where you'd like Ory authentication, inside Claude Code:
60
60
  4. **Turn on Ory login for the Claude session itself.** *(Optional but recommended.)* Out of the box the plugin only governs your *app*. To also attach an Ory identity to *Claude's* session — so every tool call is attributed to you, not a fallback `session:<id>` subject — opt in to the user-login flow:
61
61
 
62
62
  ```bash
63
- export ORY_USER_LOGIN=1
63
+ export ORY_USER_LOGIN=true
64
+ export ORY_OAUTH2_CLIENT_ID=<value printed by `local up`>
64
65
  ```
65
66
 
66
- User login is off by default. With it on, the next Claude session opens an Ory login in your browser; sign in with the same seeded credentials from step 1, and the token is reused on subsequent sessions until it expires. This is what makes `permissions enforce` (see [Agent security](#agent-security)) deny on the right identity later.
67
+ User login is off by default. Both exports above are printed in the `local up` banner — copy them straight from there. `ORY_OAUTH2_CLIENT_ID` is required whenever `ORY_USER_LOGIN` is on: it identifies the public OAuth2 client the PKCE browser flow exchanges for a token. With both set, the next Claude session opens an Ory login in your browser; sign in with the same seeded credentials from step 1, and the token is reused on subsequent sessions until it expires. This is what makes `permissions enforce` (see [Agent security](#agent-security)) deny on the right identity later.
67
68
 
68
69
  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.
69
70
 
@@ -105,24 +106,80 @@ Bundled and registered automatically. Exposes the Ory CLI and the Ory Network RE
105
106
 
106
107
  ## Pointing at a real Ory project
107
108
 
108
- The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it. A project URL is enough — the agent identity is created automatically via OAuth2 Dynamic Client Registration on first run:
109
+ The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it with a single configure command. **The plugin requires `--oauth2-client-id` whenever `--project-url` is provided**register the client first (see [Register the user OAuth2 client](#register-the-user-oauth2-client) below), then run:
109
110
 
110
111
  ```bash
111
112
  npx -y -p @ory/claude-code ory-claude configure \
112
- --project-url https://<id>.projects.oryapis.com
113
+ --project-url https://<id>.projects.oryapis.com \
114
+ --oauth2-client-id <public OAuth2 client id>
113
115
  ```
114
116
 
115
- Pass `--api-key ory_pat_...` only if you want to override the auto-registered agent identity with a static personal access token (operator override; rarely needed).
117
+ - **`--project-url`** points the plugin at your project. The **agent identity** (machine credentials for Claude's outgoing Ory API calls) is created automatically on first run via OAuth2 Dynamic Client Registration ([RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591)) against the project's `/oauth2/register` endpoint — no manual step required for that one.
118
+ - **`--oauth2-client-id`** is required because the **user** PKCE browser flow (triggered by `ORY_USER_LOGIN=true`) cannot self-register — you must register a public OAuth2 client ahead of time and supply its id here. The configure command refuses to save a project URL without it, so you don't end up with a silently-broken setup later. See [Register the user OAuth2 client](#register-the-user-oauth2-client) below for the exact CLI / Console steps.
119
+ - **`--api-key ory_pat_...`** is optional — pass it only if you want to override the auto-registered agent identity with a static personal access token (operator override; rarely needed).
116
120
 
117
- Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine. The same settings can be supplied via environment variables (`ORY_PROJECT_URL`, `ORY_AGENT_API_KEY`) env vars take precedence over the config file when both are set, which is what most CI / scripted setups want.
121
+ If you only want audit logging (no auth or permission checks), substitute `--audit-only` — the OAuth2 client id is not required in that mode:
122
+
123
+ ```bash
124
+ npx -y -p @ory/claude-code ory-claude configure --audit-only
125
+ ```
126
+
127
+ The same settings can be supplied via environment variables (`ORY_PROJECT_URL`, `ORY_OAUTH2_CLIENT_ID`, `ORY_AGENT_API_KEY`) — env vars take precedence over the config file when both are set, which is what most CI / scripted setups want.
128
+
129
+ Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
118
130
 
119
131
  Without any configuration the plugin still loads cleanly and runs in **pass-through mode**: skills, slash commands, and audit logging work, but no permission checks run, so nothing is ever blocked. You can stay in pass-through mode indefinitely if you only want the DX features.
120
132
 
133
+ ### Register the user OAuth2 client
134
+
135
+ If you plan to turn on `ORY_USER_LOGIN=true` (recommended — it's what attributes every tool call to *you* rather than a fallback `session:<id>` subject), your hosted Ory project needs a **public** OAuth2 client (no client secret) registered ahead of time. The local stack provisions this for you automatically; against a hosted project you have to register it once yourself.
136
+
137
+ The client must list **all four** loopback ports as redirect URIs:
138
+
139
+ - `http://127.0.0.1:47823/callback`
140
+ - `http://127.0.0.1:47824/callback`
141
+ - `http://127.0.0.1:47825/callback`
142
+ - `http://127.0.0.1:47826/callback`
143
+
144
+ The plugin walks the four ports at runtime so the login can survive any one of them being occupied — Ory rejects the callback if the port it lands on isn't on the registered list, so register all four.
145
+
146
+ Create the client with the [Ory CLI](https://www.ory.com/docs/guides/cli/installation):
147
+
148
+ ```bash
149
+ ory create oauth2-client --project <project-id> \
150
+ --name "ory-agent-plugin" \
151
+ --grant-type authorization_code,refresh_token \
152
+ --response-type code \
153
+ --scope openid,offline_access \
154
+ --token-endpoint-auth-method none \
155
+ --redirect-uri http://127.0.0.1:47823/callback \
156
+ --redirect-uri http://127.0.0.1:47824/callback \
157
+ --redirect-uri http://127.0.0.1:47825/callback \
158
+ --redirect-uri http://127.0.0.1:47826/callback
159
+ ```
160
+
161
+ …or in the [Ory Console](https://console.ory.sh) under *OAuth2* → *Clients* → *Create client* (pick "Public client", set "Authorization Code" + "Refresh Token" grants, scopes `openid offline_access`, paste the four redirect URIs above). Then persist the issued id with the configure command (preferred — survives across sessions):
162
+
163
+ ```bash
164
+ npx -y -p @ory/claude-code ory-claude configure \
165
+ --project-url https://<id>.projects.oryapis.com \
166
+ --oauth2-client-id <client-id from the step above>
167
+ ```
168
+
169
+ …or set it in the environment alongside `ORY_USER_LOGIN`:
170
+
171
+ ```bash
172
+ export ORY_USER_LOGIN=true
173
+ export ORY_OAUTH2_CLIENT_ID=<client-id from the step above>
174
+ ```
175
+
176
+ Headless / CI runs that already hold a session token can skip this entirely by setting `ORY_USER_SESSION_TOKEN` instead — no browser flow runs, so no OAuth2 client is needed.
177
+
121
178
  ## Agent security
122
179
 
123
180
  Once the plugin is pointed at an Ory project (local or hosted), Claude's session and every tool call can be governed by Ory.
124
181
 
125
- - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when user login is enabled (`ORY_USER_LOGIN=1`, off by default — browser PKCE flow on first session, persisted token thereafter). 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.
182
+ - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when user login is enabled (`ORY_USER_LOGIN=true`, off by default — browser PKCE flow on first session, persisted token thereafter). 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.
126
183
  - **Authorization.** Before any tool runs, the plugin checks [Ory Permissions](https://www.ory.sh/docs/keto) (Zanzibar-style relations) against the user's subject and blocks the call on `deny`. MCP tool calls additionally get a server-level check.
127
184
  - **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 relations so *"agent X acting on behalf of user Y"* stays queryable after tokens expire.
128
185
 
@@ -135,11 +192,14 @@ With an Ory project configured, the plugin runs in **observe mode** by default:
135
192
  1. **Turn on user login.** It's off by default. In your shell:
136
193
 
137
194
  ```bash
138
- export ORY_USER_LOGIN=1
195
+ export ORY_USER_LOGIN=true
196
+ export ORY_OAUTH2_CLIENT_ID=<public OAuth2 client id>
139
197
  ```
140
198
 
141
199
  The next Claude session opens a browser for PKCE login. Subsequent sessions reuse the persisted token until it expires.
142
200
 
201
+ `ORY_OAUTH2_CLIENT_ID` is required when `ORY_USER_LOGIN` is on: PKCE needs a public OAuth2 client registered with the four loopback redirect URIs (`http://127.0.0.1:47823..47826/callback`) to exchange the authorization code for a token. The local stack provisions one and prints the export in its `local up` banner; for a hosted Ory project see [Register the user OAuth2 client](#register-the-user-oauth2-client) for the exact CLI / Console steps. Headless / CI runs can skip the browser flow entirely by pre-supplying `ORY_USER_SESSION_TOKEN` instead.
202
+
143
203
  2. **Bootstrap permissions for the built-in tools.** One idempotent command grants the current user `use` on every tool Claude ships with (Read, Write, Bash, …):
144
204
 
145
205
  ```bash
@@ -168,7 +228,7 @@ With an Ory project configured, the plugin runs in **observe mode** by default:
168
228
 
169
229
  ```
170
230
  npx -y -p @ory/claude-code ory-claude install | uninstall [--global]
171
- npx -y -p @ory/claude-code ory-claude configure [--project-url <url>] [--api-key <key>] [--audit-only]
231
+ npx -y -p @ory/claude-code ory-claude configure [--project-url <url> --oauth2-client-id <id>] [--api-key <key>] [--audit-only]
172
232
  npx -y -p @ory/claude-code ory-claude agent <status|unregister> Manage the agent's OAuth2 identity
173
233
  npx -y -p @ory/claude-code ory-claude permissions <status|bootstrap|observe|enforce>
174
234
  npx -y -p @ory/claude-code ory-claude local <up|down|status|seed|logs|env|configure|reset>
package/dist/handlers.js CHANGED
@@ -226,7 +226,21 @@ async function handlePreToolUse(input, client, deps = {}) {
226
226
  };
227
227
  }
228
228
  const namespace = resolveNamespace();
229
- const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: toolName, relation: "use", ...subject }, { spanAttributes: { toolName } });
229
+ const outcome = await (0, argus_1.gateToolCall)(client, {
230
+ harness: "claude-code",
231
+ toolName,
232
+ check: { namespace, object: toolName, relation: "use", ...subject },
233
+ spanAttributes: { toolName },
234
+ });
235
+ // Interactive tools (AskUserQuestion, ExitPlanMode, TodoWrite, …)
236
+ // surface UI to the user and aren't external-system tool executions.
237
+ // gateToolCall has already recorded the `user.interaction` audit span;
238
+ // we pass through with no `tool.invoke`/`tool.block` and let the
239
+ // harness deliver the prompt to the user.
240
+ if (outcome.kind === "interactive") {
241
+ return {};
242
+ }
243
+ const decision = outcome;
230
244
  if (decision.kind === "fail_open") {
231
245
  return handlePermissionError(decision.error, toolName, client);
232
246
  }
@@ -377,6 +391,15 @@ async function handlePermissionRequest(input, client) {
377
391
  if ((0, argus_1.resolveConfig)().auditOnly) {
378
392
  return permissionRequestFallback("Audit-only mode — deferring to user");
379
393
  }
394
+ // Interactive tools: the harness is about to surface UI to the user
395
+ // (AskUserQuestion, ExitPlanMode, TodoWrite, …). Trace and fall through
396
+ // — Ory shouldn't pre-answer a prompt that's meant for the human.
397
+ if ((0, argus_1.isInteractiveTool)("claude-code", toolName)) {
398
+ client.tracer.record("user.interaction", "ok", {
399
+ attributes: { harness: "claude-code", toolName, kind: "permission-request" },
400
+ });
401
+ return permissionRequestFallback("Interactive tool — deferring to user");
402
+ }
380
403
  const subject = (0, argus_1.resolveUserSubject)(client, `session:${input.session_id}`);
381
404
  const subjectId = (0, argus_1.subjectLabel)(subject);
382
405
  const mcpTool = (0, argus_1.parseClaudeCodeMcpTool)(toolName);
@@ -401,7 +424,16 @@ async function handlePermissionRequest(input, client) {
401
424
  : "Ory MCP server permission granted");
402
425
  }
403
426
  const namespace = resolveNamespace();
404
- const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: toolName, relation: "use", ...subject }, { spanAttributes: { toolName } });
427
+ const outcome = await (0, argus_1.gateToolCall)(client, {
428
+ harness: "claude-code",
429
+ toolName,
430
+ check: { namespace, object: toolName, relation: "use", ...subject },
431
+ spanAttributes: { toolName },
432
+ });
433
+ if (outcome.kind === "interactive") {
434
+ return permissionRequestFallback("Interactive tool — deferring to user");
435
+ }
436
+ const decision = outcome;
405
437
  if (decision.kind === "fail_open") {
406
438
  const code = decision.error.code;
407
439
  const fallbackReason = code === "network_error" || code === "rate_limited"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/claude-code",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Ory plugin for Claude Code: scaffolding skills, a local Ory instance, and authentication, authorization, and audit for every tool call",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/ory/claude-plugins/tree/master/plugins/ory-agent-plugin",
@@ -75,7 +75,7 @@
75
75
  "!dist/**/*.tsbuildinfo"
76
76
  ],
77
77
  "dependencies": {
78
- "@ory/argus": "0.8.1"
78
+ "@ory/argus": "0.9.0"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=22"