@preapexis/piexis 0.2.2 → 0.2.4

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.
Files changed (149) hide show
  1. package/AGENTS.md +21 -41
  2. package/README.md +73 -139
  3. package/extensions/agents.ts +205 -0
  4. package/extensions/ask-question.ts +54 -95
  5. package/extensions/recommended-tools.ts +62 -0
  6. package/extensions/ui.ts +204 -58
  7. package/lib/agent-config.ts +55 -0
  8. package/lib/agents.ts +208 -0
  9. package/lib/question-model.ts +98 -0
  10. package/lib/question-ui.ts +214 -0
  11. package/lib/recommended-tools.ts +119 -0
  12. package/lib/subagent-runner.ts +146 -0
  13. package/lib/ui-tips.json +41 -0
  14. package/package.json +5 -13
  15. package/prompts/init.md +10 -2
  16. package/prompts/summary.md +7 -6
  17. package/schemas/agent.schema.json +48 -0
  18. package/skills/{claude-api/LICENSE.txt → caveman/LICENSE} +2 -2
  19. package/skills/caveman/LICENSE-MIT +21 -0
  20. package/skills/caveman/NOTICE +10 -0
  21. package/skills/caveman/SKILL.md +89 -0
  22. package/skills/find-skills/SKILL.md +141 -0
  23. package/skills/ponytail/LICENSE +21 -0
  24. package/skills/ponytail/NOTICE +9 -0
  25. package/skills/ponytail/SKILL.md +52 -0
  26. package/skills-lock.json +6 -0
  27. package/tests/agents.test.mjs +605 -0
  28. package/tests/ask-question-pty.test.mjs +16 -0
  29. package/tests/ask-question.test.mjs +269 -0
  30. package/tests/fixtures/agents-provider.ts +55 -0
  31. package/tests/fixtures/ask-question-pty.py +91 -0
  32. package/tests/fixtures/ask-question-terminal.mjs +69 -0
  33. package/tests/fixtures/recommended-tools-terminal.mjs +103 -0
  34. package/tests/init-workflow.test.mjs +31 -0
  35. package/tests/recommended-tools-pty.test.mjs +16 -0
  36. package/tests/recommended-tools.test.mjs +423 -0
  37. package/tests/resources.test.mjs +66 -0
  38. package/tests/skills-routing.test.mjs +7 -4
  39. package/tests/ui-tip-reload.test.mjs +70 -0
  40. package/tests/ui.test.mjs +450 -0
  41. package/tsconfig.json +1 -0
  42. package/eval/README.md +0 -72
  43. package/eval/permission-cases.json +0 -28
  44. package/eval/permissions.mjs +0 -103
  45. package/extensions/background-tasks.ts +0 -433
  46. package/extensions/background-worker.ts +0 -50
  47. package/extensions/glob.ts +0 -32
  48. package/extensions/mode.ts +0 -397
  49. package/lib/bash-approvals.ts +0 -113
  50. package/lib/bash-policy.ts +0 -164
  51. package/lib/mode-policy.ts +0 -174
  52. package/lib/path-policy.ts +0 -182
  53. package/lib/permission-classifier.ts +0 -128
  54. package/lib/permission-config.ts +0 -91
  55. package/lib/permission-denials.ts +0 -32
  56. package/lib/permission-intent.ts +0 -128
  57. package/lib/permission-taxonomy.ts +0 -15
  58. package/lib/task-broker.ts +0 -65
  59. package/lib/task-checkout.ts +0 -39
  60. package/lib/task-git.ts +0 -44
  61. package/lib/task-patch.ts +0 -106
  62. package/lib/task-permissions.ts +0 -51
  63. package/lib/task-report.ts +0 -62
  64. package/lib/task-worktree-policy.ts +0 -56
  65. package/skills/claude-api/SKILL.md +0 -572
  66. package/skills/claude-api/csharp/claude-api/README.md +0 -362
  67. package/skills/claude-api/csharp/claude-api/batches.md +0 -14
  68. package/skills/claude-api/csharp/claude-api/files-api.md +0 -25
  69. package/skills/claude-api/csharp/claude-api/streaming.md +0 -28
  70. package/skills/claude-api/csharp/claude-api/tool-use.md +0 -164
  71. package/skills/claude-api/curl/examples.md +0 -256
  72. package/skills/claude-api/curl/managed-agents.md +0 -371
  73. package/skills/claude-api/go/claude-api/README.md +0 -188
  74. package/skills/claude-api/go/claude-api/files-api.md +0 -23
  75. package/skills/claude-api/go/claude-api/streaming.md +0 -43
  76. package/skills/claude-api/go/claude-api/tool-use.md +0 -220
  77. package/skills/claude-api/go/managed-agents/README.md +0 -564
  78. package/skills/claude-api/java/claude-api/README.md +0 -238
  79. package/skills/claude-api/java/claude-api/files-api.md +0 -27
  80. package/skills/claude-api/java/claude-api/streaming.md +0 -24
  81. package/skills/claude-api/java/claude-api/tool-use.md +0 -228
  82. package/skills/claude-api/java/managed-agents/README.md +0 -443
  83. package/skills/claude-api/php/claude-api/README.md +0 -174
  84. package/skills/claude-api/php/claude-api/batches.md +0 -15
  85. package/skills/claude-api/php/claude-api/files-api.md +0 -13
  86. package/skills/claude-api/php/claude-api/streaming.md +0 -27
  87. package/skills/claude-api/php/claude-api/tool-use.md +0 -253
  88. package/skills/claude-api/php/managed-agents/README.md +0 -443
  89. package/skills/claude-api/python/claude-api/README.md +0 -565
  90. package/skills/claude-api/python/claude-api/batches.md +0 -198
  91. package/skills/claude-api/python/claude-api/files-api.md +0 -170
  92. package/skills/claude-api/python/claude-api/sdk-upgrade.md +0 -286
  93. package/skills/claude-api/python/claude-api/streaming.md +0 -179
  94. package/skills/claude-api/python/claude-api/tool-use.md +0 -627
  95. package/skills/claude-api/python/managed-agents/README.md +0 -335
  96. package/skills/claude-api/ruby/claude-api/README.md +0 -134
  97. package/skills/claude-api/ruby/claude-api/streaming.md +0 -16
  98. package/skills/claude-api/ruby/claude-api/tool-use.md +0 -41
  99. package/skills/claude-api/ruby/managed-agents/README.md +0 -394
  100. package/skills/claude-api/shared/admin-api.md +0 -179
  101. package/skills/claude-api/shared/agent-design.md +0 -101
  102. package/skills/claude-api/shared/anthropic-cli.md +0 -269
  103. package/skills/claude-api/shared/claude-platform-on-aws.md +0 -59
  104. package/skills/claude-api/shared/cost-optimization.md +0 -233
  105. package/skills/claude-api/shared/error-codes.md +0 -262
  106. package/skills/claude-api/shared/live-sources.md +0 -166
  107. package/skills/claude-api/shared/managed-agents-api-reference.md +0 -455
  108. package/skills/claude-api/shared/managed-agents-client-patterns.md +0 -220
  109. package/skills/claude-api/shared/managed-agents-core.md +0 -359
  110. package/skills/claude-api/shared/managed-agents-environments.md +0 -226
  111. package/skills/claude-api/shared/managed-agents-events.md +0 -290
  112. package/skills/claude-api/shared/managed-agents-memory.md +0 -201
  113. package/skills/claude-api/shared/managed-agents-multiagent.md +0 -260
  114. package/skills/claude-api/shared/managed-agents-onboarding.md +0 -82
  115. package/skills/claude-api/shared/managed-agents-outcomes.md +0 -108
  116. package/skills/claude-api/shared/managed-agents-overview.md +0 -77
  117. package/skills/claude-api/shared/managed-agents-scheduled-deployments.md +0 -156
  118. package/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +0 -282
  119. package/skills/claude-api/shared/managed-agents-tools.md +0 -504
  120. package/skills/claude-api/shared/managed-agents-webhooks.md +0 -143
  121. package/skills/claude-api/shared/model-migration.md +0 -1872
  122. package/skills/claude-api/shared/models.md +0 -142
  123. package/skills/claude-api/shared/platform-availability.md +0 -53
  124. package/skills/claude-api/shared/prompt-audit.md +0 -223
  125. package/skills/claude-api/shared/prompt-caching.md +0 -292
  126. package/skills/claude-api/shared/token-counting.md +0 -56
  127. package/skills/claude-api/shared/tool-use-concepts.md +0 -526
  128. package/skills/claude-api/typescript/claude-api/README.md +0 -405
  129. package/skills/claude-api/typescript/claude-api/batches.md +0 -106
  130. package/skills/claude-api/typescript/claude-api/files-api.md +0 -98
  131. package/skills/claude-api/typescript/claude-api/streaming.md +0 -178
  132. package/skills/claude-api/typescript/claude-api/tool-use.md +0 -586
  133. package/skills/claude-api/typescript/managed-agents/README.md +0 -359
  134. package/tests/auto-permissions.test.mjs +0 -315
  135. package/tests/background-tasks.test.mjs +0 -27
  136. package/tests/background-worker.test.mjs +0 -60
  137. package/tests/bash-permissions.test.mjs +0 -276
  138. package/tests/glob.test.mjs +0 -31
  139. package/tests/mode.test.mjs +0 -62
  140. package/tests/permission-evaluation.test.mjs +0 -70
  141. package/tests/permission-foundation.test.mjs +0 -194
  142. package/tests/permission-policy.test.mjs +0 -158
  143. package/tests/runtime/README.md +0 -51
  144. package/tests/runtime/harness.mjs +0 -190
  145. package/tests/runtime/permissions.test.mjs +0 -192
  146. package/tests/runtime/tui.test.mjs +0 -60
  147. package/tests/task-integration.test.mjs +0 -324
  148. package/tests/task-permissions.test.mjs +0 -178
  149. package/tests/task-worktree-policy.test.mjs +0 -53
