# Build Your Own Claude Code — Workshop A hands-on workshop by [Abhi Aiyer](https://github.com/AbhiAiyer) (Founder/CTO, Mastra) and [Tyler Barnes](https://github.com/TylerBarnes) (Founding Engineer, Mastra) covering the architecture behind [**MastraCode**](https://github.com/mastra-ai/mastra/tree/main/mastracode) — an open-source AI coding agent you can run, extend, and make your own. ## What You'll Learn The workshop dissects every layer that makes MastraCode work, from the execution harness to cost tracking: | # | Topic | What It Covers | |---|-------|----------------| | 1 | **Intro** | Key components overview | | 2 | **The Harness** | Stateful, resumable execution architecture | | 3 | **Prompts & Context** | Dynamic system prompt composition (env, mode, tools, tasks, skills) | | 4 | **Workspace** | Skills, filesystem sandboxing, purpose-built tools vs bash | | 5 | **Memory** | Context growth, compaction, observational memory | | 6 | **Modes** | PLAN, BUILD, FAST, REVIEW, TRIAGE, CUSTOM — rewiring agent behavior | | 7 | **Steering** | Human-in-the-loop: interrupts, abort, free-form input | | 8 | **Protocols** | Event system, MCP, SubAgents | | 9 | **Streaming** | Multi-model streaming, interrupt handling, provider routing | | 10 | **Policies** | Tool permission matrix, YOLO mode, cost tracking | | 11 | **Checklist** | Production-readiness criteria | ## Slides Open `slides/index.html` in a browser. Navigate with arrow keys or the top nav bar. ## Examples The `examples/` directory contains runnable TypeScript examples that progressively build up from a raw harness to a full TUI: ```bash cd examples pnpm install ``` | Example | Run | Description | |---------|-----|-------------| | `basic.ts` | `npx tsx basic.ts` | Hand-built Harness with subagents (researcher + poet), memory, and event subscriptions | | `basic-tui.ts` | `npx tsx basic-tui.ts` | Same hand-built Harness wired into `MastraTUI` for an interactive terminal UI | | `mc.ts` | `npx tsx mc.ts` | `createMastraCode()` factory — modes, tool grants, MCP manager | | `tui.ts` | `npx tsx tui.ts` | Full MastraCode TUI in ~14 lines | ## MastraCode [**MastraCode**](https://github.com/mastra-ai/mastra/tree/main/mastracode) is a coding agent built on the [Mastra Harness](https://github.com/mastra-ai/mastra/tree/main/packages/core/src/harness). It ships with modes, memory, streaming, tool policies, subagents, observational memory, and a terminal UI — everything covered in this workshop. During the live session, MastraCode was used to work on its own codebase as the final demo. ```bash npm i -g mastracode mastracode # in the dir you want to work in ``` ## Source Code - [**MastraCode**](https://github.com/mastra-ai/mastra/tree/main/mastracode) — the full CLI agent - [**Harness**](https://github.com/mastra-ai/mastra/tree/main/packages/core/src/harness) — the core execution engine in `@mastra/core`