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
Keep Prompts Focused
Keep Prompts Focused
Each prompt should have a single, clear purpose. If a prompt is doing too many things, split it into multiple agents or steps.
Be Specific About Output
Be Specific About Output
Always specify:
- What format the output should be in
- Where to write output files
- What the next agent expects to receive
Define Success and Failure
Define Success and Failure
Include clear success and failure indicators so the agent knows when it’s done and what to avoid.
Use Placeholders for Context
Use Placeholders for Context
Don’t hardcode context. Use placeholders to inject:
- Previous agent outputs
- User selections (tracks, conditions)
- Shared content (standards, templates)
Test Incrementally
Test Incrementally
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 inconfig/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:- Agent 1 writes output to
.codemachine/artifacts/planner-output.md - Register placeholder
planner_outputpointing to that file - 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 inconfig/agents.js:
config/agents.js
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
Next Steps
Your First Workflow
Put agents and prompts together in a workflow
Workflow Examples
See complete real-world examples