npm package: @majkapp/majk-chat-claude-code
Description: Claude Code SDK integration for majk-chat
Author: Jules White
Latest version: 1.0.32

# @majkapp/majk-chat-claude-code

Claude Code SDK integration for majk-chat. This package wraps the official `@anthropic-ai/claude-agent-sdk` to provide seamless integration with majk-chat's executor pattern.

## Features

- ✅ **Official SDK Integration** - Uses `@anthropic-ai/claude-agent-sdk` under the hood
- ✅ **Dual Authentication** - Supports both Anthropic API keys and AWS Bedrock
- ✅ **Streaming Support** - Real-time streaming with proper message handling
- ✅ **Tool Execution** - Full access to Claude Code's built-in tools
- ✅ **MCP Support** - Configure and use Model Context Protocol servers
- ✅ **Type Safety** - Full TypeScript support with comprehensive types

## Installation

```bash
npm install @majkapp/majk-chat-claude-code
```

## Usage

### Basic Usage

```typescript
import { ClaudeCodeExecutor } from '@majkapp/majk-chat-claude-code';

const executor = new ClaudeCodeExecutor();

const response = await executor.execute({
  messages: [
    { role: 'user', content: 'List files in current directory' }
  ],
  anthropicApiKey: process.env.ANTHROPIC_API_KEY,
  enableCoreTools: true
});

console.log(response.response.choices[0].message.content);
```

### With AWS Bedrock (Bearer Token)

```typescript
const response = await executor.execute({
  messages: [
    { role: 'user', content: 'Analyze this codebase' }
  ],
  provider: 'bedrock',
  bedrockApiKey: process.env.AWS_BEARER_TOKEN_BEDROCK,
  awsRegion: 'us-east-1',
  enableCoreTools: true
});
```

### With AWS Bedrock (IAM Credentials)

```typescript
const response = await executor.execute({
  messages: [
    { role: 'user', content: 'Refactor this module' }
  ],
  provider: 'bedrock',
  awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
  awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  awsRegion: 'us-west-2',
  enableCoreTools: true
});
```

### Streaming Output

```typescript
const response = await executor.execute({
  messages: [
    { role: 'user', content: 'Explain this code' }
  ],
  anthropicApiKey: process.env.ANTHROPIC_API_KEY,
  outputFormat: 'stream-json',
  onToolCall: (toolCall) => {
    console.log('Tool called:', toolCall.function.name);
  },
  onToolResult: (toolCall, result) => {
    console.log('Tool result:', result);
  }
});
```

### With MCP Servers

```typescript
const response = await executor.execute({
  messages: [
    { role: 'user', content: 'Search the documentation' }
  ],
  anthropicApiKey: process.env.ANTHROPIC_API_KEY,
  mcpServers: [
    {
      type: 'stdio',
      command: 'node',
      args: ['mcp-server.js']
    }
  ]
});
```

## API Reference

### ClaudeCodeExecutor

#### Methods

##### `execute(options: ClaudeCodeExecutorOptions): Promise<ExecutorResponse>`

Execute a query using Claude Code SDK.

##### `getName(): string`

Returns `'claude-code'`.

##### `supportsStreaming(): boolean`

Returns `true`.

### ClaudeCodeExecutorOptions

```typescript
interface ClaudeCodeExecutorOptions {
  // Core
  messages: Message[];
  provider?: string;
  model?: string;
  temperature?: number;
  maxTokens?: number;
  maxSteps?: number;
  systemPrompt?: string;
  outputFormat?: 'text' | 'stream-json';

  // Authentication - Anthropic
  anthropicApiKey?: string;

  // Authentication - Bedrock
  bedrockApiKey?: string;
  awsAccessKeyId?: string;
  awsSecretAccessKey?: string;
  awsSessionToken?: string;
  awsRegion?: string;

  // Tools
  enableCoreTools?: boolean;
  disableTools?: boolean;
  allowedTools?: string;
  disallowedTools?: string;

  // MCP
  mcpConfig?: string;
  mcpServers?: any[];

  // Context
  cwd?: string;
  sessionId?: string;

  // Callbacks
  onToolCall?: (toolCall: any) => void;
  onToolResult?: (toolCall: any, result: any) => void;
}
```

## Authentication

### Anthropic API

Set your API key via:
- Option: `anthropicApiKey: 'sk-ant-...'`
- Environment: `ANTHROPIC_API_KEY`

### AWS Bedrock (Bearer Token)

Preferred method for Claude Code:
- Option: `bedrockApiKey: 'bedrock-api-key-...'`
- Environment: `AWS_BEARER_TOKEN_BEDROCK`

### AWS Bedrock (IAM Credentials)

Alternative method using AWS credentials:
- Options: `awsAccessKeyId`, `awsSecretAccessKey`, `awsSessionToken`
- Environment: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`

## Integration with majk-chat CLI

This package is designed to be used by `@majkapp/majk-chat-cli`:

```bash
majk-chat chat --agent claude-code -M "Help me with this code"
```

## License

MIT