Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

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.

  • Score 76
  • 508 stars
  • MIT
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

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-agents

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install mastra-file-agents in Claude Code

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

A

No 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 →

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.

mastra-file-agents Install

Add to stack

Loading.