Skip to main content
Mastra 1.0 is available 🎉 Read announcement

Mastra Code overview

Mastra Code is a terminal-based AI coding agent built on Mastra's Harness, Agent, and Memory primitives. It runs in your terminal, connects to 70+ AI models, and provides tools for reading, searching, editing, and executing code.

Mastra Code organizes its capabilities around these areas:

  • Modes: Switch between Build, Plan, and Fast modes to match your workflow.
  • Tools: Built-in tools for file viewing, editing, searching, shell commands, and web search.
  • Configuration: Project-scoped threads, MCP servers, hooks, custom commands, skills, and database settings.
  • Customization: Extend Mastra Code programmatically with custom modes, tools, subagents, and storage.

When to use Mastra Code
Direct link to When to use Mastra Code

  • Day-to-day coding: Ask questions about your codebase, make edits, run tests, and manage Git.
  • Code exploration: Use Plan mode to analyze architecture and create implementation plans before writing code.
  • Quick lookups: Switch to Fast mode for brief answers and small edits with minimal latency.
  • Multi-model workflows: Compare responses across different AI providers by switching models mid-conversation.

Prerequisites
Direct link to Prerequisites

Mastra Code requires Node.js 22.13.0 or later.

Get started
Direct link to Get started

  1. Install Mastra Code globally:

    npm install -g mastracode

    Or run it with npx:

    npx mastracode
  2. Navigate to your project directory and start Mastra Code:

    cd your-project
    mastracode
  3. Run the /login command to authenticate with your AI providers (Anthropic, OpenAI).

  4. Type a message and press Enter. The agent responds with streaming text and can read, edit, and run code in your project.

Slash commands
Direct link to Slash commands

Mastra Code provides built-in slash commands for managing sessions and settings:

CommandDescription
/newStart a new conversation thread
/threadsList all threads for this project
/modelsSelect a different AI model
/modeSwitch between Build, Plan, and Fast modes
/costShow token usage for the current conversation
/loginAuthenticate with OAuth providers
/logoutLog out from a provider
/settingsOpen the settings panel
/sandboxAdd external directories to the allowed path list
/diffShow files modified in the current session
/helpShow available commands
/exitExit the TUI

You can also define custom slash commands as markdown files. See Configuration for details.

Keyboard shortcuts
Direct link to Keyboard shortcuts

ShortcutAction
Ctrl+CInterrupt current operation
Ctrl+DExit (when editor is empty)
Ctrl+TToggle thinking blocks visibility
Ctrl+EExpand/collapse all tool outputs
Ctrl+FSend a follow-up message while the agent is running

Architecture
Direct link to Architecture

Mastra Code is built on four layers:

  1. TUI: Terminal interface (pi-tui components)
  2. Harness: Mode management, thread persistence, event system, state management
  3. Mastra Agent: Dynamic model selection, tool execution, memory integration, subagents
  4. LibSQL Storage: Thread persistence, message history, token usage tracking, observational memory

Next steps
Direct link to Next steps