mastra-file-agents
Skill by shadcn-labs
Migrates Mastra code-based agents into the file-based convention, with one directory per agent under src/mastra/agents. Built for Mastra developers who want to split large agent files without changing how the agents behave.
Install mastra-file-agents
Built from the published package, never by AI.
git clone --depth 1 https://github.com/shadcn-labs/agentcn /tmp/agentcn && mkdir -p ~/.claude/skills && cp -r /tmp/agentcn/.agents/skills/mastra-file-agents ~/.claude/skills/mastra-file-agentsRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/shadcn-labs/agentcn /tmp/agentcn && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/agentcn/.agents/skills/mastra-file-agents ~/.gemini/antigravity-cli/skills/mastra-file-agentsAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Skills can run scripts on your machine. Some need an API key: check the README.
About
mastra-file-agents is an agent skill that converts Mastra agents built with new Agent(...) and registered in a Mastra({ agents }) map into the file-based convention. Each agent gets its own directory under src/mastra/agents/<name>/, where config.ts, instructions.md, tools/ files and optional memory, workspace, skills and subagents files take over the options that were passed inline. The skill treats the work as a behavior-preserving refactor and keeps the same model, instructions, tools and memory.
The skill works through the migration one agent at a time. It finds the code agents, maps the registration key to the directory name, removes the old code registration, and verifies the result with mastra dev or mastra build. It is aimed at Mastra developers who need to split a large index.ts or agents.ts into one folder per agent. It requires @mastra/core 1.48 or later.
Written from the project's SKILL.md and checked against it.
What it can do
- Find code-based agentsLocates new Agent(...) definitions and how they are registered in the Mastra agents map.
- Split agent configMoves options such as model and description into config.ts using agentConfig().
- Move static instructionsPlaces string or array instructions into instructions.md, while dynamic function instructions stay in config.ts.
- Split tools into filesMoves each createTool() definition into tools/<key>.ts, with the filename as the tool key.
- Handle memory and subagentsMaps memory, workspace, skills and subagents to their own files and directories using a reference guide.
- Remove code registrationDeletes the agent from the Mastra agents map and removes imports that are no longer used.
- Verify the migrationChecks the result with npx mastra dev or npx mastra build so the bundler discovers the new directories.
What you need
- A Mastra project using @mastra/core 1.48 or later
- The app runs through the Mastra CLI (mastra dev or mastra build)
Try asking
- Migrate my weather agent to the file-based agents convention
- Split my big src/mastra/index.ts into one folder per agent
- Convert my Mastra agents' tools into files under tools/
Good to know
- Agents imported and run directly, outside the Mastra CLI, are not discovered and should stay in code.
- A code agent with the same name as a file-based agent wins, so the migration does nothing until the code registration is removed.
- If config.tools is a function, discovered tool files are ignored.
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: .agents/skills/mastra-file-agents/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Alternatives to mastra-file-agents
All alternatives →Aligns a Qwen Code feature with a Codex or Claude Code reference agent. It runs both under the same scenario, captures HTTP and terminal traces, and compares them until behavior matches.
Searches, views, creates, updates, and deletes the user's Google Contacts from an AI assistant. It is for people who want to manage their address book through conversation. A one-time Google connect is required before it returns data.
Guides an AI assistant on error handling choices. It covers when to use Result, Option, ? propagation, unwrap, expect and panic, plus anyhow and thiserror.
Caveman is an agent skill that makes an AI assistant reply in a terse style. It cuts filler and keeps technical facts, code, commands and errors exact. It is built for users who want shorter, cheaper replies.
docs-sync audits or updates English SDK documentation against the requested implementation scope. It is for maintainers who want docs to match main branch features, configuration options, and defaults.
Guides an AI assistant through setting up and running monorepos with pnpm workspaces, Turborepo and Nx. Aimed at developers who need faster builds, shared code and managed dependencies across multiple packages.
Compare with agent-reproduce-align, google_contacts or m06-error-handling
mastra-file-agents: common questions
Why does my migrated Mastra agent disappear?
File-based agents are discovered only by the Mastra bundler, through mastra dev or mastra build. If the app imports the mastra instance directly, the agent directories are never found.
Why is the agent folder named after the map key instead of the id?
The directory name becomes the registration and lookup key, so existing getAgent calls and client references keep working. The id and name are set explicitly in config.ts when they differ.
What should I do with a tool shared by several agents?
The skill says to keep it in a common module and reference it from config.tools, or to duplicate it deliberately and note the choice.
How do I install mastra-file-agents?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is mastra-file-agents free?
The code is published under the MIT licence. The service it connects to may have its own pricing.
Is mastra-file-agents safe to use?
It scores 76 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to mastra-file-agents?
Similar skills: agent-reproduce-align, google_contacts, m06-error-handling, caveman.
