Mastra Code

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

25.8Kstars
2.4Kforks
Apache License 2.0
TypeScript

Mastra Code is a terminal coding agent published as the mastracode package within the larger Mastra monorepo (a YC W25-backed TypeScript framework for building AI applications and agents). Its headline feature is Observational Memory: rather than compacting conversation history when context fills up, it continuously extracts and stores observations from every conversation, then injects relevant context into future requests as needed.

Built on Mastra’s own unified model router, it supports Claude, GPT, Gemini, and thousands of other models, with OAuth login for Anthropic (Claude Max) and OpenAI (ChatGPT Plus/Codex) subscriptions rather than requiring separate API billing. Persistent per-project conversation threads, a goals system for longer-running objectives with configurable judge models, and saved approved plans round out a workflow aimed at sustained, multi-session coding work rather than one-off prompts.

Apache-2.0 licensed (consistent with the rest of the Mastra monorepo outside its separately licensed ee/ enterprise directories), Mastra Code installs globally via npm install -g mastracode or runs directly via npx mastracode, with a polished terminal UI built on the pi-tui library.

What You Get

  • A terminal coding agent with Observational Memory that avoids conversation compaction by extracting and storing observations continuously
  • Multi-model support (Claude, GPT, Gemini, and more) through Mastra’s unified model router
  • OAuth login with Anthropic (Claude Max) or OpenAI (ChatGPT Plus/Codex) instead of separate API key billing
  • Persistent per-project conversation threads, saved approved plans, and a goals system with configurable judge models

Common Use Cases

  • Running long, multi-session coding conversations without losing context to compaction over time
  • Using an existing Claude Max or ChatGPT Plus subscription for a terminal coding agent instead of paying separately for API access
  • Pursuing longer-running coding objectives (“goals”) with automated judging of progress rather than single-shot prompts
  • Switching between Claude, GPT, and Gemini models within the same coding agent session depending on the task

Under The Hood

Architecture Mastra Code lives as the mastracode package within the broader Mastra monorepo, built on top of Mastra’s own agent and model-routing primitives rather than being a fully separate codebase — meaning it benefits directly from Mastra’s unified model router and memory abstractions. Observational Memory is the key architectural departure from typical context-window management: instead of summarizing/discarding older conversation turns (compaction), it extracts discrete observations continuously and retrieves relevant ones for future context, avoiding the information loss compaction can cause.

Tech Stack TypeScript, built with Mastra’s own framework primitives and the pi-tui terminal UI library for its interface, distributed as the mastracode npm package. OAuth integration supports logging in with existing Anthropic and OpenAI subscriptions directly rather than only raw API keys.

Code Quality The package includes a dedicated e2e/ test suite, a VERIFICATION.md document, and its own changelog and build tooling (tsup, vitest) separate from the rest of the monorepo, suggesting it’s treated as its own release unit within the larger Mastra project despite sharing infrastructure.

What Makes It Unique Most coding agents handle growing context by summarizing or truncating older history (compaction), which can silently drop useful detail; Mastra Code’s Observational Memory instead continuously extracts and retrieves discrete observations, aiming to avoid that information loss — a distinctive memory architecture choice built directly on Mastra’s own framework rather than a bolted-on memory plugin.

Self-Hosting

Licensing Model Apache-2.0 licensed, consistent with the rest of the Mastra monorepo outside directories named ee/ (which carry a separate enterprise license) — the mastracode package itself is not under any ee/ directory.

Self-Hosting Restrictions Not applicable; it’s a local CLI tool using your own model provider credentials or OAuth login.

License Key Required No.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack

No spam. Unsubscribe anytime.

Join 750+ subscribers
No spam. Unsubscribe anytime.

Search