Skip to main content
9 – 17 UHR +49 8031 3508270 LUITPOLDSTR. 9, 83022 ROSENHEIM
DE / EN
Coding agent Mastra United States Terminal (CLI)

Mastra Code

Mastra Code is Mastra's open-source terminal coding agent harness with Observational Memory, Build/Plan/Fast modes and broad model access via a model router.

Licence Apache-2.0
First release February 2026
Interfaces Terminal (CLI)
Platforms macOS, Linux, Windows
Instruction file AGENTS.md

The seven building blocks in Mastra Code

How Mastra Code implements the building blocks of an AI harness

  1. 1

    Agent loop

    Per the architecture overview, the AgentController layer handles mode switching, thread persistence and the event flow, while the underlying Mastra agent layer handles model selection, tool execution and memory.

  2. 2

    Tools and execution environment

    Built-in tools for file access, search, editing, shell commands and web search can be extended via MCP servers (`/mcp`), and programmatically via custom tools (`extraTools`) and subagents.

  3. 3

    Context management

    Project-scoped threads, `AGENTS.md` or `CLAUDE.md` instructions, and skills in `SKILL.md` files (compatible with Claude Code and the Agent Skills standard) form the project-specific context.

  4. 4

    State and memory

    Observational Memory continuously generates and reflects on observations instead of trimming the conversation history, so that, per the announcement, no classic context compaction is needed; the default model for it is `google/gemini-2.5-flash`, changeable via `/om`.

  5. 5

    Permissions

    Per the documentation, tools are grouped into four permission categories (read, edit, execute, MCP), each with its own allow/ask/deny policy, configurable via `/settings` or programmatically via `permissionRules`; YOLO mode, enabled by default, sets every category to allow.

  6. 6

    Verification and feedback

    With `/goal`, Mastra Code pursues an objective across multiple turns until a separate judge model reports the status 'done', 'continue', or 'waiting' - useful for tasks that need repeated checks.

  7. 7

    Orchestration

    `/subagents` shows a model picker for the built-in subagents (Explore, Plan, Execute by default); per the customization documentation, custom modes, tools, subagents and storage backends can be added programmatically.

Models and model access

Which models the harness uses and how they are obtained

Models and model access
Models model-agnostic - per-mode model choice via the Mastra Model Router
Access routes Anthropic (API and Claude Max OAuth), OpenAI (API and ChatGPT Plus/Codex OAuth), Google Gemini (API), DeepSeek (API), Cerebras (API), Kimi For Coding (API and OAuth), custom OpenAI-compatible providers
Free choice of model Yes
Custom endpoint / LLM gateway Yes
Custom OpenAI-compatible providers can be added via `/custom-providers` with a name, base URL, optional API key and model IDs. code.mastra.ai documents native API-key or OAuth sign-in for Anthropic, OpenAI, Google, DeepSeek, Cerebras and Kimi For Coding; through the underlying Mastra Model Router, a much larger number of providers is reachable in principle, per mastra.ai/models.
Features
MCP servers Sub-agents Hooks Skills Headless / CI SDK Resume sessions
Running it with herdr
Supported by herdr Yes
State detection Lifecycle hooks when installed
Integration State and session
Per herdr's support table, herdr detects MastraCode only via installed lifecycle hooks, with no documented screen-manifest fallback.
More about herdr →

Enterprise use

Data processing, controls and pricing model according to the vendor

Local data storage

Threads, messages, token usage and Observational Memory are stored locally by default - per the product announcement in SQLite, per the configuration documentation technically via a local LibSQL file in the app data directory; for teams, the documentation additionally describes remote LibSQL (Turso) and PostgreSQL backends.

Identity via provider accounts

Per the documentation, OAuth sign-in is provided for Anthropic (Claude Max), OpenAI (ChatGPT Plus/Codex) and Kimi For Coding; the documentation does not describe a central enterprise SSO for Mastra Code itself.

Admin policies

The four permission categories - read, edit, execute and MCP - can be set individually to allow, ask or deny via `/settings` or programmatically via `permissionRules`; by default, YOLO mode is enabled and auto-allows every category.

