@scottwalker/claude-connector 0.4.5 → 0.4.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/README.md CHANGED
@@ -205,11 +205,8 @@ Connect Model Context Protocol servers:
205
205
  ```typescript
206
206
  import { Claude } from '@scottwalker/claude-connector'
207
207
 
208
+ // SDK mode (default) — inline definitions
208
209
  const claude = new Claude({
209
- // From config file
210
- mcpConfig: './mcp.json',
211
-
212
- // Or inline definitions
213
210
  mcpServers: {
214
211
  playwright: {
215
212
  command: 'npx',
@@ -221,6 +218,12 @@ const claude = new Claude({
221
218
  },
222
219
  },
223
220
  })
221
+
222
+ // CLI mode — config file path
223
+ const cliClaude = new Claude({
224
+ useSdk: false,
225
+ mcpConfig: './mcp.json',
226
+ })
224
227
  ```
225
228
 
226
229
  ### Custom Subagents
@@ -307,10 +310,10 @@ Control tool approval with a callback instead of static permission modes:
307
310
  import { Claude } from '@scottwalker/claude-connector'
308
311
 
309
312
  const claude = new Claude({
310
- canUseTool: (tool, args) => {
311
- if (tool === 'Bash' && args.command?.includes('rm ')) return false
312
- if (tool === 'Edit') return true
313
- return 'ask' // fall back to default behavior
313
+ canUseTool: async (toolName, input, { signal }) => {
314
+ if (toolName === 'Bash' && String(input.command).includes('rm -rf'))
315
+ return { behavior: 'deny', message: 'Dangerous command blocked' }
316
+ return { behavior: 'allow' }
314
317
  },
315
318
  })
316
319
  ```
@@ -321,13 +324,17 @@ Define custom tools that run in-process — no external MCP server required:
321
324
 
322
325
  ```typescript
323
326
  import { Claude, createSdkMcpServer, sdkTool } from '@scottwalker/claude-connector'
324
-
325
- const server = createSdkMcpServer({
326
- tools: {
327
- getUser: sdkTool({ id: { type: 'string' } }, async ({ id }) => {
328
- return { name: 'Alice', role: 'admin' }
329
- }),
330
- },
327
+ import { z } from 'zod/v4'
328
+
329
+ const server = await createSdkMcpServer({
330
+ name: 'my-tools',
331
+ tools: [
332
+ await sdkTool('getUser', 'Get user by ID', { id: z.string() },
333
+ async ({ id }) => ({
334
+ content: [{ type: 'text', text: JSON.stringify({ name: 'Alice', role: 'admin' }) }],
335
+ })
336
+ ),
337
+ ],
331
338
  })
332
339
  const claude = new Claude({ mcpServers: { myTools: server } })
333
340
  ```
@@ -341,11 +348,20 @@ import { Claude } from '@scottwalker/claude-connector'
341
348
 
342
349
  const claude = new Claude({
343
350
  hookCallbacks: {
344
- PreToolUse: ({ toolName, args }) => {
345
- if (toolName === 'Bash' && args.command?.includes('sudo')) return 'deny'
346
- },
347
- PostToolUse: ({ toolName, result }) => console.log(`${toolName} done`),
348
- Notification: ({ message }) => sendSlack(message),
351
+ PreToolUse: [{
352
+ matcher: 'Bash',
353
+ hooks: [async (input) => {
354
+ if (String(input.tool_input?.command).includes('sudo'))
355
+ return { decision: 'block', reason: 'sudo not allowed' }
356
+ return { continue: true }
357
+ }],
358
+ }],
359
+ Notification: [{
360
+ hooks: [async (input) => {
361
+ console.log('Notification:', input.message)
362
+ return {}
363
+ }],
364
+ }],
349
365
  },
350
366
  })
351
367
  ```
@@ -439,9 +455,13 @@ Provide CLAUDE.md instructions, settings overrides, and plugins programmatically
439
455
 
440
456
  ```typescript
441
457
  const claude = new Claude({
442
- settingSources: ['./project/CLAUDE.md', './team/CLAUDE.md'],
443
- settings: { preferredLanguage: 'TypeScript', maxFileSize: 10_000 },
444
- plugins: ['@claude/eslint-plugin', '@claude/prettier-plugin'],
458
+ settingSources: ['user', 'project'],
459
+ settings: {
460
+ permissions: { allow: ['Bash(npm test)', 'Read(*)'] },
461
+ },
462
+ plugins: [
463
+ { type: 'local', path: './my-plugin' },
464
+ ],
445
465
  })
446
466
  ```
447
467
 
@@ -453,9 +473,13 @@ Override how Claude Code processes are created — useful for VMs, containers, o
453
473
  import { Claude } from '@scottwalker/claude-connector'
454
474
 
455
475
  const claude = new Claude({
456
- spawnClaudeCodeProcess: (args, env) => {
476
+ spawnClaudeCodeProcess: (options) => {
477
+ // options: { command, args, cwd, env, signal }
457
478
  // Run inside a Docker container instead of locally
458
- return spawn('docker', ['exec', 'my-sandbox', 'claude', ...args], { env })
479
+ return spawn('docker', ['exec', 'my-sandbox', options.command, ...options.args], {
480
+ env: options.env,
481
+ cwd: options.cwd,
482
+ })
459
483
  },
460
484
  })
461
485
  ```
@@ -465,9 +489,10 @@ const claude = new Claude({
465
489
  List and inspect past sessions:
466
490
 
467
491
  ```typescript
468
- const claude = new Claude()
469
- const sessions = await claude.listSessions() // all session IDs + metadata
470
- const messages = await claude.getSessionMessages(id) // full message history
492
+ import { listSessions, getSessionMessages } from '@scottwalker/claude-connector'
493
+
494
+ const sessions = await listSessions({ limit: 10 }) // all session IDs + metadata
495
+ const messages = await getSessionMessages(sessions[0].sessionId) // full message history
471
496
  ```
472
497
 
473
498
  ### Full Configuration
@@ -506,8 +531,7 @@ const claude = new Claude({
506
531
  // Directories
507
532
  additionalDirs: ['../shared-lib', '../proto'],
508
533
 
509
- // MCP
510
- mcpConfig: './mcp.json',
534
+ // MCP (inline definitions for SDK mode)
511
535
  mcpServers: { /* ... */ },
512
536
 
513
537
  // Agents
@@ -666,7 +690,7 @@ cd claude-connector
666
690
  npm install
667
691
 
668
692
  npm run build # compile TypeScript
669
- npm test # run 122 unit tests
693
+ npm test # run unit tests
670
694
  npm run test:integration # build + run integration test
671
695
  npm run typecheck # type-check without emitting
672
696
  ```
package/dist/index.d.ts CHANGED
@@ -54,7 +54,7 @@ export type { ClientOptions, QueryOptions, PermissionMode, EffortLevel, McpServe
54
54
  *
55
55
  * @example
56
56
  * ```ts
57
- * import { createSdkMcpServer, tool } from '@scottwalker/claude-connector'
57
+ * import { createSdkMcpServer, sdkTool } from '@scottwalker/claude-connector'
58
58
  * import { z } from 'zod/v4'
59
59
  *
60
60
  * const server = createSdkMcpServer({
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ BLOCK_TEXT, BLOCK_TOOL_USE, BLOCK_TOOL_RESULT, } from './constants.js';
76
76
  *
77
77
  * @example
78
78
  * ```ts
79
- * import { createSdkMcpServer, tool } from '@scottwalker/claude-connector'
79
+ * import { createSdkMcpServer, sdkTool } from '@scottwalker/claude-connector'
80
80
  * import { z } from 'zod/v4'
81
81
  *
82
82
  * const server = createSdkMcpServer({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scottwalker/claude-connector",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Programmatic Node.js interface for Claude Code CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",