Introducing Claude Code, Cursor, and Codex agents in Mastra

Build your own coding agents using Claude, Cursor, or OpenAI's agent SDKs.

Paul ScanlonPaul Scanlon·

Jun 15, 2026

·

2 min read

Mastra is now an agent meta-harness. Starting today, you can run Claude Code, Cursor, and Codex subagents from within Mastra.

Subagents inherit Mastra's stream composition APIs — hand off to a workflow, or vice versa. You can write evals for them, chat with them in Studio, and swap one for another without changing your code.

Mastra has always been model-agnostic. Today with so many harnesses, we're taking a step towards being harness agnostic as well.

Harnesses maintain their existing feature set — file handling, codebase reasoning, multi-agent handoffs, permission controls — and inherit Mastra's agent surface:

  • Calls: .generate(), .stream(), .resumeGenerate(), .resumeStream()
  • Per-run options: requestContext, abortSignal, instructions, structuredOutput, runId, tracingContext
  • Composition: workflow steps, subagent delegation, attached tools
  • Observability: logs, traces, token usage, model cost in Studio

Get started

Install the SDK package and its peer dependency. This example uses Mastra’s ClaudeSDKAgent:

npm install @mastra/claude @anthropic-ai/claude-agent-sdk
note

Requires @mastra/core@1.38.0 or later, added in PR #16906 and PR #17525.

Create a new SDK agent and configure it with sdkOptions:

TypeScriptsrc/mastra/agents/claude-sdk-agent.ts
import { ClaudeSDKAgent } from "@mastra/claude";
 
export const claudeSDKAgent = new ClaudeSDKAgent({
  id: "claude-sdk-agent",
  name: "Claude SDK Agent",
  description: "Anthropic's Claude Agent SDK with file editing, shell execution, and codebase reasoning.",
  sdkOptions: {
    model: "claude-opus-4-8",
    cwd: process.cwd()
  }
});

Register SDK agents on your Mastra instance:

TypeScriptsrc/mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { claudeSDKAgent } from "./agents/claude-sdk-agent";
 
export const mastra = new Mastra({
  agents: { claudeSDKAgent }
});

If you've already built an OpenAI or Cursor agent, pass it to a Mastra SDK agent using the agent option:

TypeScriptsrc/mastra/agents/openai-sdk-agent.ts
import { Agent } from "@openai/agents";
import { OpenAISDKAgent } from "@mastra/openai";
 
const existingOpenAIAgent = new Agent({
  name: "OpenAI Agent",
  instructions: "...",
  model: "gpt-5.3-codex"
});
 
export const openaiSDKAgent = new OpenAISDKAgent({
  id: "openai-sdk-agent",
  name: "OpenAI SDK Agent",
  description: "...",
  agent: existingOpenAIAgent
});

For more information and full configuration options, see:

Share:
Paul Scanlon
Paul ScanlonTechnical Product Marketing Manager

Paul Scanlon sits between Developer Education and Product Marketing at Mastra. Previously, he was a Technical Product Marketing Manager at Neon and worked in Developer Relations at Gatsby, where he created educational content and developer experiences.

All articles by Paul Scanlon