Skip to main content
Prompts are the instructions that tell agents what to do. Each agent needs prompt files that define its goals and behavior.
Flexible Structure: You can organize your prompt files however you prefer. The examples in this guide (like separating persona from instructions, or using chained/ folders) are recommendations—not requirements. What matters is that your agent config points to the correct paths.

Best Practices

Each prompt should have a single, clear purpose. If a prompt is doing too many things, split it into multiple agents or steps.
Always specify:
  • What format the output should be in
  • Where to write output files
  • What the next agent expects to receive
Include clear success and failure indicators so the agent knows when it’s done and what to avoid.
Don’t hardcode context. Use placeholders to inject:
  • Previous agent outputs
  • User selections (tracks, conditions)
  • Shared content (standards, templates)
Test each prompt individually before combining into a full workflow. Use the TUI to run single agents.

Frontmatter

Every prompt file must begin with YAML frontmatter:

Placeholders

Placeholders inject dynamic content into prompts at runtime. They use triple-brace syntax: {{placeholder_name}}.

Built-in Placeholders

These are always available:

Custom Placeholders

Define custom placeholders in config/placeholders.js:
config/placeholders.js
userDir placeholders resolve to files in the user’s project. packageDir placeholders resolve to files in your workflow package.

Using Placeholders

Reference placeholders in your prompts:

Chaining Agent Outputs

Pass data between agents using output placeholders:
  1. Agent 1 writes output to .codemachine/artifacts/planner-output.md
  2. Register placeholder planner_output pointing to that file
  3. Agent 2 receives content via {{planner_output}}

Module Prompts

Modules are special agents that can loop the workflow back. Their prompts must include directive writing instructions.
prompts/templates/my-workflow/quality-gate/prompt.md

Sub-Agent Prompts

When writing prompts for agents that orchestrate sub-agents, you must include instructions for using MCP tools to spawn and delegate work.
prompts/templates/my-workflow/orchestrator/main.md
Your prompt must instruct the agent to use the agent-coordination MCP tools to spawn sub-agents and delegate specific roles to them.

Configure Agent Coordination MCP

Learn how to set up the agent-coordination MCP for sub-agent orchestration

Controller Prompts

Controllers orchestrate autonomous workflows. They respond on behalf of the user.
prompts/templates/my-workflow/controller/prompt.md

Full Example: Single Agent

Here’s a complete example of a planner agent with all its prompt files. This structure separates persona from instructions, but remember—you can organize files however works best for your workflow.

File Structure

prompts/templates
my-workflow
planner
persona.md
prompt.md

persona.md

prompts/templates/my-workflow/planner/persona.md

prompt.md

prompts/templates/my-workflow/planner/prompt.md

Agent Configuration

This agent would be configured in config/agents.js:
config/agents.js
The file names persona.md and prompt.md are just conventions. You could use identity.md, instructions.md, or any names you prefer—just update the paths in your agent config to match.

Full Example: Multi-Step Agent with Chained Prompts

Here’s a complete example of an onboarding agent that guides users through multiple steps. This uses a workflow file for shared context and chained step files for step-specific instructions.

File Structure

prompts/templates
my-workflow
onboarding
persona.md
workflow.md
chained
step-01-intro.md
step-02-setup.md
step-03-config.md

persona.md

prompts/templates/my-workflow/onboarding/persona.md

workflow.md

prompts/templates/my-workflow/onboarding/workflow.md

chained/step-01-intro.md

prompts/templates/my-workflow/onboarding/chained/step-01-intro.md

chained/step-02-setup.md

prompts/templates/my-workflow/onboarding/chained/step-02-setup.md

chained/step-03-config.md

prompts/templates/my-workflow/onboarding/chained/step-03-config.md

Agent Configuration

config/agents.js
You can use chainedPromptsPath to load all files from a directory (alphabetically), or chainedPrompts to explicitly list files in order. Using both gives you explicit control while keeping files organized in a folder.

Next Steps

Your First Workflow

Put agents and prompts together in a workflow

Workflow Examples

See complete real-world examples