home / skills / openclaw / skills / sw-claude-sdk

sw-claude-sdk skill

/skills/anton-abyzov/sw-claude-sdk

This skill provides expert guidance on Claude Code SDK usage, tools, and extension development to accelerate building robust automation and integrations.

npx playbooks add skill openclaw/skills --skill sw-claude-sdk

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

Files (2)
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 provides expert guidance and tools for developing Claude Code extensions using the Claude SDK. It bundles file operations, search, execution, agent/skill orchestration, plugin hooks, and MCP integration for building reliable, performant extensions. Use it to read, write, edit code, run commands, invoke sub-agents, and integrate protocol-based tooling into extensions.

How this skill works

The skill exposes programmatic tools to manipulate repository files (Read, Write, Edit), search code (Glob, Grep), and execute shell commands (Bash). It supports composing sub-agents (Task) and activating skills (Skill), wiring plugin hooks for lifecycle events, and optionally connecting to an MCP server for protocol-based tool access. Best-practice patterns and safety checks are recommended by the SDK.

When to use it

  • When building or maintaining Claude Code extensions and plugins.
  • When you need scripted file operations (read, write, edit) or project-wide searches.
  • When orchestrating sub-agents or composing multi-step agent workflows.
  • When integrating CI/CD tasks, running tests, or automating development commands.
  • When adding hooks for plugin lifecycle events or connecting to MCP when code-first options aren’t feasible.

Best practices

  • Use absolute file paths to avoid ambiguity and validate paths before use.
  • Search with Grep or Glob before heavy Read operations to minimize tool calls.
  • Batch independent operations and parallelize where safe to improve throughput.
  • Handle errors and timeouts gracefully and provide clear tool descriptions for debugging.
  • Sanitize inputs, avoid hardcoded secrets, and use environment variables for sensitive data.

Example use cases

  • Automate a codebase migration: Glob to find target files, Edit to apply precise replacements, and Bash to run test suites.
  • Create a development workflow: Bash to run linters/tests, Skill to activate a formatting skill, and Hook notifications on completion.
  • Build an analysis sub-agent: Task to invoke a specialized analyzer, Grep to locate relevant files, Read to fetch content, and Write to persist results.
  • Integrate external tooling via MCP: connect an MCP server for filesystem or custom tools where code-first calls are impractical.
  • Archive or back up skills: use Glob to list skill files, Read to collect content, and Bash to package artifacts.

FAQ

When should I use MCP vs direct code tools?

Prefer code-first tools for automation, CI/CD, and production. Use MCP only for quick debugging, desktop integrations, or tools without a code equivalent.

How do I minimize performance overhead when scanning code?

Use Grep or Glob to locate targets before reading files, batch operations, cache results, and parallelize independent tasks.