home / skills / anton-abyzov / specweave / claude-sdk

claude-sdk skill

/plugins/specweave-plugin-dev/skills/claude-sdk

This skill provides expert guidance and practical commands for Claude Code SDK extension development, enabling file operations, searches, and MCP integration.

This is most likely a fork of the sw-claude-sdk skill from openclaw
npx playbooks add skill anton-abyzov/specweave --skill claude-sdk

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.5 KB
---
name: claude-sdk
description: Claude Code SDK - tools (Read, Write, Edit, Bash), agent tools (Task, Skill), hooks, and MCP integration. Use for Claude Code extension development.
---

# Claude SDK Expert

Expert knowledge of Claude Code SDK, tools, and extension development.

## Core Tools

**File Operations**:
```typescript
// Read files
Read({ file_path: '/absolute/path/file.ts' });

// Write files (creates new or overwrites)
Write({
  file_path: '/absolute/path/file.ts',
  content: 'export const hello = () => "world";'
});

// Edit files (precise replacements)
Edit({
  file_path: '/absolute/path/file.ts',
  old_string: 'const x = 1;',
  new_string: 'const x = 2;'
});
```

**Search**:
```typescript
// Find files by pattern
Glob({ pattern: '**/*.ts' });

// Search file contents
Grep({
  pattern: 'TODO',
  output_mode: 'files_with_matches'
});

// Search with context
Grep({
  pattern: 'function.*export',
  output_mode: 'content',
  '-C': 3, // 3 lines before/after
  '-n': true // Line numbers
});
```

**Execution**:
```typescript
// Run commands
Bash({
  command: 'npm test',
  description: 'Run test suite'
});

// Background processes
Bash({
  command: 'npm run dev',
  run_in_background: true
});
```

## Agent Tools

**Sub-agents**:
```typescript
// Invoke specialized sub-agent
Task({
  subagent_type: 'plugin:agent-folder:agent-name',
  prompt: 'Analyze this architecture'
});
```

**Skills**:
```typescript
// Activate skill explicitly
Skill({ skill: 'skill-name' });

// Or let auto-activation handle it
```

**Commands**:
```typescript
// Execute slash command
SlashCommand({ command: '/plugin:command arg1 arg2' });
```

## Plugin Hooks

**Available Hook Events**:
```typescript
type HookEvent =
  | 'PostToolUse'        // After tool executes
  | 'PreToolUse'         // Before tool executes
  | 'PermissionRequest'  // User permission dialog
  | 'Notification'       // System notification
  | 'UserPromptSubmit'   // After user submits prompt
  | 'Stop'               // Conversation stopped
  | 'SubagentStop'       // Sub-agent stopped
  | 'PreCompact'         // Before context compaction
  | 'SessionStart'       // Session started
  | 'SessionEnd';        // Session ended
```

**Hook Configuration**:
```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "TodoWrite",
        "hooks": [{
          "type": "command",
          "command": "${CLAUDE_PLUGIN_ROOT}/hooks/post-task.sh",
          "timeout": 10
        }]
      }
    ]
  }
}
```

## MCP (Model Context Protocol)

> **Code-First Preferred**: Anthropic research shows [code execution achieves 98% token reduction vs MCP](https://www.anthropic.com/engineering/code-execution-with-mcp). Use MCP only for: quick debugging, Claude Desktop integration, or tools with no code equivalent. For automation, CI/CD, and production - write code instead.

**MCP Server Integration** (when needed):
```typescript
// Connect to MCP server
const mcp = await connectMCP({
  name: 'filesystem',
  transport: 'stdio',
  command: 'node',
  args: ['mcp-server-filesystem.js']
});

// Use MCP tools
mcp.call('read_file', { path: '/path/to/file' });
```

## Best Practices

**Tool Usage**:
- Use absolute paths (not relative)
- Handle errors gracefully
- Provide clear descriptions
- Batch independent operations

**Performance**:
- Minimize tool calls
- Use Grep before Read (search first)
- Parallel independent operations
- Cache results when possible

**Security**:
- Validate file paths
- Sanitize user input
- No hardcoded secrets
- Use environment variables

Build powerful Claude Code extensions!

Overview

This skill presents the Claude Code SDK for building Claude Code extensions and automation. It exposes file operations (read, write, edit), search utilities (glob, grep), execution helpers (bash), agent primitives (Task, Skill, SlashCommand), plugin hooks, and optional MCP integration. Use it to develop production-grade developer tools, CI automation, and autonomous sub-agents in TypeScript.

How this skill works

The SDK provides typed tool calls that operate on the filesystem, run shell commands, and invoke sub-agents or skills. Hooks let extensions react to lifecycle events (PreToolUse, PostToolUse, SessionStart, etc.) and run custom scripts. For heavy automation prefer code-first tool calls; use MCP only when a protocol bridge is required for quick debugging or desktop integrations.

When to use it

  • Creating Claude Code extensions that read, write, or modify project files programmatically
  • Implementing automated workflows that run commands, tests, or background processes
  • Composing sub-agents or delegating work to specialized Task/Skill agents
  • Adding plugin hooks for observability, notifications, or external integrations
  • Integrating legacy tools or UIs via MCP when a code-first tool is not feasible

Best practices

  • Always use absolute file paths and validate them before performing file operations
  • Search with Grep or Glob before reading large files to reduce I/O and tokens
  • Batch independent operations and run safe edits to minimize tool calls
  • Handle errors gracefully and surface clear descriptions for each tool call
  • Avoid hardcoded secrets; use environment variables and sanitize inputs

Example use cases

  • Generating code, tests, and documentation automatically and committing changes
  • Running CI tasks: run test suites, collect failures, and open tickets via Task agents
  • Building an autonomous refactoring agent that Greps references, Edits files, and runs tests
  • Hooking PostToolUse to notify a CI dashboard or trigger additional validation scripts
  • Using MCP to bridge a desktop app to filesystem tools for debugging or limited plugins

FAQ

When should I use MCP instead of direct tools?

Prefer code-first tool calls for automation and production. Use MCP for quick debugging, Claude Desktop integration, or when a protocol bridge is necessary.

How do I limit token and performance costs?

Minimize tool calls, Grep before Read to narrow scope, batch operations, and cache results when possible.