opencode-skills-antigravity 1.0.4 → 1.0.6
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/bundled-skills/ad-creative/SKILL.md +371 -0
- package/bundled-skills/ad-creative/evals/evals.json +90 -0
- package/bundled-skills/ad-creative/references/generative-tools.md +637 -0
- package/bundled-skills/ad-creative/references/platform-specs.md +213 -0
- package/bundled-skills/ai-seo/SKILL.md +407 -0
- package/bundled-skills/ai-seo/evals/evals.json +90 -0
- package/bundled-skills/ai-seo/references/content-patterns.md +285 -0
- package/bundled-skills/ai-seo/references/platform-ranking-factors.md +152 -0
- package/bundled-skills/backend-dev-guidelines/SKILL.md +1 -1
- package/bundled-skills/cc-skill-security-review/SKILL.md +1 -1
- package/bundled-skills/churn-prevention/SKILL.md +433 -0
- package/bundled-skills/churn-prevention/evals/evals.json +93 -0
- package/bundled-skills/churn-prevention/references/cancel-flow-patterns.md +316 -0
- package/bundled-skills/churn-prevention/references/dunning-playbook.md +408 -0
- package/bundled-skills/claude-api/LICENSE.txt +202 -0
- package/bundled-skills/claude-api/SKILL.md +252 -0
- package/bundled-skills/claude-api/csharp/claude-api.md +70 -0
- package/bundled-skills/claude-api/curl/examples.md +164 -0
- package/bundled-skills/claude-api/go/claude-api.md +146 -0
- package/bundled-skills/claude-api/java/claude-api.md +128 -0
- package/bundled-skills/claude-api/php/claude-api.md +88 -0
- package/bundled-skills/claude-api/python/agent-sdk/README.md +269 -0
- package/bundled-skills/claude-api/python/agent-sdk/patterns.md +319 -0
- package/bundled-skills/claude-api/python/claude-api/README.md +404 -0
- package/bundled-skills/claude-api/python/claude-api/batches.md +182 -0
- package/bundled-skills/claude-api/python/claude-api/files-api.md +162 -0
- package/bundled-skills/claude-api/python/claude-api/streaming.md +162 -0
- package/bundled-skills/claude-api/python/claude-api/tool-use.md +587 -0
- package/bundled-skills/claude-api/ruby/claude-api.md +87 -0
- package/bundled-skills/claude-api/shared/error-codes.md +205 -0
- package/bundled-skills/claude-api/shared/live-sources.md +121 -0
- package/bundled-skills/claude-api/shared/models.md +68 -0
- package/bundled-skills/claude-api/shared/tool-use-concepts.md +305 -0
- package/bundled-skills/claude-api/typescript/agent-sdk/README.md +220 -0
- package/bundled-skills/claude-api/typescript/agent-sdk/patterns.md +150 -0
- package/bundled-skills/claude-api/typescript/claude-api/README.md +313 -0
- package/bundled-skills/claude-api/typescript/claude-api/batches.md +106 -0
- package/bundled-skills/claude-api/typescript/claude-api/files-api.md +98 -0
- package/bundled-skills/claude-api/typescript/claude-api/streaming.md +178 -0
- package/bundled-skills/claude-api/typescript/claude-api/tool-use.md +477 -0
- package/bundled-skills/codex-review/SKILL.md +1 -1
- package/bundled-skills/cold-email/SKILL.md +167 -0
- package/bundled-skills/cold-email/evals/evals.json +94 -0
- package/bundled-skills/cold-email/references/benchmarks.md +83 -0
- package/bundled-skills/cold-email/references/follow-up-sequences.md +81 -0
- package/bundled-skills/cold-email/references/frameworks.md +90 -0
- package/bundled-skills/cold-email/references/personalization.md +79 -0
- package/bundled-skills/cold-email/references/subject-lines.md +53 -0
- package/bundled-skills/content-strategy/SKILL.md +374 -0
- package/bundled-skills/content-strategy/evals/evals.json +90 -0
- package/bundled-skills/content-strategy/references/headless-cms.md +194 -0
- package/bundled-skills/context7-auto-research/SKILL.md +1 -1
- package/bundled-skills/dbos-golang/SKILL.md +1 -1
- package/bundled-skills/dbos-python/SKILL.md +1 -1
- package/bundled-skills/dbos-typescript/SKILL.md +1 -1
- package/bundled-skills/debug-buttercup/SKILL.md +1 -1
- package/bundled-skills/defuddle/SKILL.md +50 -0
- package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
- package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
- package/bundled-skills/docs/integrations/jetski-gemini-loader/package.json +1 -0
- package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
- package/bundled-skills/docs/maintainers/skills-import-2026-03-21.md +81 -0
- package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
- package/bundled-skills/docs/users/bundles.md +1 -1
- package/bundled-skills/docs/users/claude-code-skills.md +1 -1
- package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
- package/bundled-skills/docs/users/getting-started.md +1 -1
- package/bundled-skills/docs/users/kiro-integration.md +1 -1
- package/bundled-skills/docs/users/usage.md +4 -4
- package/bundled-skills/docs/users/visual-guide.md +4 -4
- package/bundled-skills/evaluation/SKILL.md +1 -1
- package/bundled-skills/exa-search/SKILL.md +1 -1
- package/bundled-skills/firecrawl-scraper/SKILL.md +1 -1
- package/bundled-skills/frontend-dev-guidelines/SKILL.md +1 -1
- package/bundled-skills/gha-security-review/SKILL.md +2 -1
- package/bundled-skills/git-pushing/SKILL.md +1 -1
- package/bundled-skills/internal-comms/LICENSE.txt +202 -0
- package/bundled-skills/internal-comms/SKILL.md +35 -0
- package/bundled-skills/internal-comms/examples/3p-updates.md +47 -0
- package/bundled-skills/internal-comms/examples/company-newsletter.md +65 -0
- package/bundled-skills/internal-comms/examples/faq-answers.md +30 -0
- package/bundled-skills/internal-comms/examples/general-comms.md +16 -0
- package/bundled-skills/json-canvas/SKILL.md +253 -0
- package/bundled-skills/json-canvas/references/EXAMPLES.md +329 -0
- package/bundled-skills/lead-magnets/SKILL.md +319 -0
- package/bundled-skills/lead-magnets/references/benchmarks.md +129 -0
- package/bundled-skills/lead-magnets/references/format-guide.md +196 -0
- package/bundled-skills/memory-systems/SKILL.md +1 -1
- package/bundled-skills/obsidian-bases/SKILL.md +506 -0
- package/bundled-skills/obsidian-bases/references/FUNCTIONS_REFERENCE.md +173 -0
- package/bundled-skills/obsidian-cli/SKILL.md +115 -0
- package/bundled-skills/obsidian-markdown/SKILL.md +205 -0
- package/bundled-skills/obsidian-markdown/references/CALLOUTS.md +58 -0
- package/bundled-skills/obsidian-markdown/references/EMBEDS.md +63 -0
- package/bundled-skills/obsidian-markdown/references/PROPERTIES.md +61 -0
- package/bundled-skills/product-marketing-context/SKILL.md +250 -0
- package/bundled-skills/product-marketing-context/evals/evals.json +85 -0
- package/bundled-skills/react-best-practices/SKILL.md +1 -1
- package/bundled-skills/revops/SKILL.md +352 -0
- package/bundled-skills/revops/evals/evals.json +91 -0
- package/bundled-skills/revops/references/automation-playbooks.md +290 -0
- package/bundled-skills/revops/references/lifecycle-definitions.md +278 -0
- package/bundled-skills/revops/references/routing-rules.md +203 -0
- package/bundled-skills/revops/references/scoring-models.md +247 -0
- package/bundled-skills/sales-enablement/SKILL.md +358 -0
- package/bundled-skills/sales-enablement/evals/evals.json +91 -0
- package/bundled-skills/sales-enablement/references/deck-frameworks.md +263 -0
- package/bundled-skills/sales-enablement/references/demo-scripts.md +355 -0
- package/bundled-skills/sales-enablement/references/objection-library.md +270 -0
- package/bundled-skills/sales-enablement/references/one-pager-templates.md +208 -0
- package/bundled-skills/seo/SKILL.md +139 -0
- package/bundled-skills/seo/references/cwv-thresholds.md +108 -0
- package/bundled-skills/seo/references/eeat-framework.md +214 -0
- package/bundled-skills/seo/references/quality-gates.md +155 -0
- package/bundled-skills/seo/references/schema-types.md +118 -0
- package/bundled-skills/seo-competitor-pages/SKILL.md +229 -0
- package/bundled-skills/seo-content/SKILL.md +186 -0
- package/bundled-skills/seo-dataforseo/SKILL.md +395 -0
- package/bundled-skills/seo-geo/SKILL.md +254 -0
- package/bundled-skills/seo-hreflang/SKILL.md +209 -0
- package/bundled-skills/seo-image-gen/SKILL.md +183 -0
- package/bundled-skills/seo-images/SKILL.md +193 -0
- package/bundled-skills/seo-page/SKILL.md +103 -0
- package/bundled-skills/seo-plan/SKILL.md +136 -0
- package/bundled-skills/seo-plan/assets/agency.md +175 -0
- package/bundled-skills/seo-plan/assets/ecommerce.md +167 -0
- package/bundled-skills/seo-plan/assets/generic.md +144 -0
- package/bundled-skills/seo-plan/assets/local-service.md +160 -0
- package/bundled-skills/seo-plan/assets/publisher.md +153 -0
- package/bundled-skills/seo-plan/assets/saas.md +135 -0
- package/bundled-skills/seo-programmatic/SKILL.md +184 -0
- package/bundled-skills/seo-schema/SKILL.md +178 -0
- package/bundled-skills/seo-sitemap/SKILL.md +129 -0
- package/bundled-skills/seo-technical/SKILL.md +175 -0
- package/bundled-skills/site-architecture/SKILL.md +366 -0
- package/bundled-skills/site-architecture/evals/evals.json +88 -0
- package/bundled-skills/site-architecture/references/mermaid-templates.md +216 -0
- package/bundled-skills/site-architecture/references/navigation-patterns.md +305 -0
- package/bundled-skills/site-architecture/references/site-type-templates.md +293 -0
- package/bundled-skills/skill-improver/SKILL.md +1 -1
- package/bundled-skills/tavily-web/SKILL.md +1 -1
- package/bundled-skills/test-fixing/SKILL.md +1 -1
- package/bundled-skills/tool-design/SKILL.md +1 -1
- package/bundled-skills/ui-ux-pro-max/SKILL.md +1 -1
- package/bundled-skills/verification-before-completion/SKILL.md +1 -1
- package/bundled-skills/wiki-changelog/SKILL.md +1 -1
- package/bundled-skills/wiki-onboarding/SKILL.md +1 -1
- package/bundled-skills/wiki-qa/SKILL.md +1 -1
- package/bundled-skills/wiki-researcher/SKILL.md +1 -1
- package/bundled-skills/wiki-vitepress/SKILL.md +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Claude API — Java
|
|
2
|
+
|
|
3
|
+
> **Note:** The Java SDK supports the Claude API and beta tool use with annotated classes. Agent SDK is not yet available for Java.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Maven:
|
|
8
|
+
|
|
9
|
+
```xml
|
|
10
|
+
<dependency>
|
|
11
|
+
<groupId>com.anthropic</groupId>
|
|
12
|
+
<artifactId>anthropic-java</artifactId>
|
|
13
|
+
<version>2.15.0</version>
|
|
14
|
+
</dependency>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Gradle:
|
|
18
|
+
|
|
19
|
+
```groovy
|
|
20
|
+
implementation("com.anthropic:anthropic-java:2.15.0")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Client Initialization
|
|
24
|
+
|
|
25
|
+
```java
|
|
26
|
+
import com.anthropic.client.AnthropicClient;
|
|
27
|
+
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
|
|
28
|
+
|
|
29
|
+
// Default (reads ANTHROPIC_API_KEY from environment)
|
|
30
|
+
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
|
|
31
|
+
|
|
32
|
+
// Explicit API key
|
|
33
|
+
AnthropicClient client = AnthropicOkHttpClient.builder()
|
|
34
|
+
.apiKey("your-api-key")
|
|
35
|
+
.build();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Basic Message Request
|
|
41
|
+
|
|
42
|
+
```java
|
|
43
|
+
import com.anthropic.models.messages.MessageCreateParams;
|
|
44
|
+
import com.anthropic.models.messages.Message;
|
|
45
|
+
import com.anthropic.models.messages.Model;
|
|
46
|
+
|
|
47
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
48
|
+
.model(Model.CLAUDE_OPUS_4_6)
|
|
49
|
+
.maxTokens(1024L)
|
|
50
|
+
.addUserMessage("What is the capital of France?")
|
|
51
|
+
.build();
|
|
52
|
+
|
|
53
|
+
Message response = client.messages().create(params);
|
|
54
|
+
response.content().stream()
|
|
55
|
+
.flatMap(block -> block.text().stream())
|
|
56
|
+
.forEach(textBlock -> System.out.println(textBlock.text()));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Streaming
|
|
62
|
+
|
|
63
|
+
```java
|
|
64
|
+
import com.anthropic.core.http.StreamResponse;
|
|
65
|
+
import com.anthropic.models.messages.RawMessageStreamEvent;
|
|
66
|
+
|
|
67
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
68
|
+
.model(Model.CLAUDE_OPUS_4_6)
|
|
69
|
+
.maxTokens(1024L)
|
|
70
|
+
.addUserMessage("Write a haiku")
|
|
71
|
+
.build();
|
|
72
|
+
|
|
73
|
+
try (StreamResponse<RawMessageStreamEvent> streamResponse = client.messages().createStreaming(params)) {
|
|
74
|
+
streamResponse.stream()
|
|
75
|
+
.flatMap(event -> event.contentBlockDelta().stream())
|
|
76
|
+
.flatMap(deltaEvent -> deltaEvent.delta().text().stream())
|
|
77
|
+
.forEach(textDelta -> System.out.print(textDelta.text()));
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Tool Use (Beta)
|
|
84
|
+
|
|
85
|
+
The Java SDK supports beta tool use with annotated classes. Tool classes implement `Supplier<String>` for automatic execution via `BetaToolRunner`.
|
|
86
|
+
|
|
87
|
+
### Tool Runner (automatic loop)
|
|
88
|
+
|
|
89
|
+
```java
|
|
90
|
+
import com.anthropic.models.beta.messages.MessageCreateParams;
|
|
91
|
+
import com.anthropic.models.beta.messages.BetaMessage;
|
|
92
|
+
import com.anthropic.helpers.BetaToolRunner;
|
|
93
|
+
import com.fasterxml.jackson.annotation.JsonClassDescription;
|
|
94
|
+
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
|
|
95
|
+
import java.util.function.Supplier;
|
|
96
|
+
|
|
97
|
+
@JsonClassDescription("Get the weather in a given location")
|
|
98
|
+
static class GetWeather implements Supplier<String> {
|
|
99
|
+
@JsonPropertyDescription("The city and state, e.g. San Francisco, CA")
|
|
100
|
+
public String location;
|
|
101
|
+
|
|
102
|
+
@Override
|
|
103
|
+
public String get() {
|
|
104
|
+
return "The weather in " + location + " is sunny and 72°F";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
BetaToolRunner toolRunner = client.beta().messages().toolRunner(
|
|
109
|
+
MessageCreateParams.builder()
|
|
110
|
+
.model("claude-opus-4-6")
|
|
111
|
+
.maxTokens(1024L)
|
|
112
|
+
.putAdditionalHeader("anthropic-beta", "structured-outputs-2025-11-13")
|
|
113
|
+
.addTool(GetWeather.class)
|
|
114
|
+
.addUserMessage("What's the weather in San Francisco?")
|
|
115
|
+
.build());
|
|
116
|
+
|
|
117
|
+
for (BetaMessage message : toolRunner) {
|
|
118
|
+
System.out.println(message);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Non-Beta Tool Use
|
|
123
|
+
|
|
124
|
+
Tool use is also available through the non-beta `com.anthropic.models.messages.MessageCreateParams` with `addTool(Tool)` for manually defined JSON schemas, without needing the beta namespace. The beta namespace is only needed for the class-annotation convenience layer (`@JsonClassDescription`, `BetaToolRunner`).
|
|
125
|
+
|
|
126
|
+
### Manual Loop
|
|
127
|
+
|
|
128
|
+
For manual tool loops, define tools as JSON schema in the request, handle `tool_use` blocks in the response, send `tool_result` back, and loop until `stop_reason` is `"end_turn"`. See the [shared tool use concepts](../shared/tool-use-concepts.md) for the agentic loop pattern.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Claude API — PHP
|
|
2
|
+
|
|
3
|
+
> **Note:** The PHP SDK is the official Anthropic SDK for PHP. Tool runner and Agent SDK are not available. Bedrock, Vertex AI, and Foundry clients are supported.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
composer require "anthropic-ai/sdk"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Client Initialization
|
|
12
|
+
|
|
13
|
+
```php
|
|
14
|
+
use Anthropic\Client;
|
|
15
|
+
|
|
16
|
+
// Using API key from environment variable
|
|
17
|
+
$client = new Client(apiKey: getenv("ANTHROPIC_API_KEY"));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Amazon Bedrock
|
|
21
|
+
|
|
22
|
+
```php
|
|
23
|
+
use Anthropic\BedrockClient;
|
|
24
|
+
|
|
25
|
+
$client = new BedrockClient(
|
|
26
|
+
region: 'us-east-1',
|
|
27
|
+
);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Google Vertex AI
|
|
31
|
+
|
|
32
|
+
```php
|
|
33
|
+
use Anthropic\VertexClient;
|
|
34
|
+
|
|
35
|
+
$client = new VertexClient(
|
|
36
|
+
region: 'us-east5',
|
|
37
|
+
projectId: 'my-project-id',
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Anthropic Foundry
|
|
42
|
+
|
|
43
|
+
```php
|
|
44
|
+
use Anthropic\FoundryClient;
|
|
45
|
+
|
|
46
|
+
$client = new FoundryClient(
|
|
47
|
+
authToken: getenv("ANTHROPIC_AUTH_TOKEN"),
|
|
48
|
+
);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Basic Message Request
|
|
54
|
+
|
|
55
|
+
```php
|
|
56
|
+
$message = $client->messages->create(
|
|
57
|
+
model: 'claude-opus-4-6',
|
|
58
|
+
maxTokens: 1024,
|
|
59
|
+
messages: [
|
|
60
|
+
['role' => 'user', 'content' => 'What is the capital of France?'],
|
|
61
|
+
],
|
|
62
|
+
);
|
|
63
|
+
echo $message->content[0]->text;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Streaming
|
|
69
|
+
|
|
70
|
+
```php
|
|
71
|
+
$stream = $client->messages->createStream(
|
|
72
|
+
model: 'claude-opus-4-6',
|
|
73
|
+
maxTokens: 1024,
|
|
74
|
+
messages: [
|
|
75
|
+
['role' => 'user', 'content' => 'Write a haiku'],
|
|
76
|
+
],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
foreach ($stream as $event) {
|
|
80
|
+
echo $event;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Tool Use (Manual Loop)
|
|
87
|
+
|
|
88
|
+
The PHP SDK supports raw tool definitions via JSON schema. See the [shared tool use concepts](../shared/tool-use-concepts.md) for the tool definition format and agentic loop pattern.
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Agent SDK — Python
|
|
2
|
+
|
|
3
|
+
The Claude Agent SDK provides a higher-level interface for building AI agents with built-in tools, safety features, and agentic capabilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install claude-agent-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import anyio
|
|
17
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
|
|
18
|
+
|
|
19
|
+
async def main():
|
|
20
|
+
async for message in query(
|
|
21
|
+
prompt="Explain this codebase",
|
|
22
|
+
options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
|
|
23
|
+
):
|
|
24
|
+
if isinstance(message, ResultMessage):
|
|
25
|
+
print(message.result)
|
|
26
|
+
|
|
27
|
+
anyio.run(main)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Built-in Tools
|
|
33
|
+
|
|
34
|
+
| Tool | Description |
|
|
35
|
+
| --------- | ------------------------------------ |
|
|
36
|
+
| Read | Read files in the workspace |
|
|
37
|
+
| Write | Create new files |
|
|
38
|
+
| Edit | Make precise edits to existing files |
|
|
39
|
+
| Bash | Execute shell commands |
|
|
40
|
+
| Glob | Find files by pattern |
|
|
41
|
+
| Grep | Search files by content |
|
|
42
|
+
| WebSearch | Search the web for information |
|
|
43
|
+
| WebFetch | Fetch and analyze web pages |
|
|
44
|
+
| AskUserQuestion | Ask user clarifying questions |
|
|
45
|
+
| Agent | Spawn subagents |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Primary Interfaces
|
|
50
|
+
|
|
51
|
+
### `query()` — Simple One-Shot Usage
|
|
52
|
+
|
|
53
|
+
The `query()` function is the simplest way to run an agent. It returns an async iterator of messages.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
|
|
57
|
+
|
|
58
|
+
async for message in query(
|
|
59
|
+
prompt="Explain this codebase",
|
|
60
|
+
options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
|
|
61
|
+
):
|
|
62
|
+
if isinstance(message, ResultMessage):
|
|
63
|
+
print(message.result)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `ClaudeSDKClient` — Full Control
|
|
67
|
+
|
|
68
|
+
`ClaudeSDKClient` provides full control over the agent lifecycle. Use it when you need custom tools, hooks, streaming, or the ability to interrupt execution.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import anyio
|
|
72
|
+
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions, AssistantMessage, TextBlock
|
|
73
|
+
|
|
74
|
+
async def main():
|
|
75
|
+
options = ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
|
|
76
|
+
async with ClaudeSDKClient(options=options) as client:
|
|
77
|
+
await client.query("Explain this codebase")
|
|
78
|
+
async for message in client.receive_response():
|
|
79
|
+
if isinstance(message, AssistantMessage):
|
|
80
|
+
for block in message.content:
|
|
81
|
+
if isinstance(block, TextBlock):
|
|
82
|
+
print(block.text)
|
|
83
|
+
|
|
84
|
+
anyio.run(main)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`ClaudeSDKClient` supports:
|
|
88
|
+
|
|
89
|
+
- **Context manager** (`async with`) for automatic resource cleanup
|
|
90
|
+
- **`client.query(prompt)`** to send a prompt to the agent
|
|
91
|
+
- **`receive_response()`** for streaming messages until completion
|
|
92
|
+
- **`interrupt()`** to stop agent execution mid-task
|
|
93
|
+
- **Required for custom tools** (via SDK MCP servers)
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Permission System
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
|
|
101
|
+
|
|
102
|
+
async for message in query(
|
|
103
|
+
prompt="Refactor the authentication module",
|
|
104
|
+
options=ClaudeAgentOptions(
|
|
105
|
+
allowed_tools=["Read", "Edit", "Write"],
|
|
106
|
+
permission_mode="acceptEdits" # Auto-accept file edits
|
|
107
|
+
)
|
|
108
|
+
):
|
|
109
|
+
if isinstance(message, ResultMessage):
|
|
110
|
+
print(message.result)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Permission modes:
|
|
114
|
+
|
|
115
|
+
- `"default"`: Prompt for dangerous operations
|
|
116
|
+
- `"plan"`: Planning only, no execution
|
|
117
|
+
- `"acceptEdits"`: Auto-accept file edits
|
|
118
|
+
- `"dontAsk"`: Don't prompt (useful for CI/CD)
|
|
119
|
+
- `"bypassPermissions"`: Skip all prompts (requires `allow_dangerously_skip_permissions=True` in options)
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## MCP (Model Context Protocol) Support
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
|
|
127
|
+
|
|
128
|
+
async for message in query(
|
|
129
|
+
prompt="Open example.com and describe what you see",
|
|
130
|
+
options=ClaudeAgentOptions(
|
|
131
|
+
mcp_servers={
|
|
132
|
+
"playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
):
|
|
136
|
+
if isinstance(message, ResultMessage):
|
|
137
|
+
print(message.result)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Hooks
|
|
143
|
+
|
|
144
|
+
Customize agent behavior with hooks using callback functions:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, HookMatcher, ResultMessage
|
|
148
|
+
|
|
149
|
+
async def log_file_change(input_data, tool_use_id, context):
|
|
150
|
+
file_path = input_data.get('tool_input', {}).get('file_path', 'unknown')
|
|
151
|
+
print(f"Modified: {file_path}")
|
|
152
|
+
return {}
|
|
153
|
+
|
|
154
|
+
async for message in query(
|
|
155
|
+
prompt="Refactor utils.py",
|
|
156
|
+
options=ClaudeAgentOptions(
|
|
157
|
+
permission_mode="acceptEdits",
|
|
158
|
+
hooks={
|
|
159
|
+
"PostToolUse": [HookMatcher(matcher="Edit|Write", hooks=[log_file_change])]
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
):
|
|
163
|
+
if isinstance(message, ResultMessage):
|
|
164
|
+
print(message.result)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Available hook events: `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `Notification`, `UserPromptSubmit`, `SessionStart`, `SessionEnd`, `Stop`, `SubagentStart`, `SubagentStop`, `PreCompact`, `PermissionRequest`, `Setup`, `TeammateIdle`, `TaskCompleted`, `ConfigChange`
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Common Options
|
|
172
|
+
|
|
173
|
+
`query()` takes a top-level `prompt` (string) and an `options` object (`ClaudeAgentOptions`):
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
async for message in query(prompt="...", options=ClaudeAgentOptions(...)):
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
| Option | Type | Description |
|
|
180
|
+
| ----------------------------------- | ------ | -------------------------------------------------------------------------- |
|
|
181
|
+
| `cwd` | string | Working directory for file operations |
|
|
182
|
+
| `allowed_tools` | list | Tools the agent can use (e.g., `["Read", "Edit", "Bash"]`) |
|
|
183
|
+
| `tools` | list | Built-in tools to make available (restricts the default set) |
|
|
184
|
+
| `disallowed_tools` | list | Tools to explicitly disallow |
|
|
185
|
+
| `permission_mode` | string | How to handle permission prompts |
|
|
186
|
+
| `allow_dangerously_skip_permissions`| bool | Must be `True` to use `permission_mode="bypassPermissions"` |
|
|
187
|
+
| `mcp_servers` | dict | MCP servers to connect to |
|
|
188
|
+
| `hooks` | dict | Hooks for customizing behavior |
|
|
189
|
+
| `system_prompt` | string | Custom system prompt |
|
|
190
|
+
| `max_turns` | int | Maximum agent turns before stopping |
|
|
191
|
+
| `max_budget_usd` | float | Maximum budget in USD for the query |
|
|
192
|
+
| `model` | string | Model ID (default: determined by CLI) |
|
|
193
|
+
| `agents` | dict | Subagent definitions (`dict[str, AgentDefinition]`) |
|
|
194
|
+
| `output_format` | dict | Structured output schema |
|
|
195
|
+
| `thinking` | dict | Thinking/reasoning control |
|
|
196
|
+
| `betas` | list | Beta features to enable (e.g., `["context-1m-2025-08-07"]`) |
|
|
197
|
+
| `setting_sources` | list | Settings to load (e.g., `["project"]`). Default: none (no CLAUDE.md files) |
|
|
198
|
+
| `env` | dict | Environment variables to set for the session |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Message Types
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage, SystemMessage
|
|
206
|
+
|
|
207
|
+
async for message in query(
|
|
208
|
+
prompt="Find TODO comments",
|
|
209
|
+
options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
|
|
210
|
+
):
|
|
211
|
+
if isinstance(message, ResultMessage):
|
|
212
|
+
print(message.result)
|
|
213
|
+
elif isinstance(message, SystemMessage) and message.subtype == "init":
|
|
214
|
+
session_id = message.session_id # Capture for resuming later
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Subagents
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition, ResultMessage
|
|
223
|
+
|
|
224
|
+
async for message in query(
|
|
225
|
+
prompt="Use the code-reviewer agent to review this codebase",
|
|
226
|
+
options=ClaudeAgentOptions(
|
|
227
|
+
allowed_tools=["Read", "Glob", "Grep", "Agent"],
|
|
228
|
+
agents={
|
|
229
|
+
"code-reviewer": AgentDefinition(
|
|
230
|
+
description="Expert code reviewer for quality and security reviews.",
|
|
231
|
+
prompt="Analyze code quality and suggest improvements.",
|
|
232
|
+
tools=["Read", "Glob", "Grep"]
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
):
|
|
237
|
+
if isinstance(message, ResultMessage):
|
|
238
|
+
print(message.result)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Error Handling
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
from claude_agent_sdk import query, ClaudeAgentOptions, CLINotFoundError, CLIConnectionError, ResultMessage
|
|
247
|
+
|
|
248
|
+
try:
|
|
249
|
+
async for message in query(
|
|
250
|
+
prompt="...",
|
|
251
|
+
options=ClaudeAgentOptions(allowed_tools=["Read"])
|
|
252
|
+
):
|
|
253
|
+
if isinstance(message, ResultMessage):
|
|
254
|
+
print(message.result)
|
|
255
|
+
except CLINotFoundError:
|
|
256
|
+
print("Claude Code CLI not found. Install with: pip install claude-agent-sdk")
|
|
257
|
+
except CLIConnectionError as e:
|
|
258
|
+
print(f"Connection error: {e}")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Best Practices
|
|
264
|
+
|
|
265
|
+
1. **Always specify allowed_tools** — Explicitly list which tools the agent can use
|
|
266
|
+
2. **Set working directory** — Always specify `cwd` for file operations
|
|
267
|
+
3. **Use appropriate permission modes** — Start with `"default"` and only escalate when needed
|
|
268
|
+
4. **Handle all message types** — Check for `ResultMessage` to get agent output
|
|
269
|
+
5. **Limit max_turns** — Prevent runaway agents with reasonable limits
|