Authoring Commands
This guide explains how to write effective commands for Archonβs AI workflow system. Commands are the building blocks of workflows - each command is a prompt template that instructs the AI agent what to do.
What is a Command?
Section titled βWhat is a Command?βA command is a markdown file that serves as a detailed instruction set for an AI agent. When a workflow executes a step like - command: investigate-issue, Archon:
- Loads the command file from
.archon/commands/investigate-issue.md - Substitutes variables like
$ARGUMENTSwith actual values - Sends the entire document as a prompt to the AI
- The AI follows the instructions and produces output
Commands are prompts, not code. They guide AI behavior through clear instructions.
File Format
Section titled βFile FormatβCommands live in .archon/commands/ relative to the working directory and are loaded at runtime.
CLI vs Server: The CLI reads commands from wherever you run it (sees uncommitted changes). The server reads from
~/.archon/workspaces/owner/repo/, which only syncs from the remote before worktree creation β so changes must be committed and pushed for the server to pick them up.
Commands use this structure:
---description: One-line description shown in /commands listargument-hint: <expected-input-format>---
# Command Name
**Input**: $ARGUMENTS
---
[Instructions for the AI agent...]Frontmatter Fields
Section titled βFrontmatter Fieldsβ| Field | Required | Purpose |
|---|---|---|
description | Recommended | Shown in /commands list and workflow routing |
argument-hint | Optional | Tells users what input to provide |
The Golden Rule: Artifacts Are Everything
Section titled βThe Golden Rule: Artifacts Are EverythingβThe artifact you produce IS the specification for the next step.
In multi-step workflows, agents donβt share memory. The ONLY way to pass information between steps is through artifacts - files saved to disk.
Step 1: investigate-issue Step 2: implement-issueβββββββββββββββββββββββ ββββββββββββββββββββββββ AI Agent A β β AI Agent B ββ β β ββ Analyzes issue β β Reads artifact ββ Produces artifact βββΌβββββββΌβ> Executes plan ββ β β ββββββββββββββββββββββββ βββββββββββββββββββββββ β β βΌ β $ARTIFACTS_DIR/ β issues/issue-123.md ββββββββββββββββWhy This Matters
Section titled βWhy This Mattersβ- No shared context: Each workflow node can run with
context: fresh - Resumability: If a step fails, the artifact preserves progress
- Auditability: Artifacts create a paper trail of AI decisions
- Handoff quality: The artifact determines if the next step succeeds
What Makes a Good Artifact
Section titled βWhat Makes a Good ArtifactβThe artifact must contain everything the next agent needs:
| Include | Why |
|---|---|
| Problem statement | Next agent needs context |
| Specific file paths + line numbers | No guessing where to look |
| Actual code snippets | Not summaries - real code |
| Step-by-step implementation plan | Actionable without questions |
| Validation commands | How to verify success |
| Edge cases and risks | What to watch out for |
Bad artifact: βFix the authentication bug in the login handlerβ
Good artifact:
## ProblemUsers get 401 errors when token refresh races with API calls.
## Root Cause`src/auth/refresh.ts:45` - The refresh lock doesn't wait for in-flight requests.
## Implementation Plan
### Step 1: Add request queue**File**: `src/auth/refresh.ts`**Lines**: 45-60
**Current code:**```typescriptasync function refresh() { // Current problematic code}```
**Change to:**```typescriptasync function refresh() { // Fixed code with queue}```
### Step 2: Add test**File**: `src/auth/refresh.test.ts`**Action**: CREATE
```typescriptdescribe('refresh', () => { it('queues requests during refresh', async () => { // Test implementation });});```
## Validation```bashbun run type-checkbun test src/auth/```Command Structure
Section titled βCommand StructureβPhase-Based Organization
Section titled βPhase-Based OrganizationβBreak commands into clear phases. This helps the AI:
- Know where it is in the process
- Self-verify before proceeding
- Recover if something fails
## Phase 1: LOAD - Get Context
### 1.1 First action[Instructions...]
### 1.2 Second action[Instructions...]
**PHASE_1_CHECKPOINT:**- [ ] Data loaded- [ ] Context understood- [ ] Ready to proceed
---
## Phase 2: ANALYZE - Process Information
[...]Why Phases Work
Section titled βWhy Phases Workβ- Chunked reasoning: AI handles complex tasks better in pieces
- Self-verification: Checkpoints force the AI to validate progress
- Debugging: When something fails, you know which phase
- Consistency: Similar structure across commands = predictable behavior
Common Phase Patterns
Section titled βCommon Phase Patternsβ| Phase Name | Purpose | Example Actions |
|---|---|---|
| LOAD | Gather inputs and context | Read files, fetch from GitHub, parse arguments |
| EXPLORE | Understand the codebase | Search for patterns, trace code flow |
| ANALYZE | Form conclusions | Root cause analysis, design decisions |
| GENERATE | Produce output | Write artifact, create files |
| VALIDATE | Verify correctness | Run tests, check types, review output |
| COMMIT | Save to git | Stage, commit, push |
| REPORT | Communicate results | Output summary to user |
Checkpoints
Section titled βCheckpointsβEnd each phase with a checkpoint:
**PHASE_2_CHECKPOINT:**- [ ] Root cause identified with evidence- [ ] All affected files listed- [ ] Implementation approach determinedWhy Checkpoints Matter
Section titled βWhy Checkpoints Matterβ- Self-regulation: AI verifies it completed all steps
- Quality gate: Prevents rushing to next phase
- Debugging aid: Shows where process broke down
- Documentation: Records what was accomplished
Variable Substitution
Section titled βVariable SubstitutionβArchon replaces variables in command text before sending to the AI. The most commonly used variables in commands:
| Variable | Value |
|---|---|
$ARGUMENTS / $USER_MESSAGE | Userβs input message |
$1, $2, $3 | Positional arguments (direct invocation only) |
$ARTIFACTS_DIR | Pre-created artifacts directory for this workflow run |
$BASE_BRANCH | Base branch (auto-detected or configured) |
$DOCS_DIR | Documentation directory path (default: docs/) |
$WORKFLOW_ID | Unique workflow run ID |
$CONTEXT | GitHub issue/PR context (if available) |
See the Variable Reference for the complete list, including $LOOP_USER_INPUT, $REJECTION_REASON, node output references, substitution order, and context variable behavior.
Usage Pattern
Section titled βUsage PatternβAlways show the input at the top:
# Investigate Issue
**Input**: $ARGUMENTS
---
## Your Mission[...]This ensures the AI knows exactly what itβs working with.
Artifact Conventions
Section titled βArtifact ConventionsβWhere Artifacts Live
Section titled βWhere Artifacts LiveβArtifacts are stored outside the repository in the Archon workspace directory. Use the $ARTIFACTS_DIR variable to reference the pre-created artifacts directory for each workflow run:
~/.archon/workspaces/owner/repo/artifacts/runs/{workflow-id}/This keeps artifacts out of git and avoids polluting the working tree.
Naming Conventions
Section titled βNaming Conventionsβ| Artifact Type | Path Pattern |
|---|---|
| Issue investigation | $ARTIFACTS_DIR/issues/issue-{number}.md |
| Free-form investigation | $ARTIFACTS_DIR/issues/investigation-{timestamp}.md |
| PR review scope | $ARTIFACTS_DIR/reviews/pr-{number}/scope.md |
| Code review findings | $ARTIFACTS_DIR/reviews/pr-{number}/code-review-findings.md |
Instructing the AI to Save
Section titled βInstructing the AI to SaveβBe explicit about artifact creation:
## Phase 4: GENERATE - Create Artifact
### 4.1 Create Directory
```bashmkdir -p $ARTIFACTS_DIR/issues4.2 Write Artifact
Section titled β4.2 Write ArtifactβWrite to $ARTIFACTS_DIR/issues/issue-{number}.md:
# Investigation: {Title}
**Issue**: #{number}**Type**: {BUG|ENHANCEMENT}...CRITICAL: This artifact is the ONLY way to pass information to the next workflow step. Include everything needed for implementation:
- Exact file paths with line numbers
- Actual code snippets (not summaries)
- Step-by-step implementation instructions
- Validation commands
- Edge cases to handle
The implementing agent will work ONLY from this artifact.
---
## Writing Effective Instructions
### Be Explicit About Tools
Tell the AI which tools to use:
```markdown### 2.1 Search for Relevant Code
Use Task tool with subagent_type="Explore":Find all files related to authentication:
- Token handling
- Session management
- Login/logout flows
### 2.2 Check Git History
```bashgit log --oneline -10 -- {affected-file}git blame -L {start},{end} {affected-file}### Provide Decision Trees
Help the AI handle different scenarios:
```markdown### 3.2 Handle Git Stateββ IN WORKTREE? β ββ YES β Use it (assume itβs for this work) β ββ ON MAIN BRANCH? β ββ Clean? β Create branch: fix/issue-{number} β ββ Dirty? β STOP, ask user to commit/stash β ββ ON FEATURE BRANCH? ββ Use it (assume itβs for this work)
Include Error Handling
Section titled βInclude Error HandlingβTell the AI what to do when things go wrong:
## Handling Edge Cases
### Artifact not foundArtifact not found at $ARTIFACTS_DIR/issues/issue-{number}.md
Run /investigate-issue {number} first.
### Code has driftedCode has changed since investigation:
File: src/x.ts:45
- Artifact expected: {snippet}
- Actual code: {different}
Options:
- Re-run /investigate-issue
- Proceed with manual adjustments
Success Criteria
Section titled βSuccess CriteriaβEnd every command with clear success criteria:
## Success Criteria
- **ARTIFACT_COMPLETE**: All sections filled with specific content- **EVIDENCE_BASED**: Every claim has file:line reference- **IMPLEMENTABLE**: Next agent can execute without questions- **COMMITTED**: Artifact saved in gitThese serve as:
- Final checklist for the AI
- Definition of βdoneβ
- Quality bar for the command
Template: Basic Command
Section titled βTemplate: Basic Commandβ---description: Brief description of what this command doesargument-hint: <expected-input>---
# Command Name
**Input**: $ARGUMENTS
---
## Your Mission
{1-2 sentences explaining the goal and what success looks like}
**Output artifact**: `$ARTIFACTS_DIR/{category}/{name}.md`
---
## Phase 1: LOAD - Gather Context
### 1.1 Parse Input
{Instructions for understanding the input}
### 1.2 Load Dependencies
{Instructions for loading required context}
**PHASE_1_CHECKPOINT:**- [ ] Input parsed correctly- [ ] Required context loaded
---
## Phase 2: PROCESS - Do the Work
### 2.1 Main Action
{Core instructions}
### 2.2 Secondary Action
{Supporting instructions}
**PHASE_2_CHECKPOINT:**- [ ] Main work completed- [ ] Results validated
---
## Phase 3: GENERATE - Create Artifact
### 3.1 Artifact Location
```bashmkdir -p $ARTIFACTS_DIR/{category}Path: $ARTIFACTS_DIR/{category}/{name}.md
3.2 Artifact Content
Section titled β3.2 Artifact ContentβWrite this structure:
# {Title}
**Created**: {timestamp}**Input**: {original input}
## Summary
{Key findings/results}
## Details
{Comprehensive information for next step}
## Next Steps
{What the next agent should do with this}CRITICAL: Include everything the next workflow step needs.
PHASE_3_CHECKPOINT:
- Artifact file created
- All sections populated
- Information is actionable
Phase 4: COMMIT - Save Work
Section titled βPhase 4: COMMIT - Save Workβgit add .git commit -m "{Descriptive message}"PHASE_4_CHECKPOINT:
- Changes committed
Phase 5: REPORT - Output Results
Section titled βPhase 5: REPORT - Output Resultsβ## Complete
**Artifact**: `$ARTIFACTS_DIR/{category}/{name}.md`
### Summary
{Brief results}
### Next Step
Run `/{next-command}` to continue.Success Criteria
Section titled βSuccess Criteriaβ- CONTEXT_LOADED: Required information gathered
- WORK_COMPLETE: Main task accomplished
- ARTIFACT_SAVED: Output written to correct location
- COMMITTED: Changes saved to git
---
## Anti-Patterns to Avoid
### 1. Vague Instructions
Bad:```markdownAnalyze the code and find the problem.Good:
### 2.1 Trace the Error Path
1. Find where the error originates using grep: ```bash grep -r "ErrorType" src/-
Read the file and identify the function:
Terminal window cat src/handlers/error.ts -
Document the call chain leading to the error.
### 2. Missing Artifact Instructions
Bad:```markdown## Results
Output your findings.Good:
## Phase 4: GENERATE - Create Artifact
Write to `$ARTIFACTS_DIR/issues/issue-{number}.md`:
[Exact template with all required sections]
**CRITICAL**: This artifact is the handoff to the implementing agent.3. No Error Handling
Section titled β3. No Error HandlingβBad:
Create the PR.Good:
### Create PR
**First, check if PR already exists:**```bashgh pr list --head $(git branch --show-current)If PR exists: Use existing PR, skip creation.
If no PR: Create new PR:
gh pr create --title "..." --body "..."### 4. Assuming Context
Bad:```markdownFix the bug in the file we discussed.Good:
### 1.1 Load Artifact
```bashcat $ARTIFACTS_DIR/issues/issue-{number}.mdExtract:
- File paths to modify
- Line numbers for changes
- Expected behavior
---
## Testing Your Command
1. **Run it manually**: `bun run cli workflow run {workflow} "test input"`2. **Check artifact output**: Does it contain everything needed?3. **Simulate next step**: Can another agent work from just the artifact?4. **Edge cases**: What happens with bad input? Missing files?
---
## Summary
1. **Commands are prompts** - Write clear instructions for AI agents2. **Artifacts are the handoff** - The ONLY way to pass data between steps3. **Use phases** - Break work into verifiable chunks4. **Be explicit** - Tell the AI exactly what to do, where, and how5. **Include everything** - The next agent works ONLY from your artifact