Agent skill

Mastra File Agents

by shadcn-labs in shadcn-labs/agentcn

Migrate Mastra code-based agents (agents built with new Agent(...) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents.

MITAuto-check passed

Install Mastra File Agents

skills CLI
$ npx skills add shadcn-labs/agentcn --skill mastra-file-agents -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install shadcn-labs/agentcn mastra-file-agents --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/shadcn-labs/agentcn.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/mastra-file-agents .claude/skills/mastra-file-agents && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mastra-file-agents
GitHub stars
490
Token cost
~2.4k tokens
SKILL.md length
1,048 words
Files
11 (incl. references)
Skills in repo
5
Repo updated
First seen
Licence
MIT

At a glance

Migrate Mastra code-based agents (agents built with new Agent(...) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents.

  • Works in 6 steps: Find the code-based agents → Create the directory and split the config → Split out the tools → …
  • The user wants to convert
  • SKILL.md covers Two things that break migrations, Workflow and Mapping cheat sheet
  • Runs TypeScript scripts from its folder; calls npx

What it does

Mastra File Agents is an agent skill from shadcn-labs/agentcn. Migrate Mastra code-based agents (agents built with new Agent(...) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents. Use when the user wants to convert or refactor Mastra agents to the per-directory convention, mentions Mastra "file-based agents" or agentConfig, or wants to split a big src/mastra/index.ts or agents.ts into one folder per agent — even if they do not name this skill. Requires @mastra/core 1.48+.

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 22 other files, including reference files (for example `evals/evals.json`, `evals/files/research-project/package.json` and `evals/files/research-project/src/mastra/index.ts`). Compatibility notes: A Mastra project using @mastra/core = 1.48.0. Agents must run through the Mastra CLI (mastra dev / mastra build) for file-based discovery.

It works with Mastra. The repository describes itself as: shadcn/ui, but for building agents. 🤖. The licence is MIT.

When your agent uses it

  • The user wants to convert
  • Refactor Mastra agents to the per-directory convention
  • Mentions Mastra file-based agents
  • Wants to split a big src/mastra/index.ts

Example prompts

  • “file-based agents”
  • “/mastra-file-agents”

Requirements

  • Node.js
  • Compatibility (from SKILL.md): A Mastra project using @mastra/core >= 1.48.0. Agents must run through the Mastra CLI (mastra dev / mastra build) for file-based discovery.

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Find the code-based agents
  2. Create the directory and split the config
  3. Split out the tools
  4. Handle the remaining surfaces
  5. Remove the code registration
  6. Verify

What it can do on your machine

Read from SKILL.md and the folder at commit 4cd4d83. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (TypeScript, from the files we listed), which the agent can run.

    Shell commands in SKILL.md call:

    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    A Mastra project using @mastra/core >= 1.48.0. Agents must run through the Mastra CLI (mastra dev / mastra build) for file-based discovery.

    From compatibility in the SKILL.md frontmatter.

Context cost

Mastra File Agents loads about 2.4k tokens when it runs, and up to ~4.7k if it reads all its reference files. Until then it costs about 126 tokens; SKILL.md has 1,048 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~126
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~4.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from shadcn-labs/agentcn at commit 4cd4d83, republished under its MIT licence (© shadcn-labs). 1,048 words, ~2,363 tokens.

Download SKILL.mdSave it as .claude/skills/mastra-file-agents/SKILL.md (or your agent's skills folder). This skill also uses 10 other files; get the full folder from GitHub.
name
mastra-file-agents
description
Migrate Mastra code-based agents (agents built with new Agent(...) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents. Use when the user wants to convert or refactor Mastra agents to the per-directory convention, mentions Mastra "file-based agents" or agentConfig, or wants to split a big src/mastra/index.ts or agents.ts into one folder per agent — even if they do not name this skill. Requires @mastra/core 1.48+.
compatibility
A Mastra project using @mastra/core >= 1.48.0. Agents must run through the Mastra CLI (mastra dev / mastra build) for file-based discovery.

Migrate Mastra agents to file-based

Convert agents built in code with new Agent({...}) and registered in a new Mastra({ agents: {...} }) map into the file-based convention: one directory per agent under src/mastra/agents/<name>/, where sibling files supply what used to be constructor options.

This is a behavior-preserving refactor, not a redesign. Move each option to the file that owns it, keep the same model, instructions, tools, memory, skills, and subagents, and don't invent config the agent didn't have.

Two things that break migrations

1. File-based agents are discovered ONLY by the Mastra bundler (mastra dev / mastra build). If the app imports the mastra instance directly (Mastra used as a library, a custom server, tests that import { mastra }), agents/<name>/ directories are never discovered and the agent silently disappears. Before migrating, confirm how the app runs: through the CLI → migrate freely; imported directly → do not migrate that agent, keep it in code and tell the user why.

2. Code wins on name collisions. If an agent exists in both a config.ts directory and the Mastra({ agents }) map, the code one is kept and the file-based one is ignored (with a warning). The migration is a no-op until you remove the code registration (Step 5). Half-migrating changes nothing.

Workflow

Work one agent at a time. Copy this checklist and track it:

Migration progress for <agent>:
- [ ] Confirmed the app runs via mastra dev/build (not a direct import)
- [ ] Created src/mastra/agents/<name>/
- [ ] config.ts (agentConfig) with model + non-instruction/tool config
- [ ] instructions.md OR dynamic instructions kept in config.ts
- [ ] tools/*.ts (one default export each, filename = tool key)
- [ ] memory.ts / workspace.ts / skills/ / subagents/ if present (see references/mapping.md)
- [ ] Removed the agent from the Mastra({ agents }) map
- [ ] Deleted now-dead imports / the old agent file if nothing else uses it
- [ ] Verified with mastra dev
Step 1: Find the code-based agents

Locate every new Agent({...}) and how it is registered. Usually the registration is in src/mastra/index.ts inside new Mastra({ agents: { ... } }), but agents may be defined in separate files (src/mastra/agents/*.ts, a big agents.ts) and imported. Read the full Agent config for each — you need every option to map it faithfully. Note the key used in the agents map — that key is how the agent is registered and looked up (e.g. mastra.getAgent('weather'), Studio, client SDK), and it becomes the directory name.

Step 2: Create the directory and split the config

For an agent registered as agents: { weather: weatherAgent }, create src/mastra/agents/weather/.

Name the directory after the map key, not the id. The directory name becomes the agent's registration/lookup key, so using the map key preserves every existing getAgent(...) call and client reference. This matters when the map key differs from the id — e.g. agents: { browserAgent } where new Agent({ id: 'browser-agent' }). Name the folder browserAgent (the key), and because id/name would otherwise default to browserAgent, set them explicitly in config.ts to keep the original 'browser-agent' / 'Browser Agent'. If the map key and id already match, id/name default to the folder and you can drop them.

config.ts — everything except instructions and tools that were passed inline. Use agentConfig() so the partial is typed and sibling files fill the rest:

typescript
import { agentConfig } from '@mastra/core/agent'

export default agentConfig({
  model: 'openai/gpt-5.5',
  // instructions omitted -> taken from instructions.md
  // tools omitted -> taken from tools/*.ts
})

model is required — a missing model fails the build and names the directory.

instructions.md — if the original instructions was a string (or array of static strings/messages), move the text into instructions.md and omit instructions from config.ts. instructions.md wins over a static instructions string, so leaving both is redundant.

If the original instructions was a function (dynamic instructions that read runtime context), it CANNOT live in instructions.md. Keep it in config.ts — dynamic function instructions win over instructions.md. See references/mapping.md.

Step 3: Split out the tools

Each tool becomes its own file under tools/, default-exporting the createTool() call. The filename becomes the tool key, so name the file after the key used in the original tools map (or the tool's id). If the original was tools: { get_weather: getWeatherTool }, the file must be tools/get_weather.ts.

typescript
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

export default createTool({
  id: 'get_weather',
  description: 'Get the current weather for a city',
  inputSchema: z.object({ city: z.string() }),
  execute: async ({ context }) => ({ city: context.city, tempC: 21 }),
})

Tools from tools/*.ts merge with any config.tools. On a key collision config.tools wins (with a warning), so don't list a tool in both places. If config.tools is a function, discovered tool files are ignored — in that case keep tools in config.ts and say so. Test files (*.test.ts, *.spec.ts, etc.) are ignored by discovery.

Not every tool is a createTool(). Provider-native tools (e.g. openai.tools.webSearch({})) and other pre-built tool objects don't fit the createTool() shape. Either leave them inline in config.tools, or default-export the tool object from a tools/<key>.ts file — both are discovered. When in doubt, keeping a provider tool in config.tools is the simplest faithful move. Reserve tools/*.ts files for the project's own createTool() definitions.

If a tool is shared by multiple agents, don't force it into one agent's tools/. Keep the shared tool in a common module and reference it from config.tools, or duplicate deliberately. Note the choice for the user.

Show full SKILL.md (331 more words)Show less
Step 4: Handle the remaining surfaces

Memory, workspace, skills, and subagents each have their own file/directory and precedence rules. When the agent you're migrating uses any of them, read references/mapping.md for the exact mapping and gotchas (dynamic-config caveats, subagent description requirement, seed files, etc.). Do not drop these during migration — losing an agent's memory or subagent silently changes behavior.

Step 5: Remove the code registration

This is what completes the migration (gotcha 2). Delete the agent's entry from the Mastra({ agents: {...} }) map, then remove imports and definitions that are now unused — if the old new Agent(...) lived in its own file and nothing else imports it, delete that file.

Leave code-registered any agent that must stay in code: direct-import/library usage, programmatic or dynamic registration, or a shared instance imported elsewhere. Both styles coexist fine.

Step 6: Verify

Run the app through the CLI so the bundler discovers the new directories:

bash
npx mastra dev

npx mastra build is a good non-interactive check when you can't start the dev server — it runs the same discovery and fails loudly on missing models, missing subagent descriptions, or unresolved directories. If dependencies aren't installed in your environment, say so and mark verification as structural only rather than claiming it runs.

Confirm each migrated agent still appears (under its original registration key) and responds, and that no "code agent overrides file-based" or "config.X wins" warnings are logged (those signal a leftover collision or a redundant config entry). Fix warnings before calling it done.

Mapping cheat sheet

new Agent({...}) optionFile-based location
agents map keyDirectory name (preserves registration/lookup key)
id / nameDefault to directory name; set explicitly in config.ts when they differ from the folder
modelconfig.ts (required)
instructions (string/array)instructions.md
instructions (function)keep in config.ts
descriptionconfig.ts (required for subagents)
tools: { key: createTool(...) }tools/<key>.ts (default export)
provider/pre-built tools (e.g. openai.tools.*)keep in config.tools, or default-export from tools/<key>.ts
skillsskills/ (see references/mapping.md)
memorymemory.ts (see references/mapping.md)
workspaceworkspace.ts + workspace/ seed files
delegated agents (agents)subagents/<childId>/
everything elseconfig.ts via agentConfig()

© shadcn-labs, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 10 other files (references) in .agents/skills/mastra-file-agents of shadcn-labs/agentcn.

  • SKILL.md
  • evals/evals.json
  • evals/files/research-project/package.json
  • evals/files/research-project/src/mastra/index.ts
  • evals/files/support-project/package.json
  • evals/files/support-project/src/mastra/agents/support.ts
  • evals/files/support-project/src/mastra/index.ts
  • evals/files/weather-project/package.json
  • evals/files/weather-project/src/mastra/index.ts
  • … and 2 more

Open the folder on GitHubat commit 4cd4d83

Compare with similar skills

Mastra File Agents next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mastra File Agents compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mastra File Agents this skillshadcn-labs/agentcn490—~2.4kAutomated safety check: PassMIT
React Best Practicesmastra-ai/mastra29k—~1.9kAutomated safety check: PassCustom licence
Nestjs Best Practicesrolling-scopes/rsschool-app10k6 repos~1.2kAutomated safety check: PassMIT
Guidelinesakash-network/node1.1k20 repos~577Automated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0
Component Refactoringlangflow-ai/langflow155k—~3.5kAutomated safety check: PassMIT

Similar skills

  • React Best Practices

    mastra-ai/mastra

    React performance optimization guidelines from Mastra Engineering.

    29k GitHub stars~1.9k tokensUpdated today
    Frontend & DesignAuto-check passed
  • Nestjs Best Practices

    rolling-scopes/rsschool-app

    NestJS best practices and architecture patterns for building production-ready applications.

    10k GitHub starsUsed in 6 repos~1.2k tokens
    Backend & APIsAuto-check passed
  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 20 repos~577 tokens
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    155k GitHub stars~3.5k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Ponytail Lazy Developer Mode

    DietrichGebert/ponytail

    Makes the agent pick the laziest solution that works: skip unneeded work, reuse what exists, prefer the standard library and platform features, and keep diffs small.

    160k GitHub starsUsed in 1 repo~873 tokens
    DevelopmentAuto-check passed

More from shadcn-labs/agentcn

  • Flue

    shadcn-labs/agentcn

    A skill your agent uses when building, debugging, reviewing, or documenting Flue agents, workflows, channels, skills, tools, sandboxes, targets, routing, persistence, observability, or CLI usage…

    490 GitHub stars~2k tokensUpdated 4 days ago
    Auto-check passed
  • SEO Audit

    shadcn-labs/agentcn

    How to present the deterministic AI-SEO audit returned by auditpage.

    490 GitHub stars~598 tokensUpdated 4 days ago
    Auto-check passed
  • Research

    shadcn-labs/agentcn

    Iterative, self-evaluating web research. An agent skill from shadcn-labs/agentcn.

    490 GitHub stars~133 tokensUpdated 4 days ago
    Auto-check passed
  • Workspace

    shadcn-labs/agentcn

    How to safely operate the sandboxed workspace. An agent skill from shadcn-labs/agentcn.

    490 GitHub stars~141 tokensUpdated 4 days ago
    Auto-check passed

Works with

Questions about Mastra File Agents

What does Mastra File Agents do?

Migrate Mastra code-based agents (agents built with new Agent(...) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents. Mastra File Agents is an agent skill from shadcn-labs/agentcn.) and registered in a Mastra({ agents }) map) to the file-based convention: one directory per agent under src/mastra/agents.

When should I use Mastra File Agents?

Mastra File Agents fits situations like: the user wants to convert; refactor Mastra agents to the per-directory convention; mentions Mastra file-based agents; wants to split a big src/mastra/index.ts.

How do I install Mastra File Agents in Claude Code?

Run `npx skills add shadcn-labs/agentcn --skill mastra-file-agents -a claude-code`. Or copy the skill folder (.agents/skills/mastra-file-agents in shadcn-labs/agentcn) into .claude/skills/mastra-file-agents in your project. Claude Code loads it when a task matches its description.

How do I install Mastra File Agents in Codex?

Run `npx skills add shadcn-labs/agentcn --skill mastra-file-agents -a codex`. Or copy the skill folder (.agents/skills/mastra-file-agents in shadcn-labs/agentcn) into .agents/skills/mastra-file-agents in your project. Codex loads it when a task matches its description.

Can I use Mastra File Agents in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add shadcn-labs/agentcn --skill mastra-file-agents -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mastra-file-agents, .gemini/skills/mastra-file-agents, .github/skills/mastra-file-agents and .opencode/skills/mastra-file-agents in your project.

What does Mastra File Agents need to run?

Going by SKILL.md and its folder, Mastra File Agents needs TypeScript for the scripts in its folder and the command-line tools its instructions call (npx). Our summary lists: Node.js. Compatibility (from SKILL.md): A Mastra project using @mastra/core >= 1.48.0. Agents must run through the Mastra CLI (mastra dev / mastra build) for file-based discovery..

Does Mastra File Agents access the network?

SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Mastra File Agents safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mastra File Agents use?

Mastra File Agents is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mastra File Agents use?

About 2.4k tokens (SKILL.md is roughly 9.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 2.3k tokens, read only when the agent opens those files.

What are the alternatives to Mastra File Agents?

Skills that share tags, products or a category with Mastra File Agents: React Best Practices (mastra-ai/mastra, 29k stars), Nestjs Best Practices (rolling-scopes/rsschool-app, 10k stars), Guidelines (akash-network/node, 1.1k stars) and Migrate Core Code to Submodules (tinyhumansai/openhuman, 42k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mastra File Agents?

shadcn-labs (a GitHub organization) maintains it in shadcn-labs/agentcn, which has 490 GitHub stars. The repository holds 5 skills in this directory. The repository was last updated on October 7, 2026.

Source: shadcn-labs/agentcn on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.