Telemetry

Per the documentation, Mastra Code collects anonymous product analytics by default (operating system, version numbers, CPU architecture, a hostname-derived ID, and usage of sessions, prompts and slash commands); prompt text, message content, file paths and tool inputs are explicitly not collected, per the documentation. This can be disabled via the `MASTRA_TELEMETRY_DISABLED=1` environment variable.

Pricing model

Mastra Code is open source with no licence cost; model access runs through your own API keys or existing provider subscriptions such as Claude Max, ChatGPT Plus/Codex, or Kimi For Coding.

Strengths
  • Observational Memory is intended, per the vendor, to avoid classic context compaction on long projects
  • Three working modes (Build, Plan, Fast) for different task depths and response times
  • Goal tracking via `/goal` with a separate judge model for multi-step tasks
  • A model router with broad model choice and custom OpenAI-compatible providers
  • Programmatically embeddable via the `mastracode` npm package (`createMastraCode()`, `runMC()`) for CI and custom surfaces
  • Built on the open-source Mastra primitives Agent, Memory and Tools
Limitations
  • No documented IDE integration; Mastra Code runs exclusively in the terminal
  • No documented checkpoint or rewind system for file changes
  • The documentation itself describes signing in with a Claude Max subscription via OAuth as a grey area relative to Anthropic's Terms of Service

Use cases

Typical tasks for this harness

Long-running coding projects where classic context compaction gets in the way
Architecture analysis and planning before implementation in Plan mode
Automated, goal-driven tasks such as PR reviews via `/goal`
CI automation via headless mode (`mastracode --prompt`, `runMC`)

AI harnesses are the software layer that turns a language model into a working agent. Mastra Code is Mastra’s terminal coding agent harness: built on the open-source Mastra framework, with Observational Memory instead of classic context compaction, and access to a broad model selection through a central model router. As of 20 September 2026.

What is Mastra Code?

Mastra Code is developed by the team behind Mastra, the TypeScript framework for AI applications and agents (the legal vendor, per its Terms of Service, is Kepler Software, Inc.). Its source code lives in the mastra-ai/mastra monorepo, under the mastracode directory; outside the separately licensed ee/ directories, the repository is licensed under Apache-2.0 according to its own licence file. Mastra Code is installed via npm install -g mastracode or run directly with npx mastracode; running mastracode in a project directory starts an onboarding wizard that configures model providers and modes for the first run. Node.js 22.19.0 or later is a documented prerequisite.

Mastra Code as an AI harness

The architecture has four layers: a terminal interface, the AgentController for mode management, thread persistence and the event flow, the underlying Mastra agent layer for model selection and tool execution, and a LibSQL storage layer for history and Observational Memory. Three modes - Build, Plan and Fast - match depth and response time to the task at hand. File and shell tools can be extended via MCP servers (/mcp), and programmatically via custom tools and subagents; on top of that, skills in SKILL.md files, which Mastra Code reads, per the documentation, from locations including .claude/skills/ and .agents/skills/ - making it compatible with Claude Code and the open Agent Skills standard. Mastra Code reads project instructions from AGENTS.md or CLAUDE.md. For multi-step tasks, /goal pursues an objective until a separate judge model reports the status “done”, “continue” or “waiting”; /subagents shows a model picker for the built-in subagents.

Models and model access

Mastra Code uses the Mastra Model Router, which automatically routes requests to the right provider based on the model ID and available credentials. For Mastra Code itself, code.mastra.ai documents native API-key or subscription-based access to Anthropic (Claude Max), OpenAI (ChatGPT Plus/Codex), Google Gemini, DeepSeek, Cerebras and Kimi For Coding; through the underlying Model Router, a much larger number of further providers is reachable in principle, per mastra.ai/models. For a custom endpoint, /custom-providers lets you enter a name, base URL, optional API key and model IDs for an OpenAI-compatible provider. Model access can therefore generally be routed through a central proxy such as our AI Gateway by registering its endpoint as a custom provider.

