New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mastracode

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mastracode

A terminal-based coding agent TUI built with [Mastra](https://mastra.ai) and [pi-tui](https://github.com/badlogic/pi-mono).

latest
Source
npmnpm
Version
0.13.0
Version published
Maintainers
1
Created
Source

Mastra Code

A terminal-based coding agent TUI built with Mastra and pi-tui.

Features

  • 🤖 Multi-model support: Use Claude, GPT, Gemini, and 70+ other models via Mastra's unified model router
  • 🔐 OAuth login: Authenticate with Anthropic (Claude Max) and OpenAI (ChatGPT Plus/Codex)
  • 💾 Persistent conversations: Threads are saved per-project and resume automatically
  • 🛠️ Coding tools: View files, edit code, run shell commands
  • 📋 Plan persistence: Approved plans are saved as markdown files for future reference
  • 📊 Token tracking: Monitor usage with persistent token counts per thread
  • 🎨 Beautiful TUI: Polished terminal interface with streaming responses

Installation

Install mastracode globally with your package manager of choice.

npm install -g mastracode

If you prefer not to install packages globally, you can use npx:

npx mastracode

On first launch, an interactive onboarding wizard guides you through:

  • Authentication — log in with your AI provider (Anthropic, OpenAI, etc.)
  • Model packs — choose default models for each mode (build / plan / fast)
  • Observational Memory — pick a model for OM (learns about you over time)
  • YOLO mode — auto-approve tool calls, or require manual confirmation

You can re-run setup anytime with /setup.

Prerequisites

Optional: fd for file autocomplete

The @ file autocomplete feature uses fd, a fast file finder that respects .gitignore. Without it, @ autocomplete silently does nothing.

Install with your package manager:

# macOS
brew install fd

# Ubuntu/Debian
sudo apt install fd-find

# Arch
sudo pacman -S fd

On Ubuntu/Debian the binary is called fdfind — mastracode detects both fd and fdfind automatically.

Usage

Starting a conversation

Type your message and press Enter. If the agent is already working, Enter queues your next message and sends it after the current run finishes.

@ file references

Type @ followed by a partial filename to fuzzy-search project files and reference them in your message. This requires fd to be installed (see Prerequisites).

  • @setup — fuzzy-matches files like setup.ts, setup.py, etc.
  • @src/tui — scoped search within a directory
  • @"path with spaces" — quoted form for paths containing spaces

Select a suggestion with arrow keys and press Tab to insert it.

Slash commands

CommandDescription
/newStart a new conversation thread
/threadsList and switch between threads with freshness-checked cached lazy previews
/modelsSwitch/manage model packs (built-in/custom)
/custom-providersManage custom OpenAI-compatible providers/models
/modeSwitch agent mode
/subagentsConfigure subagent model defaults
/omConfigure Observational Memory models
/thinkSet thinking level (Anthropic)
/skillsList available skills
/diffShow modified files or git diff
/nameRename current thread
/costShow token usage and estimated costs
/reviewReview a GitHub pull request
/hooksShow/reload configured hooks
/mcpShow/reload MCP server connections
/sandboxManage allowed paths (add/remove dirs)
/permissionsView/manage tool approval permissions
/settingsGeneral settings (notifications, YOLO, etc.)
/yoloToggle YOLO mode (auto-approve all tools)
/resourceShow/switch resource ID (tag for sharing)
/thread:tag-dirTag current thread with this directory
/loginAuthenticate with OAuth providers
/logoutLog out from a provider
/setupRe-run the interactive setup wizard
/helpShow available commands
/exitExit the TUI

Keyboard shortcuts

ShortcutAction
Ctrl+CInterrupt current operation or clear input
Ctrl+C ×2Exit (double-tap)
Ctrl+DExit (when editor is empty)
Ctrl+ZSuspend process (fg to resume)
Alt+ZUndo last clear
Ctrl+TToggle thinking blocks visibility
Ctrl+EExpand/collapse all tool outputs
EnterSend a message, or queue a follow-up while the agent is running
Ctrl+YToggle YOLO mode

Configuration

Project-based threads

Threads are automatically scoped to your project based on:

  • Git remote URL (if available)
  • Absolute path (fallback)

This means conversations are shared across clones, worktrees, and SSH/HTTPS URLs of the same repository.

Database location

The SQLite database is stored in your system's application data directory:

  • macOS: ~/Library/Application Support/mastracode/
  • Linux: ~/.local/share/mastracode/
  • Windows: %APPDATA%/mastracode/

Authentication

For Anthropic models, mastracode supports two authentication methods:

  • Claude Max OAuth (primary) — Use /login to authenticate with a Claude Pro/Max subscription.
  • API key (fallback) — Set the ANTHROPIC_API_KEY environment variable for direct API access. This is used when not logged in via OAuth.

When both are available, Claude Max OAuth takes priority.

For other providers (OpenAI, Google, etc.), set the corresponding environment variable (e.g., OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY) or use OAuth where supported.

Credentials are stored alongside the database in auth.json.

Custom providers and models

Use /custom-providers to manage OpenAI-compatible providers with:

  • provider name
  • provider url
  • optional provider apiKey
  • one or more custom model IDs per provider

Once saved, provider models appear in existing selectors like /models and /subagents and can be selected like built-in models.

Custom providers are stored in settings.json in the same app data directory. If you save an API key, it is stored locally in plaintext, so use a machine/user profile you trust.

macOS sleep prevention

On macOS, Mastra Code starts the built-in caffeinate utility while the agent is actively running, then stops it as soon as the run completes, errors, aborts, or the TUI exits. Idle sessions do not keep your machine awake.

To disable this behavior, set MASTRACODE_DISABLE_CAFFEINATE=1 before launching Mastra Code:

export MASTRACODE_DISABLE_CAFFEINATE=1

Plan persistence

When you approve a plan (via submit_plan), it is saved as a markdown file in the app data directory:

  • macOS: ~/Library/Application Support/mastracode/plans/<resourceId>/
  • Linux: ~/.local/share/mastracode/plans/<resourceId>/
  • Windows: %APPDATA%/mastracode/plans/<resourceId>/

Files are named <timestamp>-<slugified-title>.md and contain the plan title, approval timestamp, and full plan body.

To save plans to a project-local directory instead, set the MASTRA_PLANS_DIR environment variable:

export MASTRA_PLANS_DIR=.mastracode/plans

Architecture

┌─────────────────────────────────────────────────────────────┐
│                          TUI                                │
│  (pi-tui components: Editor, Markdown, Loader, etc.)        │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                        Harness                              │
│  - Mode management (plan, build, review)                    │
│  - Thread/message persistence                               │
│  - Event system for TUI updates                             │
│  - State management with Zod schemas                        │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                      Mastra Agent                           │
│  - Dynamic model selection                                  │
│  - Tool execution (view, edit, bash)                        │
│  - Memory integration                                       │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                      LibSQL Storage                         │
│  - Thread persistence                                       │
│  - Message history                                          │
│  - Token usage tracking                                     │
└─────────────────────────────────────────────────────────────┘

Development

# Run in development mode (with watch)
pnpm dev

# Type check
pnpm typecheck

# Build
pnpm build

Credits

  • Mastra - AI agent framework
  • pi-mono - TUI primitives and inspiration
  • OpenCode - OAuth provider patterns

License

Apache-2.0

FAQs

Package last updated on 09 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts