Claude Code Mastra banner
t3ta t3ta

Claude Code Mastra

Testing community

Description

Claude Code SDK integration for Mastra Framework - TypeScript Agent implementation with comprehensive testing

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Claude Code × Mastra Agent Integration

This library integrates the Claude Code TypeScript SDK as an Agent within the Mastra framework.

Overview

This library adapts the Claude Code SDK to the Mastra Agent interface, enabling powerful coding assistance features of Claude Code within the Mastra framework.

Features

  • Mastra Agent Compatible: Fully implements the Mastra Framework Agent interface
  • Custom Tools: Supports Mastra Agent's tools feature
  • MCP External Tools: Integrates external tools via Model Context Protocol
  • Streaming Support: Real-time response processing
  • Session Management: Tracks session state and manages resources
  • Error Handling: Robust error handling mechanisms
  • Configurable: Supports Claude Code-specific options
  • Type Safe: Complete TypeScript type definitions

Installation

npm install @anthropic-ai/claude-code @mastra/core

Basic Usage

Simple Generation

import { ClaudeCodeAgent } from './claude-code-agent.js';

const agent = new ClaudeCodeAgent({
  maxTurns: 3,
  permissionMode: 'default'
});

const response = await agent.generate(
  'Write a TypeScript function to calculate fibonacci numbers'
);

console.log(response.content);
console.log(response.metadata); // Session info, cost, etc.

Streaming

for await (const chunk of agent.stream('Create a REST API with Express.js')) {
  if (chunk.type === 'content') {
    console.log('Content:', chunk.data.content);
  } else if (chunk.type === 'complete') {
    console.log('Total cost:', chunk.data.totalCost);
  }
}

Configuration Options

interface ClaudeCodeAgentOptions {
  maxTurns?: number;                    // Max turns (default: 10)
  allowedTools?: string[];              // Allowed tools
  permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
  workingDirectory?: string;            // Working directory
  timeout?: number;                     // Timeout (ms,