README
Overview
This directory contains research findings on developing custom Claude Code agents and the testing workflow needed for iterative development.
Research Tasks Completed
✅ Task 1: Agent Specification Research
Status: Complete Documentation: agent-spec.md
Researched and documented the complete specification for Claude Code custom agents including:
- File structure and storage locations
- YAML frontmatter configuration
- Tool restrictions and model selection
- Best practices and common patterns
- Example agent structures
Key Findings:
- Agents are Markdown files with YAML frontmatter
- Stored in
.claude/agents/*.md(project) or~/.claude/agents/*.md(user) - Critical fields:
name,description,tools,model - The
descriptionfield is crucial for proper delegation - Tool restriction improves security and focus
✅ Task 2: Headless Mode Verification
Status: Confirmed Working Documentation: headless-testing.md
Verified that Claude can run in headless mode via CLI:
$ claude -p "What is 2+2?"4Key Findings:
-p/--printflag enables non-interactive mode- Outputs response to stdout and exits
- Supports multiple output formats (text, json, stream-json)
- Can continue conversations with
--continue - Provides extensive configuration options
✅ Task 3: Headless Agent Invocation
Status: Discovered and Documented Documentation: headless-agent-testing-guide.md
Key Discovery: Agents CAN be invoked in headless mode with explicit syntax:
claude -p "Use the [agent-name] and provide its complete response. [task]"Example:
$ claude -p "Use the simple-agent and provide its complete response."SIMPLE AGENT ACTIVATEDAgent: simple-agentStatus: Working!✅ The agent was successfully invoked✅ Custom agents are working correctlyCritical Requirements:
- Run from project root (where
.claude/agents/exists) - Explicitly name the agent: “Use the [agent-name]”
- Request complete response: “and provide its complete response”
- Complex agents may timeout - use simpler test queries
The Development Challenge
Problem: Agent files are loaded when Claude Code starts. Changes to agent .md files require restarting the interactive session to take effect.
Solution: Use headless mode for rapid iterative testing.
Recommended Development Workflow
# 1. Create or edit agentvim .claude/agents/my-agent.md
# 2. Test immediately in headless mode (loads fresh agent definitions)# IMPORTANT: Explicitly invoke the agent by name!claude -p "Use the my-agent and provide its complete response. Test functionality."
# 3. Iterate rapidly without session restartsvim .claude/agents/my-agent.mdclaude -p "Use the my-agent and provide its complete response. Test with different input."claude -p "Use the my-agent and provide its complete response. Edge case testing."
# 4. Once satisfied, restart interactive session for production use# (Only restart when you're done iterating)Key Pattern for Headless Testing:
claude -p "Use the [agent-name] and provide its complete response. [your task]" ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ Explicit agent Request raw output Your testQuick Start
Create Your First Agent
# 1. Create agent filecat > .claude/agents/example.md << 'EOF'---name: exampledescription: Example agent that demonstrates basic structuretools: Read, Writemodel: haiku---
You are an example agent. Your purpose is to demonstratethe basic structure and capabilities of Claude Code agents.EOF
# 2. Test it immediatelyclaude -p "Show me how the example agent works"
# 3. Iterate and refinevim .claude/agents/example.mdclaude -p "Test again"Testing Patterns
# Fast testing with Haikuclaude -p "Quick test" --model haiku
# Realistic testing with Sonnetclaude -p "Real world test" --model sonnet
# JSON output for automationclaude -p "Generate data" --output-format json
# Tool restrictionsclaude -p "Read only test" --tools "Read,Grep"
# Continue conversationclaude -p "First prompt"claude -p "Follow up" --continueDocumentation Structure
agent-spec.md
Complete specification of the agent file format:
- File structure and YAML frontmatter
- Configuration fields and options
- System prompt guidelines
- Example agent structures
- Best practices and patterns
- Troubleshooting guide
headless-testing.md
Comprehensive guide to headless mode testing:
- Basic usage and options
- Agent development workflow
- Testing patterns and examples
- Scripting and automation
- Debugging techniques
- Best practices
README.md (this file)
Overview and quick reference for the research.
Key Insights
Agent Development
- Description is critical: It determines when agents are invoked
- Tool restriction improves focus: Limit to minimum required
- Start simple: Iterate based on real usage
- Use appropriate models: Haiku for speed, Sonnet for balance, Opus for complexity
Testing Strategy
- Headless mode is essential: Enables rapid iteration without restarts
- Test incrementally: Small changes, quick validation
- Use JSON output: Enables automation and verification
- Script your tests: Build regression suites
Workflow Optimization
- Separate testing from production: Use headless for development, interactive for real work
- Only restart when satisfied: Minimize disruption to interactive sessions
- Version your agents: Track changes like code
- Document learnings: Update agent prompts with insights
Project Structure Created
.claude/└── agents/ # Project-level agents (created) └── (your agents here)
~/.claude/└── agents/ # User-level agents (already exists) ├── collaboration-analyst.md └── diagram-generator.mdNext Steps
To set up an agent development environment:
-
Create test agent directory structure
Terminal window mkdir -p .claude/agentsmkdir -p test/agent-tests -
Create a test harness script
test/agent-tests/run-tests.sh #!/bin/bashfor test in test/agent-tests/*.txt; doecho "Testing: $test"claude -p "$(cat $test)" --output-format jsondone -
Set up CI/CD integration
- Run headless tests on commits
- Validate agent syntax
- Check for regression
-
Create agent templates
- Starter templates for common patterns
- Boilerplate for new agents
-
Build agent library
- Catalog of reusable agents
- Documentation and examples
- Version management
Additional Resources
Built-in Examples
# View existing agentsls -la ~/.claude/agents/cat ~/.claude/agents/collaboration-analyst.mdcat ~/.claude/agents/diagram-generator.mdCLI Help
# View all optionsclaude --help
# View agent-specific helpclaude --help | grep -A5 agentsOnline Documentation
- Claude Code: Use
/helpcommand in interactive mode - Agent SDK: Additional capabilities for plugin development
Environment Requirements
- Claude Code: Installed and authenticated
- Shell access: For headless mode testing
- Text editor: For editing agent files
- Optional:
jqfor JSON processing
Verification
All research findings have been verified:
✅ Agent spec researched and documented ✅ Headless mode confirmed working ✅ Documentation created ✅ Quick start examples provided ✅ Workflow optimization documented
Summary
This research establishes a complete foundation for iterative Claude Code agent development:
- Specification: Complete understanding of agent file format
- Testing: Headless mode enables rapid iteration
- Workflow: Optimized development cycle without session restarts
- Documentation: Comprehensive guides for reference
You can now develop agents efficiently using the headless testing workflow!