Claude Code Integration
Orchex integrates seamlessly with the Claude Code CLI to provide AI-assisted orchestration directly from your terminal. This guide covers installation, configuration, and common workflows.
Overview
The Claude Code CLI is Anthropic's official command-line interface for Claude. When combined with Orchex's MCP server, you get:
- AI-assisted manifest creation: Describe your goals, Claude helps structure them
- Interactive execution: Run manifests with real-time feedback
- Smart debugging: Claude can analyze failures and suggest fixes
- Workflow automation: Chain commands for complex development tasks
Prerequisites
- Node.js 18+ installed
- API key for your preferred LLM provider:
- Anthropic: console.anthropic.com
- OpenAI: platform.openai.com
- Google Gemini: aistudio.google.com
- Ollama: No key needed (local models)
- Orchex installed (
npm install -g @wundam/orchex)
Installation
1. Install Claude Code CLI
npm install -g @anthropic-ai/claude-codeOr using Homebrew:
brew install anthropic/tap/claude2. Configure LLM Provider
Set your API key for your preferred provider. Orchex auto-detects which provider to use based on available keys:
Anthropic (Claude):
export ANTHROPIC_API_KEY="sk-ant-..."OpenAI (GPT-4, GPT-4.5):
export OPENAI_API_KEY="sk-..."Google Gemini:
export GEMINI_API_KEY="AI..."
# or
export GOOGLE_API_KEY="AI..."Ollama (local models):
# No API key needed - just ensure Ollama is running
export OLLAMA_BASE_URL="http://localhost:11434"Explicit provider selection (optional):
# Force a specific provider even if multiple keys are set
export ORCHEX_PROVIDER="openai" # or: anthropic, gemini, ollamaAdd to your shell profile (.bashrc, .zshrc, etc.) to persist:
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.zshrc3. Configure Orchex MCP Server
Create or update .mcp.json in your project root. The configuration depends on your LLM provider:
Anthropic (Claude):
{
"mcpServers": {
"orchex": {
"command": "npx",
"args": ["@wundam/orchex", "mcp"],
"env": {
"ANTHROPIC_API_KEY": "${ANTHROPIC_API_KEY}"
}
}
}
}OpenAI (GPT-4, GPT-4.5):
{
"mcpServers": {
"orchex": {
"command": "npx",
"args": ["@wundam/orchex", "mcp"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}"
}
}
}
}Google Gemini:
{
"mcpServers": {
"orchex": {
"command": "npx",
"args": ["@wundam/orchex", "mcp"],
"env": {
"GEMINI_API_KEY": "${GEMINI_API_KEY}"
}
}
}
}Ollama (local models):
{
"mcpServers": {
"orchex": {
"command": "npx",
"args": ["@wundam/orchex", "mcp"],
"env": {
"OLLAMA_BASE_URL": "http://localhost:11434"
}
}
}
}Global Configuration (for all projects):
Create ~/.mcp.json with your provider configuration. Example for OpenAI:
{
"mcpServers": {
"orchex": {
"command": "orchex",
"args": ["mcp"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}"
}
}
}
}4. Verify Installation
# Check Claude Code
claude --version
# Check Orchex
orchex --version
# Test MCP connection
claude "List available Orchex commands"Configuration Options
Environment Variables
# LLM Provider (one required)
export ANTHROPIC_API_KEY="sk-ant-..." # For Claude
export OPENAI_API_KEY="sk-..." # For GPT-4/4.5
export GEMINI_API_KEY="AI..." # For Gemini 1.5/2.0
export OLLAMA_BASE_URL="http://..." # For local Ollama
# Provider Selection (optional - auto-detected if not set)
export ORCHEX_PROVIDER="openai" # Force specific provider
# Optional
export ORCHEX_LOG_LEVEL="info" # debug, info, warn, error
export ORCHEX_ARTIFACTS_DIR=".orchex" # where to store outputs
export ORCHEX_MAX_PARALLEL=5 # max concurrent streamsAdvanced MCP Configuration
For team environments or custom setups with explicit provider selection:
{
"mcpServers": {
"orchex": {
"command": "orchex",
"args": ["mcp"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}",
"ORCHEX_PROVIDER": "openai",
"ORCHEX_CLOUD_TOKEN": "${ORCHEX_CLOUD_TOKEN}",
"ORCHEX_TEAM_ID": "team_abc123"
},
"settings": {
"defaultExecutor": "cloud",
"autoVerify": true,
"saveArtifacts": true
}
}
}
}Multi-provider setup (switch providers easily):
{
"mcpServers": {
"orchex-claude": {
"command": "orchex",
"args": ["mcp"],
"env": {
"ANTHROPIC_API_KEY": "${ANTHROPIC_API_KEY}"
}
},
"orchex-gpt": {
"command": "orchex",
"args": ["mcp"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}"
}
},
"orchex-local": {
"command": "orchex",
"args": ["mcp"],
"env": {
"OLLAMA_BASE_URL": "http://localhost:11434"
}
}
}
}Slash Commands
Claude Code provides convenient slash commands for common Orchex operations:
`/orchex-create`
Create a new manifest interactively:
claude
> /orchex-create "Add user authentication to the API"Claude will:
- Analyze your project structure
- Suggest stream breakdown
- Create a manifest file
- Ask for your approval before saving
`/orchex-run`
Execute an existing manifest:
claude
> /orchex-run manifest.yamlOptions:
# Dry run (show plan without executing)
> /orchex-run manifest.yaml --dry-run
# Run specific streams only
> /orchex-run manifest.yaml --streams="setup,core"
# Use cloud executor
> /orchex-run manifest.yaml --cloud`/orchex-status`
Check execution status:
claude
> /orchex-statusShows:
- Currently running executions
- Completed streams
- Failed streams with errors
- Resource usage (tokens, API calls)
`/orchex-debug`
Analyze failures and get suggestions:
claude
> /orchex-debug exec_abc123Claude will:
- Review error logs
- Analyze context and prompts
- Suggest fixes (prompt improvements, dependency changes)
- Offer to update the manifest automatically
`/orchex-optimize`
Improve manifest efficiency:
claude
> /orchex-optimize manifest.yamlAnalyzes:
- Parallelization opportunities
- Context bloat
- Redundant dependencies
- Prompt clarity
Workflow Examples
Example 1: Feature Development
End-to-end feature implementation:
# Start Claude Code
claude
# Create manifest
> Help me add a user profile page to my Next.js app.
> It should include:
> - Profile display with avatar
> - Edit form
> - API routes
> - Tests
> Can you create an Orchex manifest for this?
# Claude creates the manifest, then:
> /orchex-run profile-feature.yaml
# Monitor progress
> /orchex-status
# If any stream fails:
> /orchex-debug exec_abc123
> Apply the suggested fixesExample 2: Bug Fix
Quickly fix a reported issue:
claude "I have a bug where user sessions expire too quickly.
The issue is in src/auth/session.ts.
Can you create a manifest to:
1. Investigate the current timeout logic
2. Fix it to use 7 day expiration
3. Add tests
4. Update documentation"
# Claude creates manifest
> /orchex-run fix-session-bug.yamlExample 3: Refactoring
Safe, tested refactoring:
claude "I need to refactor src/utils/validation.ts to use Zod instead of custom validators.
Create a manifest that:
1. Analyzes current validation logic
2. Installs Zod
3. Rewrites validators
4. Updates all imports
5. Runs tests to verify
6. Updates type definitions"
> /orchex-run refactor-validation.yamlExample 4: Documentation Sprint
Generate comprehensive docs:
claude "Generate API documentation for all routes in src/api/.
Include:
- OpenAPI spec
- Example requests/responses
- Authentication requirements
- Error codes
Create an Orchex manifest to do this systematically."
> /orchex-run generate-api-docs.yaml --streams="analyze,openapi,examples"Example 5: Multi-Stage Migration
Complex migrations with verification:
claude "Create a manifest to migrate from Express to Fastify:
Wave 1: Setup
- Install Fastify
- Create parallel server structure
- Set up plugins
Wave 2: Migrate routes
- Convert auth routes
- Convert API routes
- Convert webhooks
Wave 3: Testing
- Port tests
- Add integration tests
- Performance benchmarks
Wave 4: Cleanup
- Remove Express
- Update docs
- Update CI/CD"
> /orchex-run migrate-fastify.yamlAdvanced Usage
Custom Prompts
Create reusable prompt templates:
# In your project, create .claude/prompts/
mkdir -p .claude/prompts
# Create template
cat > .claude/prompts/add-feature.md << 'EOF'
Create an Orchex manifest for adding a new feature.
Feature: {{feature_name}}
Files affected: {{files}}
Include:
1. Implementation stream
2. Test stream (depends on implementation)
3. Documentation stream (depends on implementation)
4. Verification checks
Use parallel execution where possible.
EOF
# Use it
claude "@add-feature.md feature_name='dark mode' files='src/theme/'"Integration with Git
Automate branch and commit management:
claude "Create a manifest that:
1. Creates a new branch 'feature/search'
2. Implements search functionality
3. Runs tests
4. Commits changes
5. Pushes to remote
Don't actually merge, just prepare the PR."CI/CD Integration
Use Claude Code in automation:
# .github/workflows/orchex-review.yml
name: Orchex Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Claude Code
run: npm install -g @anthropic-ai/claude-code @wundam/orchex
- name: Generate Review Manifest
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude "Create an Orchex manifest to review this PR:
- Check for test coverage
- Verify documentation updates
- Look for security issues
- Suggest improvements
Output: review-manifest.yaml"
- name: Run Review
run: orchex run review-manifest.yaml
- name: Post Results
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const results = fs.readFileSync('.orchex/artifacts/review-results.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: results
});Tips & Best Practices
1. Start Small
Begin with simple manifests:
claude "Create a manifest with one stream that adds a new utility function"Gradually increase complexity as you learn.
2. Be Specific
Provide context about your project:
claude "In my Next.js 14 app using TypeScript and Prisma,
create a manifest to add a blog post editor.
We use server components and app router."3. Review Before Running
Always review generated manifests:
# Claude generates manifest
> Show me the full manifest content before we run it
# Make adjustments
> In the 'api-routes' stream, also include rate limiting
# Then run
> /orchex-run blog-editor.yaml4. Use Dry Runs
Test execution plans:
> /orchex-run complex-migration.yaml --dry-runReview the execution plan, then remove --dry-run.
5. Monitor Progress
For long-running executions:
# In one terminal
> /orchex-run large-refactor.yaml
# In another
watch -n 5 'orchex status'6. Save Successful Patterns
Create a library of working manifests:
mkdir -p .orchex/templates
# After successful execution
cp successful-feature.yaml .orchex/templates/add-feature-template.yaml
# Reuse later
claude "Use .orchex/templates/add-feature-template.yaml as a basis,
but adapt it for adding a comments feature instead."Troubleshooting
Claude Can't Find Orchex MCP Server
Symptom: "I don't have access to Orchex commands"
Solution:
# Check .mcp.json exists
cat .mcp.json
# Verify orchex is in PATH
which orchex
# Restart Claude Code session
exit
claude
# Explicitly connect
claude --mcp-config .mcp.jsonManifest Creation Fails
Symptom: Claude creates invalid YAML
Solution:
# Validate manually
orchex validate manifest.yaml
# Show Claude the errors
claude "The manifest has these validation errors: [paste errors]
Please fix them."Execution Hangs
Symptom: Stream appears stuck
Solution:
# Check status with details
orchex status --verbose
# Cancel if needed
orchex cancel exec_abc123
# Debug
claude "The execution hung on stream 'database-migration'.
Here's the log: [paste log]
What went wrong?"High Token Usage
Symptom: Executions use too many tokens
Solution:
# Analyze context
claude "Review my manifest and suggest ways to reduce context size"
# Use optimize command
> /orchex-optimize expensive-manifest.yaml
# Limit context in manifest
# Edit to use more specific file patternsNext Steps
- Manifest Format: Deep dive into YAML structure
- Writing Prompts: Craft effective prompts
- API Reference: Full CLI documentation
- Examples: More workflow examples
- Cloud Integration: Use Orchex Cloud for team workflows
Community & Support
- Email: support@orchex.dev
- Support: Report bugs or request features
- Twitter: @orchex for updates
Contributing
Have a great Claude Code workflow? Share it:
- Document your workflow
- Create a template manifest
- Submit a PR to add it to this guide
See Contributing Guide for details.