@@ -1,394 +0,0 @@
1
- # Managed Agents - Ruby
2
-
3
- > **Bindings not shown here:** This README covers the most common managed-agents flows for Ruby. If you need a class, method, namespace, field, or behavior that isn't shown, WebFetch the Ruby SDK repo **or the relevant docs page** from `shared/live-sources.md` rather than guess. Do not extrapolate from cURL shapes or another language's SDK.
4
-
5
- > **Agents are persistent - create once, reference by ID.** Store the agent ID returned by `client.beta.agents.create` and pass it to every subsequent `client.beta.sessions.create`; do not call `agents.create` in the request path. **Recommended:** define agents and environments as version-controlled YAML applied with the `ant` CLI - see `shared/anthropic-cli.md` (its live-docs URL is in `shared/live-sources.md`). The CLI owns the control plane (create/update); your code owns the data plane (sessions with the stored ID). The examples below show in-code creation for when you must provision programmatically; in production the create call belongs in setup, not in the request path.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- gem install anthropic
11
- ```
12
-
13
- ## Client Initialization
14
-
15
- ```ruby
16
- require "anthropic"
17
-
18
- # Default (uses ANTHROPIC_API_KEY env var)
19
- client = Anthropic::Client.new
20
-
21
- # Explicit API key
22
- client = Anthropic::Client.new(api_key: "your-api-key")
23
- ```
24
-
25
- > Warning: **Trailing underscores:** The Ruby SDK uses `system_:` and `send_(` (trailing underscore) to avoid shadowing `Kernel#system` and `Kernel#send`. Use these forms throughout managed-agents code.
26
-
27
- ---
28
-
29
- ## Create an Environment
30
-
31
- ```ruby
32
- environment = client.beta.environments.create(
33
- name: "my-dev-env",
34
- config: {
35
- type: "cloud",
36
- networking: {type: "unrestricted"}
37
- }
38
- )
39
- puts "Environment ID: #{environment.id}" # env_...
40
- ```
41
-
42
- ---
43
-
44
- ## Create an Agent (required first step)
45
-
46
- > Warning: **There is no inline agent config.** `model`/`system_`/`tools` live on the agent object, not the session. Always start with `client.beta.agents.create()` - the session takes either `agent: agent.id` or the typed hash form `agent: {type: "agent", id: agent.id, version: agent.version}`.
47
-
48
- ### Minimal
49
-
50
- ```ruby
51
- # 1. Create the agent (reusable, versioned)
52
- agent = client.beta.agents.create(
53
- name: "Coding Assistant",
54
- model: :"claude-opus-5",
55
- system_: "You are a helpful coding assistant.",
56
- tools: [{type: "agent_toolset_20260401"}]
57
- )
58
-
59
- # 2. Start a session
60
- session = client.beta.sessions.create(
61
- agent: {type: "agent", id: agent.id, version: agent.version},
62
- environment_id: environment.id,
63
- title: "Quickstart session"
64
- )
65
- puts "Session ID: #{session.id}"
66
- puts "Trace: https://platform.claude.com/workspaces/default/sessions/#{session.id}" # swap 'default' for your workspace ID if the API key is not in the Default workspace
67
- ```
68
-
69
- ### Updating an Agent
70
-
71
- Updates create new versions; the agent object is immutable per version.
72
-
73
- ```ruby
74
- updated_agent = client.beta.agents.update(
75
- agent.id,
76
- version: agent.version,
77
- system_: "You are a helpful coding agent. Always write tests."
78
- )
79
- puts "New version: #{updated_agent.version}"
80
-
81
- # List all versions
82
- client.beta.agents.versions.list(agent.id).auto_paging_each do |version|
83
- puts "Version #{version.version}: #{version.updated_at.iso8601}"
84
- end
85
-
86
- # Archive the agent
87
- archived = client.beta.agents.archive(agent.id)
88
- puts "Archived at: #{archived.archived_at.iso8601}"
89
- ```
90
-
91
- ---
92
-
93
- ## Send a User Message
94
-
95
- ```ruby
96
- client.beta.sessions.events.send_(
97
- session.id,
98
- events: [{
99
- type: "user.message",
100
- content: [{type: "text", text: "Review the auth module"}]
101
- }]
102
- )
103
- ```
104
-
105
- > Tip: **Stream-first:** Open the stream *before* (or concurrently with) sending the message. The stream only delivers events that occur after it opens - stream-after-send means early events arrive buffered in one batch. See [Steering Patterns](../../shared/managed-agents-events.md#steering-patterns).
106
-
107
- ---
108
-
109
- ## Stream Events (SSE)
110
-
111
- ```ruby
112
- # Open the stream first, then send the user message
113
- stream = client.beta.sessions.events.stream_events(session.id)
114
-
115
- client.beta.sessions.events.send_(
116
- session.id,
117
- events: [{
118
- type: "user.message",
119
- content: [{type: "text", text: "Summarize the repo README"}]
120
- }]
121
- )
122
-
123
- stream.each do |event|
124
- case event.type
125
- in :"agent.message"
126
- event.content.each { |block| print block.text }
127
- in :"agent.tool_use"
128
- puts "\n[Using tool: #{event.name}]"
129
- in :"session.status_idle"
130
- break
131
- in :"session.error"
132
- puts "\n[Error: #{event.error&.message || "unknown"}]"
133
- break
134
- else
135
- # ignore other event types
136
- end
137
- end
138
- ```
139
-
140
- > Note: Event `.type` is a Symbol (compare with `:"agent.message"`, not `"agent.message"`).
141
-
142
- ### Reconnecting and Tailing
143
-
144
- When reconnecting mid-session, list past events first to dedupe, then tail live events:
145
-
146
- ```ruby
147
- require "set"
148
-
149
- stream = client.beta.sessions.events.stream_events(session.id)
150
-
151
- # Stream is open and buffering. List history before tailing live.
152
- seen_event_ids = Set.new
153
- client.beta.sessions.events.list(session.id).auto_paging_each { |past| seen_event_ids << past.id }
154
-
155
- # Tail live events, skipping anything already seen
156
- stream.each do |event|
157
- next if seen_event_ids.include?(event.id)
158
- seen_event_ids << event.id
159
- case event.type
160
- in :"agent.message"
161
- event.content.each { |block| print block.text }
162
- in :"session.status_idle"
163
- break
164
- else
165
- # ignore other event types
166
- end
167
- end
168
- ```
169
-
170
- ---
171
-
172
- ## Provide Custom Tool Result
173
-
174
- > Note: The Ruby managed-agents bindings for `user.custom_tool_result` are not yet documented in this skill or in the apps source examples. Refer to `shared/managed-agents-events.md` for the wire format and the `anthropic` Ruby gem repository for the corresponding params.
175
-
176
- ---
177
-
178
- ## Poll Events
179
-
180
- ```ruby
181
- client.beta.sessions.events.list(session.id).auto_paging_each do |event|
182
- puts "#{event.type}: #{event.id}"
183
- end
184
- ```
185
-
186
- ---
187
-
188
- ## Upload a File
189
-
190
- ```ruby
191
- require "pathname"
192
-
193
- file = client.beta.files.upload(file: Pathname("data.csv"))
194
- puts "File ID: #{file.id}"
195
-
196
- # Mount in a session
197
- session = client.beta.sessions.create(
198
- agent: agent.id,
199
- environment_id: environment.id,
200
- resources: [
201
- {
202
- type: "file",
203
- file_id: file.id,
204
- mount_path: "/workspace/data.csv"
205
- }
206
- ]
207
- )
208
- ```
209
-
210
- ### Add and Manage Resources on an Existing Session
211
-
212
- ```ruby
213
- # Attach an additional file to an open session
214
- resource = client.beta.sessions.resources.add(
215
- session.id,
216
- type: "file",
217
- file_id: file.id
218
- )
219
- puts resource.id # "sesrsc_01ABC..."
220
-
221
- # List resources on the session
222
- listed = client.beta.sessions.resources.list(session.id)
223
- listed.data.each { |entry| puts "#{entry.id} #{entry.type}" }
224
-
225
- # Detach a resource
226
- client.beta.sessions.resources.delete(resource.id, session_id: session.id)
227
- ```
228
-
229
- ---
230
-
231
- ## List and Download Session Files
232
-
233
- ```ruby
234
- files = client.beta.files.list(scope_id: "sesn_abc123", betas: ["managed-agents-2026-04-01"])
235
- content = client.beta.files.download(files.data[0].id)
236
- File.binwrite("output.txt", content.read)
237
- ```
238
-
239
- ---
240
-
241
- ## Session Management
242
-
243
- ```ruby
244
- # List environments
245
- environments = client.beta.environments.list
246
-
247
- # Retrieve a specific environment
248
- env = client.beta.environments.retrieve(environment.id)
249
-
250
- # Archive an environment (read-only, existing sessions continue)
251
- client.beta.environments.archive(environment.id)
252
-
253
- # Delete an environment (only if no sessions reference it)
254
- client.beta.environments.delete(environment.id)
255
-
256
- # Delete a session
257
- client.beta.sessions.delete(session.id)
258
- ```
259
-
260
- ---
261
-
262
- ## MCP Server Integration
263
-
264
- ```ruby
265
- # Agent declares MCP server (no auth here - auth goes in a vault)
266
- agent = client.beta.agents.create(
267
- name: "GitHub Assistant",
268
- model: :"claude-opus-5",
269
- mcp_servers: [
270
- {
271
- type: "url",
272
- name: "github",
273
- url: "https://api.githubcopilot.com/mcp/"
274
- }
275
- ],
276
- tools: [
277
- {type: "agent_toolset_20260401"},
278
- {type: "mcp_toolset", mcp_server_name: "github"}
279
- ]
280
- )
281
-
282
- # Session attaches vault(s) containing credentials for those MCP server URLs
283
- session = client.beta.sessions.create(
284
- agent: {type: "agent", id: agent.id, version: agent.version},
285
- environment_id: environment.id,
286
- vault_ids: [vault.id]
287
- )
288
- ```
289
-
290
- See `shared/managed-agents-tools.md` §Vaults for creating vaults and adding credentials.
291
-
292
- ---
293
-
294
- ## Vaults
295
-
296
- ```ruby
297
- # Create a vault
298
- vault = client.beta.vaults.create(
299
- display_name: "Alice",
300
- metadata: {external_user_id: "usr_abc123"}
301
- )
302
- puts vault.id # "vlt_01ABC..."
303
-
304
- # Add an OAuth credential
305
- credential = client.beta.vaults.credentials.create(
306
- vault.id,
307
- display_name: "Alice's Slack",
308
- auth: {
309
- type: "mcp_oauth",
310
- mcp_server_url: "https://mcp.slack.com/mcp",
311
- access_token: "xoxp-...",
312
- expires_at: "2026-04-15T00:00:00Z",
313
- refresh: {
314
- token_endpoint: "https://slack.com/api/oauth.v2.access",
315
- client_id: "1234567890.0987654321",
316
- scope: "channels:read chat:write",
317
- refresh_token: "xoxe-1-...",
318
- token_endpoint_auth: {
319
- type: "client_secret_post",
320
- client_secret: "abc123..."
321
- }
322
- }
323
- }
324
- )
325
-
326
- # Rotate the credential (e.g., after a token refresh)
327
- client.beta.vaults.credentials.update(
328
- credential.id,
329
- vault_id: vault.id,
330
- auth: {
331
- type: "mcp_oauth",
332
- access_token: "xoxp-new-...",
333
- expires_at: "2026-05-15T00:00:00Z",
334
- refresh: {refresh_token: "xoxe-1-new-..."}
335
- }
336
- )
337
-
338
- # Archive a vault
339
- client.beta.vaults.archive(vault.id)
340
- ```
341
-
342
- ---
343
-
344
- ## GitHub Repository Integration
345
-
346
- Mount a GitHub repository as a session resource (a vault holds the GitHub MCP credential):
347
-
348
- ```ruby
349
- session = client.beta.sessions.create(
350
- agent: agent.id,
351
- environment_id: environment.id,
352
- vault_ids: [vault.id],
353
- resources: [
354
- {
355
- type: "github_repository",
356
- url: "https://github.com/org/repo",
357
- mount_path: "/workspace/repo",
358
- authorization_token: "ghp_your_github_token"
359
- }
360
- ]
361
- )
362
- ```
363
-
364
- Multiple repositories on the same session:
365
-
366
- ```ruby
367
- resources = [
368
- {
369
- type: "github_repository",
370
- url: "https://github.com/org/frontend",
371
- mount_path: "/workspace/frontend",
372
- authorization_token: "ghp_your_github_token"
373
- },
374
- {
375
- type: "github_repository",
376
- url: "https://github.com/org/backend",
377
- mount_path: "/workspace/backend",
378
- authorization_token: "ghp_your_github_token"
379
- }
380
- ]
381
- ```
382
-
383
- Rotating a repository's authorization token:
384
-
385
- ```ruby
386
- listed = client.beta.sessions.resources.list(session.id)
387
- repo_resource_id = listed.data.first.id
388
-
389
- client.beta.sessions.resources.update(
390
- repo_resource_id,
391
- session_id: session.id,
392
- authorization_token: "ghp_your_new_github_token"
393
- )
394
- ```
@@ -1,179 +0,0 @@
1
- # Admin API (Organization Management)
2
-
3
- Read this file when the user wants to manage their Anthropic organization programmatically: members and roles, invites, workspaces and workspace members, API keys, rate limit reports, service accounts, workload identity federation (WIF), or customer-managed encryption keys (CMEK).
4
-
5
- The Admin API lives under `https://api.anthropic.com/v1/organizations/*`. It manages the organization itself - it does not send messages. As of **August 26, 2026** it is available in all seven SDKs (Python, TypeScript, C#, Go, Java, PHP, Ruby) under `client.beta.organization`, and in the `ant` CLI under `ant beta:organization`. Usage reports, cost reports, and the Claude Enterprise user-management and analytics endpoints are **not** in the SDKs - call those with raw HTTP.
6
-
7
- ## Authentication
8
-
9
- Two credential types, both read automatically by the default SDK client and the CLI:
10
-
11
- | Credential | Env var | HTTP header | Covers |
12
- | --- | --- | --- | --- |
13
- | Admin API key (`sk-ant-admin...`) | `ANTHROPIC_API_KEY` | `x-api-key` | Most endpoints |
14
- | `org:admin` OAuth token | `ANTHROPIC_AUTH_TOKEN` | `authorization: Bearer` | Everything, including the OAuth-only endpoints |
15
-
16
- - **OAuth-only endpoints:** service accounts, federation issuers, and federation rules reject API keys - they require an `org:admin` OAuth token.
17
- - **Precedence gotcha:** when both env vars are set, some clients prefer the API key. When using a bearer token, leave `ANTHROPIC_API_KEY` unset in that shell.
18
- - Admin API keys are created in the Claude Console by organization admins.
19
- - Regular (non-admin) API keys do not work on any of these endpoints, and admin credentials do not work on the Messages API.
20
- - An `org:admin` token grants access to the whole organization regardless of any workspace binding.
21
-
22
- **Interactive OAuth token** - log in with the `ant` CLI under a dedicated profile (keeps routine commands from running with elevated access), then export the token. Tokens are short-lived; on 401, re-run the export. Profile and scope mechanics (why `org:admin` needs an explicit `--scope`, switching profiles): `shared/anthropic-cli.md`.
23
-
24
- ```bash
25
- ant auth login --profile admin --scope "org:admin"
26
- export ANTHROPIC_AUTH_TOKEN=$(ant auth print-credentials --profile admin --access-token)
27
- # When done: unset ANTHROPIC_AUTH_TOKEN && ant profile activate default
28
- ```
29
-
30
- **Automated workloads (CI)** - don't log in interactively. Create a federation rule with `oauth_scope: org:admin` targeting a service account whose `organization_role` is `admin` (this one rule must be created by a human in the Claude Console), then point the client at it with the federation env vars and construct it with no arguments - the SDK/CLI performs the token exchange automatically and refreshes before expiry:
31
-
32
- ```bash
33
- export ANTHROPIC_FEDERATION_RULE_ID=fdrl_... # the org:admin rule
34
- export ANTHROPIC_ORGANIZATION_ID=<org-uuid>
35
- export ANTHROPIC_SERVICE_ACCOUNT_ID=svac_... # the rule's target service account
36
- export ANTHROPIC_IDENTITY_TOKEN_FILE=/path/to/jwt # or ANTHROPIC_IDENTITY_TOKEN
37
- ```
38
-
39
- **curl** also needs `anthropic-version: 2023-06-01` on every request.
40
-
41
- ## Endpoint Coverage
42
-
43
- SDK accessor shown in Python spelling; see the per-language table below for naming conventions.
44
-
45
- | Resource | REST path | SDK accessor (`client.beta.organization` +) | CLI (`ant beta:organization` +) |
46
- | --- | --- | --- | --- |
47
- | Organization info | `GET /v1/organizations/me` | `.retrieve()` | `retrieve` |
48
- | Members | `/v1/organizations/users` | `.users` - `list`, `update`, `remove` | `:users list\|update\|remove` |
49
- | Invites | `/v1/organizations/invites` | `.invites` - `create`, `list`, `delete` | `:invites create\|list\|delete` |
50
- | Workspaces | `/v1/organizations/workspaces` | `.workspaces` - `create`, `retrieve`, `list`, `update`, `archive` | `:workspaces create\|list\|update\|archive` |
51
- | Workspace members | `/v1/organizations/workspaces/{id}/members` | `.workspaces.members` - `add`, `list`, `update`, `remove` | `:workspaces:members add\|list\|update\|remove` |
52
- | API keys | `/v1/organizations/api_keys` | `.api_keys` - `list`, `update` | `:api-keys list\|update` |
53
- | Org rate limits | `GET /v1/organizations/rate_limits` | `.rate_limits.list(model=..., group_type=...)` | `:rate-limits list` |
54
- | Workspace rate limits | `GET /v1/organizations/workspaces/{id}/rate_limits` | `.workspaces.rate_limits.list(workspace_id)` | `:workspaces:rate-limits list` |
55
- | Service accounts (*) | `/v1/organizations/service_accounts` | `.service_accounts` - `create`, `list`, `archive` | `:service-accounts create\|list\|archive` |
56
- | Federation issuers (*) | `/v1/organizations/federation_issuers` | `.federation.issuers` - `create`, `list`, `archive` | `:federation:issuers create\|list\|archive` |
57
- | Federation rules (*) | `/v1/organizations/federation_rules` | `.federation.rules` - `create`, `list`, `archive` | `:federation:rules create\|list\|archive` |
58
- | CMEK external keys | `/v1/organizations/external_keys` | `.external_keys` - `create`, `validate` | - |
59
-
60
- (*) OAuth-only: requires an `org:admin` bearer token, not an API key.
61
-
62
- Attaching a CMEK external key to a workspace is a workspace update: `client.beta.organization.workspaces.update("<workspace-id>", external_key_id="ekey_...")`.
63
-
64
- ## Per-Language Naming & Pagination
65
-
66
- | Language | Accessor style (list members example) | List behavior |
67
- | --- | --- | --- |
68
- | Python | `client.beta.organization.users.list(limit=10)` | Iterator auto-fetches more pages; `limit` = page size, not total |
69
- | TypeScript | `client.beta.organization.users.list({ limit: 10 })` - camelCase sub-resources: `apiKeys`, `rateLimits`, `serviceAccounts`, `externalKeys` | `for await` auto-pages |
70
- | C# | `client.Beta.Organization.Users.List(new() { Limit = 10 })` | `await foreach (var u in page.Paginate())` auto-pages |
71
- | Go | `client.Beta.Organization.Users.ListAutoPaging(ctx, params)`; org info is `Organization.Get(ctx)` | `.Next()` / `.Current()` auto-pages |
72
- | Java | `client.beta().organization().users().list(params)` with builder params (`UserListParams.builder().limit(10).build()`) | `.autoPager()` auto-pages |
73
- | PHP | `$client->beta->organization->users->list(limit: 10)` | Raw single-page data call - iterate `->getItems()`; the SDK's auto-pagination helpers aren't wired up for these endpoints yet |
74
- | Ruby | `client.beta.organization.users.list(limit: 10)` | Raw single-page data call - iterate `.data`; the SDK's auto-pagination helpers aren't wired up for these endpoints yet |
75
- | CLI | `ant beta:organization:users list --limit 10` | On the member, invite, workspace, workspace-member, and API-key lists, `--limit` caps the results (unlike most `ant` list commands, where `--limit` sets the page size and `--max-items` caps - see `shared/anthropic-cli.md`) |
76
- | curl | `GET /v1/organizations/users?limit=10` | One page per request; cursor pagination per the Admin API reference |
77
-
78
- The rate-limit lists (`rate_limits`, `workspaces.rate_limits`) also support pagination as of launch - page them like the other list endpoints rather than assuming a single response.
79
-
80
- Go param types follow the pattern `anthropic.BetaOrganizationUserListParams` (with `anthropic.Int(10)` for `Limit`); Java params use builders from `com.anthropic.models.beta.organization.*` (e.g. `UserListParams.builder().limit(10).build()`). The Go and Java pagination loops:
81
-
82
- ```go
83
- users := client.Beta.Organization.Users.ListAutoPaging(ctx, anthropic.BetaOrganizationUserListParams{Limit: anthropic.Int(10)})
84
- for users.Next() {
85
- user := users.Current() // ...
86
- }
87
- if err := users.Err(); err != nil { /* handle */ }
88
- ```
89
-
90
- ```java
91
- for (var user : client.beta().organization().users().list(params).autoPager()) { /* ... */ }
92
- ```
93
-
94
- ## Examples
95
-
96
- Common operations (Python spelling; map to other languages with the table above - every operation follows the same shape in each language):
97
-
98
- ```python
99
- # Organization info
100
- org = client.beta.organization.retrieve()
101
-
102
- # List members (iterator auto-fetches more pages; limit = page size)
103
- for user in client.beta.organization.users.list(limit=10):
104
- print(f"{user.id}: {user.email} ({user.role})")
105
-
106
- # Change a member's role / remove a member
107
- client.beta.organization.users.update("user_...", role="developer")
108
- client.beta.organization.users.remove("user_...")
109
-
110
- # Invite someone
111
- client.beta.organization.invites.create(email="user@example.com", role="developer")
112
-
113
- # Create a workspace and add a member to it
114
- ws = client.beta.organization.workspaces.create(name="Production")
115
- client.beta.organization.workspaces.members.add(
116
- ws.id, user_id="user_...", workspace_role="workspace_developer"
117
- )
118
-
119
- # Deactivate / rename an API key
120
- client.beta.organization.api_keys.update("apikey_...", status="inactive", name="New Key Name")
121
-
122
- # Rate limit reports (optional filters: model=..., group_type=...)
123
- client.beta.organization.rate_limits.list(model="claude-opus-5")
124
- client.beta.organization.workspaces.rate_limits.list("wrkspc_...")
125
-
126
- # Service accounts + WIF (org:admin OAuth token required)
127
- sa = client.beta.organization.service_accounts.create(name="inference-worker", organization_role="developer")
128
- issuer = client.beta.organization.federation.issuers.create(
129
- name="github-actions",
130
- issuer_url="https://token.actions.githubusercontent.com",
131
- jwks={"type": "discovery"},
132
- )
133
- client.beta.organization.federation.rules.create(
134
- name="gha-deploy",
135
- issuer_id=issuer.id,
136
- match={"subject_prefix": "repo:my-org/my-repo:ref:refs/heads/main",
137
- "claims": {"repository_owner": "my-org"}},
138
- target={"type": "service_account", "service_account_id": sa.id},
139
- workspace_id="wrkspc_...",
140
- oauth_scope="workspace:developer",
141
- token_lifetime_seconds=600,
142
- )
143
-
144
- # CMEK: register, validate, then attach an external key to a workspace
145
- key = client.beta.organization.external_keys.create(
146
- display_name="prod-key", geo="us",
147
- provider_config={"type": "aws", "kms_arn": "arn:aws:kms:..."},
148
- )
149
- client.beta.organization.external_keys.validate(key.id)
150
- client.beta.organization.workspaces.update("wrkspc_...", external_key_id=key.id)
151
- ```
152
-
153
- ## Organization Roles
154
-
155
- | Role | Permissions |
156
- | --- | --- |
157
- | `user` | Playground |
158
- | `claude_code_user` | Playground + Claude Code |
159
- | `developer` | Playground + manage API keys |
160
- | `billing` | Playground + manage billing |
161
- | `admin` | All of the above + manage users |
162
-
163
- Owners and primary owners have all admin permissions and can also manage admins. Workspace roles are `workspace_user`, `workspace_developer`, `workspace_admin`, and `workspace_billing`.
164
-
165
- ## Platform Restrictions
166
-
167
- - **Claude Platform on AWS:** only the workspace endpoints work. Members, workspace members, invites, API keys, and usage/cost/rate-limit reports are unavailable. CMEK external-key endpoints are not yet available there - register and attach keys in the Claude Console.
168
- - **Claude Enterprise (claude.ai orgs):** only members and invites from this surface, plus Enterprise-only endpoints (group and custom-role reads, spend limits) that are not in the SDKs.
169
-
170
- ## Live Docs
171
-
172
- | Topic | URL |
173
- | --- | --- |
174
- | Admin API guide | `https://platform.claude.com/docs/en/manage-claude/admin-api.md` |
175
- | Admin API reference | `https://platform.claude.com/docs/en/api/admin.md` |
176
- | Workspaces | `https://platform.claude.com/docs/en/manage-claude/workspaces.md` |
177
- | Rate limits API | `https://platform.claude.com/docs/en/manage-claude/rate-limits-api.md` |
178
- | WIF admin | `https://platform.claude.com/docs/en/manage-claude/wif-admin-api.md` |
179
- | Usage & cost reports (curl-only) | `https://platform.claude.com/docs/en/manage-claude/usage-cost-api.md` |
@@ -1,101 +0,0 @@
1
- # Agent Design Patterns
2
-
3
- This file covers decision heuristics for building agents on the Claude API: which primitives to reach for, how to design your tool surface, and how to manage context and cost over long runs. For per-tool mechanics and code examples, see `tool-use-concepts.md` and the language-specific folders.
4
-
5
- ---
6
-
7
- ## Model Parameters
8
-
9
- | Parameter | When to use it | What to expect |
10
- | --- | --- | --- |
11
- | **Adaptive thinking** (`thinking: {type: "adaptive"}`) | When you want Claude to control when and how much to think. | Claude determines thinking depth per request and automatically interleaves thinking between tool calls. No token budget to tune. |
12
- | **Effort** (`output_config: {effort: ...}`) | When adjusting the tradeoff between thoroughness and token efficiency. | Lower effort -> fewer and more-consolidated tool calls, less preamble, terser confirmations. `medium` is often a favorable balance. Use `max` when correctness matters more than cost. |
13
-
14
- See `SKILL.md` §Thinking & Effort for model support and parameter details.
15
-
16
- ---
17
-
18
- ## Designing Your Tool Surface
19
-
20
- ### Bash vs. dedicated tools
21
-
22
- Claude doesn't know your application's security boundary, approval policy, or UX surface. Claude emits tool calls; your harness handles them. The shape of those tool calls determines what the harness can do.
23
-
24
- A **bash tool** gives Claude broad programmatic leverage - it can perform almost any action. But it gives the harness only an opaque command string, the same shape for every action. Promoting an action to a **dedicated tool** gives the harness an action-specific hook with typed arguments it can intercept, gate, render, or audit.
25
-
26
- **When to promote an action to a dedicated tool:**
27
-
28
- - **Security boundary.** Actions that require gating are natural candidates. Reversibility is a useful criterion: hard-to-reverse actions (external API calls, sending messages, deleting data) can be gated behind user confirmation. A `send_email` tool is easy to gate; `bash -c "curl -X POST ..."` is not.
29
- - **Staleness checks.** A dedicated `edit` tool can reject writes if the file changed since Claude last read it. Bash can't enforce that invariant.
30
- - **Rendering.** Some actions benefit from custom UI. Claude Code promotes question-asking to a tool so it can render as a modal, present options, and block the agent loop until answered.
31
- - **Scheduling.** Read-only tools like `glob` and `grep` can be marked parallel-safe. When the same actions run through bash, the harness can't tell a parallel-safe `grep` from a parallel-unsafe `git push`, so it must serialize.
32
-
33
- **Rule of thumb:** Start with bash for breadth. Promote to dedicated tools when you need to gate, render, audit, or parallelize the action.
34
-
35
- ---
36
-
37
- ## Anthropic-Provided Tools
38
-
39
- | Tool | Side | When to use it | What to expect |
40
- | --- | --- | --- | --- |
41
- | **Bash** | Client | Claude needs to execute shell commands. | Claude emits commands; your harness executes them. Reference implementation provided. |
42
- | **Text editor** | Client | Claude needs to read or edit files. | Claude views, creates, and edits files via your implementation. Reference implementation provided. |
43
- | **Computer use** | Client or Server | Claude needs to interact with GUIs, web apps, or visual interfaces. | Claude takes screenshots and issues mouse/keyboard commands. Can be self-hosted (you run the environment) or Anthropic-hosted. |
44
- | **Code execution** | Server | Claude needs to run code in a sandbox you don't want to manage. | Anthropic-hosted container with built-in file and bash sub-tools. No client-side execution. |
45
- | **Web search / fetch** | Server | Claude needs information past its training cutoff (news, current events, recent docs) or the content of a specific URL. | Claude issues a query or URL; Anthropic executes it and returns results with citations. |
46
- | **Memory** | Client | Claude needs to save context across sessions. | Claude reads/writes a `/memories` directory. You implement the storage backend. |
47
-
48
- **Client-side** tools are defined by Anthropic (name, schema, Claude's usage pattern) but executed by your harness. Anthropic provides reference implementations. **Server-side** tools run entirely on Anthropic infrastructure - declare them in `tools` and Claude handles the rest.
49
-
50
- ---
51
-
52
- ## Composing Tool Calls: Programmatic Tool Calling
53
-
54
- With standard tool use, each tool call is a round trip: Claude calls the tool, the result lands in Claude's context, Claude reasons about it, then calls the next tool. Three sequential actions (read profile -> look up orders -> check inventory) means three round trips. Each adds latency and tokens, and most of the intermediate data is never needed again.
55
-
56
- **Programmatic tool calling (PTC)** lets Claude compose those calls into a script instead. The script runs in the code execution container. When the script calls a tool, the container pauses, the call is executed (client-side or server-side), and the result returns to the running code - not to Claude's context. The script processes it with normal control flow (loops, filters, branches). Only the script's final output returns to Claude.
57
-
58
- | When to use it | What to expect |
59
- | --- | --- |
60
- | Many sequential tool calls, or large intermediate results you want filtered before they hit the context window. | Claude writes code that invokes tools as functions. Runs in the code execution container. Token cost scales with final output, not intermediate results. |
61
-
62
- ---
63
-
64
- ## Scaling the Tool and Instruction Set
65
-
66
- | Feature | When to use it | What to expect |
67
- | --- | --- | --- |
68
- | **Tool search** | Many tools available, but only a few relevant per request. Don't want all schemas in context upfront. | Claude searches the tool set and loads only relevant schemas. Tool definitions are appended, not swapped - preserves cache (see Caching below). |
69
- | **Skills** | Task-specific instructions Claude should load only when relevant. | Each skill is a folder with a `SKILL.md`. The skill's description sits in context by default; Claude reads the full file when the task calls for it. |
70
-
71
- Both patterns keep the fixed context small and load detail on demand.
72
-
73
- ---
74
-
75
- ## Long-Running Agents: Managing Context
76
-
77
- | Pattern | When to use it | What to expect |
78
- | --- | --- | --- |
79
- | **Context editing** | Context grows stale over many turns (old tool results, completed thinking). | Tool results and thinking blocks are cleared based on configurable thresholds. Keeps the transcript lean without summarizing. |
80
- | **Compaction** | Conversation likely to reach or exceed the context window limit. | Earlier context is summarized into a compaction block server-side. See `SKILL.md` §Compaction for the critical `response.content` handling. |
81
- | **Memory** | State must persist across sessions (not just within one conversation). | Claude reads/writes files in a memory directory. Survives process restarts. |
82
-
83
- **Choosing between them:** Context editing and compaction operate within a session - editing prunes stale turns, compaction summarizes when you're near the limit. Memory is for cross-session persistence. Many long-running agents use all three.
84
-
85
- ---
86
-
87
- ## Caching for Agents
88
-
89
- **Read `prompt-caching.md` first.** It covers the prefix-match invariant, breakpoint placement, the silent-invalidator audit, and why changing tools or models mid-session breaks the cache. This section covers only the agent-specific workarounds for those constraints.
90
-
91
- | Constraint (from `prompt-caching.md`) | Agent-specific workaround |
92
- | --- | --- |
93
- | Editing the system prompt mid-session invalidates the cache. | Append a `{"role": "system", ...}` message to `messages[]` instead (no beta header; on supporting models - see `prompt-caching.md` § Mid-conversation system messages). The cached prefix stays intact, and the model treats it as an operator-authority instruction rather than user text. On models that don't support it, fall back to a `<system-reminder>` text block in the user turn. |
94
- | Switching models mid-session invalidates the cache. | Spawn a **subagent** with the cheaper model for the sub-task; keep the main loop on one model. On Managed Agents that is a `multiagent` roster entry - see `managed-agents-multiagent.md`. |
95
- | Adding/removing tools mid-session invalidates the cache. | Use **tool search** for dynamic discovery - it appends tool schemas rather than swapping them, so the existing prefix is preserved. |
96
-
97
- For multi-turn breakpoint placement, use the combination in `prompt-caching.md` § Automatic vs explicit breakpoints: one explicit breakpoint on the static system prefix plus top-level automatic caching for the conversation tail (where automatic caching is available).
98
-
99
- ---
100
-
101
- For live documentation on any of these features, see `live-sources.md`.