Enterprise use: data protection and governance

Per the documentation, Mastra Code collects anonymous product analytics by default - operating system, version numbers, CPU architecture, a hostname-derived ID, and usage of sessions, prompts and slash commands - though prompt text, message content, file paths and tool inputs are explicitly not collected, per the documentation; this can be disabled via the MASTRA_TELEMETRY_DISABLED=1 environment variable. Threads, messages, token usage and Observational Memory stay local by default, per the product announcement in SQLite and, per the configuration documentation, technically via a local LibSQL file, and are not transmitted automatically; for teams, the documentation additionally describes remote LibSQL (Turso) and PostgreSQL backends. The four permission categories - read, edit, execute and MCP - can be set via /settings or programmatically; a central enterprise SSO for Mastra Code itself is not documented. What stays constant: once a cloud model provider or provider subscription is used, source code and prompts go to that provider - this belongs in your records of processing activities in advance.

Orchestrating Mastra Code with herdr

herdr supervises several coding agents at once inside a terminal multiplexer. Per herdr’s documentation, it detects MastraCode only via installed lifecycle hooks and provides both state and session information through them - without the screen-manifest fallback common for other harnesses.

Where it fits: developer harness and enterprise harness

Mastra Code is a terminal tool for developers working on long-running projects who want to avoid losing context. For business users across an entire company who don’t work from a terminal, CompanyGPT is the fitting harness: tools via MCP servers and integrations, roles from Entra ID or Keycloak, and audit logs for governance. Our AI Gateway provides the shared cost and governance layer across different harnesses and model providers. Further agent harnesses are listed in our harness overview. If you’d like to check how a terminal coding agent like Mastra Code fits securely and cost-transparently into your development environment, get in touch.

From developer harness to enterprise harness

Coding harnesses are tools for developers. Business users, cost control and governance need two more layers.

CompanyGPT – the harness for business users

CompanyGPT gives any language model tools via MCP servers, integrations and n8n, company knowledge via companyRAG, roles from Entra ID or Keycloak, and audit logs – operated in your Azure environment or sovereignly on STACKIT.

Discover CompanyGPT
AI Gateway – cost and governance for every agent

The AI Gateway bundles the model access of your tools and coding agents behind an OpenAI-compatible API: authentication via Entra ID, budgets and cost centres per team, user and agent, guardrails and complete logging.

View the AI Gateway

Frequently Asked Questions

What is Mastra Code?

Mastra Code is an open-source terminal coding agent harness from Mastra, built on the Mastra primitives AgentController, Agent and Memory. It connects to many models via a model router and provides tools for reading, searching, editing and executing code.

Is Mastra Code open source?

Yes. The `mastracode` directory lives in the `mastra-ai/mastra` repository outside the separately licensed `ee/` directories, and is therefore licensed under Apache-2.0 according to the repository's licence file.

Which models does Mastra Code support?

Mastra Code is model-agnostic and uses the Mastra Model Router. code.mastra.ai documents native API-key or OAuth support for Anthropic, OpenAI, Google Gemini, DeepSeek, Cerebras and Kimi For Coding, plus custom OpenAI-compatible providers via `/custom-providers`; through the Model Router, a much larger number of further providers is reachable in principle, per mastra.ai/models.

What is Observational Memory in Mastra Code?

Observational Memory is Mastra Code's memory mechanism: instead of trimming the conversation history once the context limit is reached, the agent continuously generates and reflects on observations about the project, so that, per the product announcement, no classic compaction pause is needed.

Does Mastra Code work with herdr?

Yes. Per herdr's support table, herdr detects MastraCode via installed lifecycle hooks and provides both state and session information through them.

What is the difference between Mastra Code and the Mastra framework?

Mastra is the underlying TypeScript framework for AI applications and agents, with building blocks such as Agent, Memory, Tools and the Model Router. Mastra Code is a finished product that assembles exactly these building blocks into a ready-to-use terminal coding agent.

Introduce coding agents safely in your company

We support selection, model access in the EU, permission design and cost control.