@clawnet/template-minimal 0.0.1
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/.agents/skills/claude-agent-sdk/.claude-plugin/plugin.json +13 -0
- package/.agents/skills/claude-agent-sdk/SKILL.md +954 -0
- package/.agents/skills/claude-agent-sdk/references/mcp-servers-guide.md +387 -0
- package/.agents/skills/claude-agent-sdk/references/permissions-guide.md +429 -0
- package/.agents/skills/claude-agent-sdk/references/query-api-reference.md +437 -0
- package/.agents/skills/claude-agent-sdk/references/session-management.md +419 -0
- package/.agents/skills/claude-agent-sdk/references/subagents-patterns.md +464 -0
- package/.agents/skills/claude-agent-sdk/references/top-errors.md +503 -0
- package/.agents/skills/claude-agent-sdk/rules/claude-agent-sdk.md +96 -0
- package/.agents/skills/claude-agent-sdk/scripts/check-versions.sh +55 -0
- package/.agents/skills/claude-agent-sdk/templates/basic-query.ts +55 -0
- package/.agents/skills/claude-agent-sdk/templates/custom-mcp-server.ts +161 -0
- package/.agents/skills/claude-agent-sdk/templates/error-handling.ts +283 -0
- package/.agents/skills/claude-agent-sdk/templates/filesystem-settings.ts +211 -0
- package/.agents/skills/claude-agent-sdk/templates/multi-agent-workflow.ts +318 -0
- package/.agents/skills/claude-agent-sdk/templates/package.json +30 -0
- package/.agents/skills/claude-agent-sdk/templates/permission-control.ts +211 -0
- package/.agents/skills/claude-agent-sdk/templates/query-with-tools.ts +54 -0
- package/.agents/skills/claude-agent-sdk/templates/session-management.ts +151 -0
- package/.agents/skills/claude-agent-sdk/templates/subagents-orchestration.ts +166 -0
- package/.agents/skills/claude-agent-sdk/templates/tsconfig.json +22 -0
- package/.claude/settings.local.json +70 -0
- package/.claude/skills/moltbook-example/SKILL.md +79 -0
- package/.claude/skills/post/SKILL.md +130 -0
- package/.env.example +4 -0
- package/.vercel/README.txt +11 -0
- package/.vercel/project.json +1 -0
- package/AGENTS.md +114 -0
- package/CLAUDE.md +532 -0
- package/README.md +44 -0
- package/api/index.ts +3 -0
- package/biome.json +14 -0
- package/clark_avatar.jpeg +0 -0
- package/package.json +21 -0
- package/scripts/wake.ts +38 -0
- package/skills/clawbook/HEARTBEAT.md +142 -0
- package/skills/clawbook/SKILL.md +219 -0
- package/skills/moltbook-example/SKILL.md +79 -0
- package/skills/moltbook-example/bot/index.ts +61 -0
- package/src/agent/prompts.ts +98 -0
- package/src/agent/runner.ts +526 -0
- package/src/agent/tool-definitions.ts +1151 -0
- package/src/agent-options.ts +14 -0
- package/src/bot-identity.ts +41 -0
- package/src/constants.ts +15 -0
- package/src/handlers/heartbeat.ts +21 -0
- package/src/handlers/openai-compat.ts +95 -0
- package/src/handlers/post.ts +21 -0
- package/src/identity.ts +83 -0
- package/src/index.ts +30 -0
- package/src/middleware/cron-auth.ts +53 -0
- package/src/middleware/sigma-auth.ts +147 -0
- package/src/runs.ts +49 -0
- package/tests/agent/prompts.test.ts +172 -0
- package/tests/agent/runner.test.ts +353 -0
- package/tests/agent/tool-definitions.test.ts +171 -0
- package/tests/constants.test.ts +24 -0
- package/tests/handlers/openai-compat.test.ts +128 -0
- package/tests/handlers.test.ts +133 -0
- package/tests/identity.test.ts +66 -0
- package/tests/index.test.ts +108 -0
- package/tests/middleware/cron-auth.test.ts +99 -0
- package/tests/middleware/sigma-auth.test.ts +198 -0
- package/tests/runs.test.ts +56 -0
- package/tests/skill.test.ts +71 -0
- package/tsconfig.json +14 -0
- package/vercel.json +9 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
# Top Errors & Solutions
|
|
2
|
+
|
|
3
|
+
Complete reference for common Claude Agent SDK errors and how to fix them.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Error #1: CLI Not Found
|
|
8
|
+
|
|
9
|
+
### Error Message
|
|
10
|
+
```
|
|
11
|
+
"Claude Code CLI not installed"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Why It Happens
|
|
15
|
+
The SDK requires Claude Code CLI to be installed globally, but it's not found in PATH.
|
|
16
|
+
|
|
17
|
+
### Solution
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @anthropic-ai/claude-code
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Verify installation:
|
|
23
|
+
```bash
|
|
24
|
+
which claude-code
|
|
25
|
+
# Should output: /usr/local/bin/claude-code or similar
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Prevention
|
|
29
|
+
- Install CLI before using SDK
|
|
30
|
+
- Add to project setup documentation
|
|
31
|
+
- Check CLI availability in CI/CD
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Error #2: Authentication Failed
|
|
36
|
+
|
|
37
|
+
### Error Message
|
|
38
|
+
```
|
|
39
|
+
"Invalid API key"
|
|
40
|
+
"Authentication failed"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Why It Happens
|
|
44
|
+
- ANTHROPIC_API_KEY environment variable not set
|
|
45
|
+
- API key is invalid or expired
|
|
46
|
+
- API key has wrong format
|
|
47
|
+
|
|
48
|
+
### Solution
|
|
49
|
+
```bash
|
|
50
|
+
# Set API key
|
|
51
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
52
|
+
|
|
53
|
+
# Verify it's set
|
|
54
|
+
echo $ANTHROPIC_API_KEY
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Get API key:
|
|
58
|
+
1. Visit https://console.anthropic.com/
|
|
59
|
+
2. Navigate to API Keys section
|
|
60
|
+
3. Create new key
|
|
61
|
+
4. Copy and save securely
|
|
62
|
+
|
|
63
|
+
### Prevention
|
|
64
|
+
- Use environment variables (never hardcode)
|
|
65
|
+
- Check key before running
|
|
66
|
+
- Add to .env.example template
|
|
67
|
+
- Document setup process
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Error #3: Permission Denied
|
|
72
|
+
|
|
73
|
+
### Error Message
|
|
74
|
+
```
|
|
75
|
+
"Tool use blocked"
|
|
76
|
+
"Permission denied for tool: Bash"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Why It Happens
|
|
80
|
+
- Tool not in `allowedTools` array
|
|
81
|
+
- `permissionMode` is too restrictive
|
|
82
|
+
- Custom `canUseTool` callback denied execution
|
|
83
|
+
|
|
84
|
+
### Solution
|
|
85
|
+
```typescript
|
|
86
|
+
// Add tool to allowedTools
|
|
87
|
+
options: {
|
|
88
|
+
allowedTools: ["Read", "Write", "Edit", "Bash"] // Add needed tools
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Or use less restrictive permission mode
|
|
92
|
+
options: {
|
|
93
|
+
permissionMode: "acceptEdits" // Auto-approve edits
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Or check canUseTool logic
|
|
97
|
+
options: {
|
|
98
|
+
canUseTool: async (toolName, input) => {
|
|
99
|
+
console.log("Tool requested:", toolName); // Debug
|
|
100
|
+
return { behavior: "allow" };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Prevention
|
|
106
|
+
- Set appropriate `allowedTools` from start
|
|
107
|
+
- Test permission logic thoroughly
|
|
108
|
+
- Use `permissionMode: "bypassPermissions"` in CI/CD
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Error #4: Context Length Exceeded
|
|
113
|
+
|
|
114
|
+
### Error Message
|
|
115
|
+
```
|
|
116
|
+
"Prompt too long"
|
|
117
|
+
"Context length exceeded"
|
|
118
|
+
"Too many tokens"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Why It Happens
|
|
122
|
+
- Input prompt exceeds model's context window (200k tokens)
|
|
123
|
+
- Long conversation without pruning
|
|
124
|
+
- Large files in context
|
|
125
|
+
|
|
126
|
+
### Solution
|
|
127
|
+
SDK auto-compacts context, but you can:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// Fork session to start fresh from a point
|
|
131
|
+
const forked = query({
|
|
132
|
+
prompt: "Continue with fresh context",
|
|
133
|
+
options: {
|
|
134
|
+
resume: sessionId,
|
|
135
|
+
forkSession: true // Start fresh
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Or reduce context
|
|
140
|
+
options: {
|
|
141
|
+
allowedTools: ["Read", "Grep"], // Limit tools
|
|
142
|
+
systemPrompt: "Keep responses concise."
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Prevention
|
|
147
|
+
- Use session forking for long tasks
|
|
148
|
+
- Keep prompts focused
|
|
149
|
+
- Don't load unnecessary files
|
|
150
|
+
- Monitor context usage
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Error #5: Tool Execution Timeout
|
|
155
|
+
|
|
156
|
+
### Error Message
|
|
157
|
+
```
|
|
158
|
+
"Tool did not respond"
|
|
159
|
+
"Tool execution timeout"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Why It Happens
|
|
163
|
+
- Tool takes too long (>5 minutes default)
|
|
164
|
+
- Infinite loop in tool implementation
|
|
165
|
+
- Network timeout for external tools
|
|
166
|
+
|
|
167
|
+
### Solution
|
|
168
|
+
|
|
169
|
+
For custom tools:
|
|
170
|
+
```typescript
|
|
171
|
+
tool("long_task", "Description", schema, async (args) => {
|
|
172
|
+
// Add timeout
|
|
173
|
+
const timeout = 60000; // 1 minute
|
|
174
|
+
const promise = performLongTask(args);
|
|
175
|
+
const result = await Promise.race([
|
|
176
|
+
promise,
|
|
177
|
+
new Promise((_, reject) =>
|
|
178
|
+
setTimeout(() => reject(new Error('Timeout')), timeout)
|
|
179
|
+
)
|
|
180
|
+
]);
|
|
181
|
+
return { content: [{ type: "text", text: result }] };
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
For bash commands:
|
|
186
|
+
```typescript
|
|
187
|
+
// Add timeout to bash command
|
|
188
|
+
command: "timeout 60s long-running-command"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Prevention
|
|
192
|
+
- Set reasonable timeouts
|
|
193
|
+
- Optimize tool implementations
|
|
194
|
+
- Use background jobs for long tasks
|
|
195
|
+
- Test tools independently
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Error #6: Session Not Found
|
|
200
|
+
|
|
201
|
+
### Error Message
|
|
202
|
+
```
|
|
203
|
+
"Invalid session ID"
|
|
204
|
+
"Session not found"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Why It Happens
|
|
208
|
+
- Session ID is incorrect
|
|
209
|
+
- Session expired (old)
|
|
210
|
+
- Session from different CLI instance
|
|
211
|
+
|
|
212
|
+
### Solution
|
|
213
|
+
```typescript
|
|
214
|
+
// Ensure session ID captured correctly
|
|
215
|
+
let sessionId: string | undefined;
|
|
216
|
+
for await (const message of response) {
|
|
217
|
+
if (message.type === 'system' && message.subtype === 'init') {
|
|
218
|
+
sessionId = message.session_id; // Capture here
|
|
219
|
+
console.log("Session:", sessionId); // Verify
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Use correct session ID
|
|
224
|
+
query({
|
|
225
|
+
prompt: "...",
|
|
226
|
+
options: { resume: sessionId } // Must match exactly
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Prevention
|
|
231
|
+
- Always capture session_id from system init
|
|
232
|
+
- Store session IDs reliably
|
|
233
|
+
- Don't rely on sessions lasting indefinitely
|
|
234
|
+
- Handle session errors gracefully
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Error #7: MCP Server Connection Failed
|
|
239
|
+
|
|
240
|
+
### Error Message
|
|
241
|
+
```
|
|
242
|
+
"Server connection error"
|
|
243
|
+
"MCP server not responding"
|
|
244
|
+
"Failed to connect to MCP server"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Why It Happens
|
|
248
|
+
- Server command/URL incorrect
|
|
249
|
+
- Server crashed or not running
|
|
250
|
+
- Network issues (HTTP/SSE servers)
|
|
251
|
+
- Missing dependencies
|
|
252
|
+
|
|
253
|
+
### Solution
|
|
254
|
+
|
|
255
|
+
For stdio servers:
|
|
256
|
+
```typescript
|
|
257
|
+
// Verify command works independently
|
|
258
|
+
// Test: npx @modelcontextprotocol/server-filesystem
|
|
259
|
+
options: {
|
|
260
|
+
mcpServers: {
|
|
261
|
+
"filesystem": {
|
|
262
|
+
command: "npx", // Verify npx is available
|
|
263
|
+
args: ["@modelcontextprotocol/server-filesystem"],
|
|
264
|
+
env: {
|
|
265
|
+
ALLOWED_PATHS: "/path" // Verify path exists
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
For HTTP servers:
|
|
273
|
+
```typescript
|
|
274
|
+
// Test URL separately
|
|
275
|
+
const testResponse = await fetch("https://api.example.com/mcp");
|
|
276
|
+
console.log(testResponse.status); // Should be 200
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Prevention
|
|
280
|
+
- Test MCP servers independently before integration
|
|
281
|
+
- Verify command/URL works
|
|
282
|
+
- Add error handling for server failures
|
|
283
|
+
- Use health checks
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Error #8: Subagent Definition Error
|
|
288
|
+
|
|
289
|
+
### Error Message
|
|
290
|
+
```
|
|
291
|
+
"Invalid AgentDefinition"
|
|
292
|
+
"Agent configuration error"
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Why It Happens
|
|
296
|
+
- Missing required fields (`description` or `prompt`)
|
|
297
|
+
- Invalid `model` value
|
|
298
|
+
- Invalid `tools` array
|
|
299
|
+
|
|
300
|
+
### Solution
|
|
301
|
+
```typescript
|
|
302
|
+
agents: {
|
|
303
|
+
"my-agent": {
|
|
304
|
+
description: "Clear description of when to use", // Required
|
|
305
|
+
prompt: "Detailed system prompt", // Required
|
|
306
|
+
tools: ["Read", "Write"], // Optional
|
|
307
|
+
model: "sonnet" // Optional
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Prevention
|
|
313
|
+
- Always include `description` and `prompt`
|
|
314
|
+
- Use TypeScript types
|
|
315
|
+
- Test agent definitions
|
|
316
|
+
- Follow examples in templates
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Error #9: Settings File Not Found
|
|
321
|
+
|
|
322
|
+
### Error Message
|
|
323
|
+
```
|
|
324
|
+
"Cannot read settings"
|
|
325
|
+
"Settings file not found"
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Why It Happens
|
|
329
|
+
- `settingSources` includes non-existent file
|
|
330
|
+
- File path incorrect
|
|
331
|
+
- File permissions deny read
|
|
332
|
+
|
|
333
|
+
### Solution
|
|
334
|
+
```typescript
|
|
335
|
+
// Check file exists before loading
|
|
336
|
+
import fs from 'fs';
|
|
337
|
+
|
|
338
|
+
const projectSettingsPath = '.claude/settings.json';
|
|
339
|
+
const settingSources = [];
|
|
340
|
+
|
|
341
|
+
if (fs.existsSync(projectSettingsPath)) {
|
|
342
|
+
settingSources.push('project');
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
options: {
|
|
346
|
+
settingSources // Only existing files
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Prevention
|
|
351
|
+
- Check file exists before including in sources
|
|
352
|
+
- Use empty array for isolated execution
|
|
353
|
+
- Handle missing files gracefully
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Error #10: Tool Name Collision
|
|
358
|
+
|
|
359
|
+
### Error Message
|
|
360
|
+
```
|
|
361
|
+
"Duplicate tool name"
|
|
362
|
+
"Tool already defined"
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Why It Happens
|
|
366
|
+
- Two MCP servers define same tool name
|
|
367
|
+
- Tool name conflicts with built-in tool
|
|
368
|
+
|
|
369
|
+
### Solution
|
|
370
|
+
```typescript
|
|
371
|
+
// Use unique tool names
|
|
372
|
+
const server1 = createSdkMcpServer({
|
|
373
|
+
name: "service-a",
|
|
374
|
+
tools: [
|
|
375
|
+
tool("service_a_process", ...) // Prefix with server name
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const server2 = createSdkMcpServer({
|
|
380
|
+
name: "service-b",
|
|
381
|
+
tools: [
|
|
382
|
+
tool("service_b_process", ...) // Different name
|
|
383
|
+
]
|
|
384
|
+
});
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Prevention
|
|
388
|
+
- Use unique tool names
|
|
389
|
+
- Prefix tools with server name
|
|
390
|
+
- Test integration before deployment
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## Error #11: Zod Schema Validation Error
|
|
395
|
+
|
|
396
|
+
### Error Message
|
|
397
|
+
```
|
|
398
|
+
"Invalid tool input"
|
|
399
|
+
"Schema validation failed"
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Why It Happens
|
|
403
|
+
- Agent provided data that doesn't match Zod schema
|
|
404
|
+
- Schema too restrictive
|
|
405
|
+
- Missing `.describe()` on fields
|
|
406
|
+
|
|
407
|
+
### Solution
|
|
408
|
+
```typescript
|
|
409
|
+
// Add descriptive schemas
|
|
410
|
+
{
|
|
411
|
+
email: z.string().email().describe("User email address"),
|
|
412
|
+
age: z.number().int().min(0).max(120).describe("Age in years"),
|
|
413
|
+
role: z.enum(["admin", "user"]).describe("User role")
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Make fields optional if appropriate
|
|
417
|
+
{
|
|
418
|
+
email: z.string().email(),
|
|
419
|
+
phoneOptional: z.string().optional() // Not required
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Prevention
|
|
424
|
+
- Use `.describe()` on all fields
|
|
425
|
+
- Add validation constraints
|
|
426
|
+
- Test with various inputs
|
|
427
|
+
- Make optional fields explicit
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
## Error #12: Filesystem Permission Denied
|
|
432
|
+
|
|
433
|
+
### Error Message
|
|
434
|
+
```
|
|
435
|
+
"Access denied"
|
|
436
|
+
"Cannot access path"
|
|
437
|
+
"EACCES: permission denied"
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Why It Happens
|
|
441
|
+
- Path outside `workingDirectory`
|
|
442
|
+
- No read/write permissions
|
|
443
|
+
- Protected system directory
|
|
444
|
+
|
|
445
|
+
### Solution
|
|
446
|
+
```typescript
|
|
447
|
+
// Set correct working directory
|
|
448
|
+
options: {
|
|
449
|
+
workingDirectory: "/path/to/accessible/dir"
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Or fix permissions
|
|
453
|
+
// chmod +r file.txt (add read)
|
|
454
|
+
// chmod +w file.txt (add write)
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Prevention
|
|
458
|
+
- Set appropriate `workingDirectory`
|
|
459
|
+
- Verify file permissions
|
|
460
|
+
- Don't access system directories
|
|
461
|
+
- Use dedicated project directories
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## General Error Handling Pattern
|
|
466
|
+
|
|
467
|
+
```typescript
|
|
468
|
+
try {
|
|
469
|
+
const response = query({ prompt: "...", options: { ... } });
|
|
470
|
+
|
|
471
|
+
for await (const message of response) {
|
|
472
|
+
if (message.type === 'error') {
|
|
473
|
+
console.error('Agent error:', message.error);
|
|
474
|
+
// Handle non-fatal errors
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
} catch (error) {
|
|
478
|
+
console.error('Fatal error:', error);
|
|
479
|
+
|
|
480
|
+
// Handle specific errors
|
|
481
|
+
switch (error.code) {
|
|
482
|
+
case 'CLI_NOT_FOUND':
|
|
483
|
+
console.error('Install: npm install -g @anthropic-ai/claude-code');
|
|
484
|
+
break;
|
|
485
|
+
case 'AUTHENTICATION_FAILED':
|
|
486
|
+
console.error('Check ANTHROPIC_API_KEY');
|
|
487
|
+
break;
|
|
488
|
+
case 'RATE_LIMIT_EXCEEDED':
|
|
489
|
+
console.error('Rate limited. Retry with backoff.');
|
|
490
|
+
break;
|
|
491
|
+
case 'CONTEXT_LENGTH_EXCEEDED':
|
|
492
|
+
console.error('Reduce context or fork session');
|
|
493
|
+
break;
|
|
494
|
+
default:
|
|
495
|
+
console.error('Unexpected error:', error);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
**For more details**: See SKILL.md
|
|
503
|
+
**Template**: templates/error-handling.ts
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: "**/*agent*.ts", "**/*.ts"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Claude Agent SDK Corrections
|
|
6
|
+
|
|
7
|
+
This uses **@anthropic-ai/claude-agent-sdk v0.1.50**.
|
|
8
|
+
|
|
9
|
+
## MCP Tool Naming Convention
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
/* ❌ Wrong naming */
|
|
13
|
+
const tool = 'mcp_server_tool'
|
|
14
|
+
|
|
15
|
+
/* ✅ Double underscores required */
|
|
16
|
+
const tool = 'mcp__server-name__tool-name'
|
|
17
|
+
// Format: mcp__<server-name>__<tool-name>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## No Default System Prompt
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
/* ❌ Assuming default instructions */
|
|
24
|
+
const agent = new Agent({
|
|
25
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
26
|
+
// No system prompt...
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/* ✅ Always provide custom system instruction */
|
|
30
|
+
const agent = new Agent({
|
|
31
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
32
|
+
system: 'You are a helpful assistant that...',
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Permission Control
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
/* ✅ Implement canUseTool for security */
|
|
40
|
+
const agent = new Agent({
|
|
41
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
42
|
+
canUseTool: async (tool) => {
|
|
43
|
+
if (tool.name.startsWith('dangerous_')) return 'deny'
|
|
44
|
+
if (tool.name === 'file_write') return 'ask'
|
|
45
|
+
return 'allow'
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Permission modes:
|
|
50
|
+
// 'default' - Normal permissions
|
|
51
|
+
// 'acceptEdits' - Auto-accept file edits
|
|
52
|
+
// 'bypassPermissions' - CI/CD only!
|
|
53
|
+
// 'plan' - Planning mode
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Session Forking (Unique Feature)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
/* ✅ Create branch without modifying original */
|
|
60
|
+
const forkedSession = await session.fork()
|
|
61
|
+
// Original session unchanged
|
|
62
|
+
// Forked session can diverge
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Subagent Definitions
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
/* ❌ Missing required fields */
|
|
69
|
+
const subagent = { prompt: 'Do task' }
|
|
70
|
+
|
|
71
|
+
/* ✅ Include description and prompt */
|
|
72
|
+
const subagent = {
|
|
73
|
+
description: 'Handles data processing tasks',
|
|
74
|
+
prompt: 'Process the provided data and return results',
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Settings Priority
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
Highest → Lowest:
|
|
82
|
+
1. Programmatic (code)
|
|
83
|
+
2. Local (.claude/settings.local.json)
|
|
84
|
+
3. Project (.claude/settings.json)
|
|
85
|
+
4. User (~/.claude/settings.json)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Quick Fixes
|
|
89
|
+
|
|
90
|
+
| If Claude suggests... | Use instead... |
|
|
91
|
+
|----------------------|----------------|
|
|
92
|
+
| `mcp_server_tool` | `mcp__server__tool` (double underscores) |
|
|
93
|
+
| No system prompt | Always provide `system` instruction |
|
|
94
|
+
| Missing canUseTool | Implement permission control |
|
|
95
|
+
| Subagent without description | Include `description` and `prompt` |
|
|
96
|
+
| Tool timeout issues | >5 minutes raises error, handle long tasks |
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Check package versions for Claude Agent SDK skill
|
|
4
|
+
# Usage: ./scripts/check-versions.sh
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
echo "🔍 Checking Claude Agent SDK package versions..."
|
|
9
|
+
echo ""
|
|
10
|
+
|
|
11
|
+
# Colors
|
|
12
|
+
RED='\033[0;31m'
|
|
13
|
+
GREEN='\033[0;32m'
|
|
14
|
+
YELLOW='\033[1;33m'
|
|
15
|
+
NC='\033[0m' # No Color
|
|
16
|
+
|
|
17
|
+
# Check if npm is available
|
|
18
|
+
if ! command -v npm &> /dev/null; then
|
|
19
|
+
echo -e "${RED}❌ npm not found. Please install Node.js.${NC}"
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Function to check package version
|
|
24
|
+
check_package() {
|
|
25
|
+
local package=$1
|
|
26
|
+
local current_version=$2
|
|
27
|
+
|
|
28
|
+
echo -n "Checking $package... "
|
|
29
|
+
|
|
30
|
+
# Get latest version from npm
|
|
31
|
+
latest_version=$(npm view $package version 2>/dev/null)
|
|
32
|
+
|
|
33
|
+
if [ $? -ne 0 ]; then
|
|
34
|
+
echo -e "${RED}❌ Not found in npm registry${NC}"
|
|
35
|
+
return 1
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
if [ "$current_version" = "$latest_version" ]; then
|
|
39
|
+
echo -e "${GREEN}✅ Up to date ($current_version)${NC}"
|
|
40
|
+
else
|
|
41
|
+
echo -e "${YELLOW}⚠️ Update available: $current_version → $latest_version${NC}"
|
|
42
|
+
fi
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
echo "📦 Dependencies:"
|
|
46
|
+
check_package "@anthropic-ai/claude-agent-sdk" "0.1.0"
|
|
47
|
+
check_package "zod" "3.23.0"
|
|
48
|
+
|
|
49
|
+
echo ""
|
|
50
|
+
echo "🛠️ Dev Dependencies:"
|
|
51
|
+
check_package "@types/node" "20.0.0"
|
|
52
|
+
check_package "typescript" "5.3.0"
|
|
53
|
+
|
|
54
|
+
echo ""
|
|
55
|
+
echo "✨ Check complete!"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Basic Query Template
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates:
|
|
7
|
+
* - Simple query execution
|
|
8
|
+
* - Model selection
|
|
9
|
+
* - Working directory
|
|
10
|
+
* - Basic message handling
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
async function basicQuery() {
|
|
14
|
+
const response = query({
|
|
15
|
+
prompt: "Analyze the codebase and suggest improvements",
|
|
16
|
+
options: {
|
|
17
|
+
model: "claude-sonnet-4-5", // or "haiku", "opus"
|
|
18
|
+
workingDirectory: process.cwd(),
|
|
19
|
+
allowedTools: ["Read", "Grep", "Glob"]
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Process streaming messages
|
|
24
|
+
for await (const message of response) {
|
|
25
|
+
switch (message.type) {
|
|
26
|
+
case 'system':
|
|
27
|
+
if (message.subtype === 'init') {
|
|
28
|
+
console.log(`Session ID: ${message.session_id}`);
|
|
29
|
+
console.log(`Model: ${message.model}`);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case 'assistant':
|
|
34
|
+
if (typeof message.content === 'string') {
|
|
35
|
+
console.log('Assistant:', message.content);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
case 'tool_call':
|
|
40
|
+
console.log(`Executing tool: ${message.tool_name}`);
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case 'tool_result':
|
|
44
|
+
console.log(`Tool ${message.tool_name} completed`);
|
|
45
|
+
break;
|
|
46
|
+
|
|
47
|
+
case 'error':
|
|
48
|
+
console.error('Error:', message.error.message);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Run
|
|
55
|
+
basicQuery().catch(console.error);
|