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 CodeDirect 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.
PrerequisitesDirect link to Prerequisites
Mastra Code requires Node.js 22.13.0 or later.
Get startedDirect link to Get started
Install Mastra Code globally:
- npm
- pnpm
- Yarn
- Bun
npm install -g mastracodepnpm add -g mastracodeyarn global add mastracodebun add --global mastracodeOr run it with
npx:- npm
- pnpm
- Yarn
- Bun
npx mastracodepnpm dlx mastracodeyarn dlx mastracodebun x mastracodeNavigate to your project directory and start Mastra Code:
cd your-project
mastracodeRun the
/logincommand to authenticate with your AI providers (Anthropic, OpenAI).Type a message and press Enter. The agent responds with streaming text and can read, edit, and run code in your project.
Slash commandsDirect link to Slash commands
Mastra Code provides built-in slash commands for managing sessions and settings:
| Command | Description |
|---|---|
/new | Start a new conversation thread |
/threads | List all threads for this project |
/models | Select a different AI model |
/mode | Switch between Build, Plan, and Fast modes |
/cost | Show token usage for the current conversation |
/login | Authenticate with OAuth providers |
/logout | Log out from a provider |
/settings | Open the settings panel |
/sandbox | Add external directories to the allowed path list |
/diff | Show files modified in the current session |
/help | Show available commands |
/exit | Exit the TUI |
You can also define custom slash commands as markdown files. See Configuration for details.
Keyboard shortcutsDirect link to Keyboard shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Interrupt current operation |
Ctrl+D | Exit (when editor is empty) |
Ctrl+T | Toggle thinking blocks visibility |
Ctrl+E | Expand/collapse all tool outputs |
Ctrl+F | Send a follow-up message while the agent is running |
ArchitectureDirect link to Architecture
Mastra Code is built on four layers:
- TUI: Terminal interface (
pi-tuicomponents) - Harness: Mode management, thread persistence, event system, state management
- Mastra Agent: Dynamic model selection, tool execution, memory integration, subagents
- LibSQL Storage: Thread persistence, message history, token usage tracking, observational memory