OpenCode AI Agent Setup
This guide covers setting up and using the OpenCode AI agent integration with the CalyCode CLI for AI-assisted Xano development.
Table of Contents
- Overview
- Quick Start
- Setup Command
- Running OpenCode
- Agents & Slash Commands
- Skills
- Configuration Files
- Native Host for Browser Extension
- Troubleshooting
Overview
The CalyCode CLI integrates with OpenCode, an open-source AI coding agent. This integration provides:
- Specialized Xano Agents - AI agents trained for XanoScript development
- Slash Commands - Quick actions for common Xano tasks
- Skills - Domain-specific knowledge for database design, security, and performance
- Browser Extension Support - Native messaging host for the CalyCode Chrome extension
Quick Start
# 1. Install the CLI globally
npm install -g @calycode/cli
# 2. Set up OpenCode with agents, commands, and skills
caly-xano oc setup
# 3. Run OpenCode interactively
caly-xano oc run
# 4. Or run with a specific agent
caly-xano oc run "@xano-planner Plan a user authentication system"
Setup Command
The caly-xano oc setup command installs everything needed for AI-assisted development:
caly-xano oc setup [options]
Options
| Option | Description |
|---|---|
--force | Re-download and overwrite existing configuration |
--skip-config | Skip template/skill installation |
--extension-id | Register additional Chrome extension IDs |
What Gets Installed
The setup command installs files to ~/.calycode/opencode/:
~/.calycode/opencode/
├── opencode.json # OpenCode configuration
├── AGENTS.md # Global agent instructions
├── agents/ # Specialized agents
│ ├── xano-planner.md
│ ├── xano-table-designer.md
│ ├── xano-function-writer.md
│ ├── xano-api-writer.md
│ ├── xano-addon-writer.md
│ ├── xano-task-writer.md
│ ├── xano-ai-builder.md
│ └── ...
├── commands/ # Slash commands
│ ├── xano-plan.md
│ ├── xano-table.md
│ ├── xano-function.md
│ ├── xano-api.md
│ └── ...
└── skills/ # Domain-specific knowledge
├── xano-database-best-practices/
├── xano-query-performance/
├── xano-schema-design/
├── xano-security/
├── xano-data-access/
├── xano-monitoring/
└── caly-xano-cli/
Update Templates
To get the latest agents, commands, and skills:
# Force re-download all templates
caly-xano oc setup --force
# Or update just templates
caly-xano oc update
Running OpenCode
Interactive Mode
Start an interactive AI coding session:
# Start OpenCode in the current directory
caly-xano oc run
# Start in a specific project directory
caly-xano oc run --workdir /path/to/project
With Initial Prompt
Run with a specific task or agent:
# Use a specialized agent
caly-xano oc run "@xano-planner Design a blog backend with posts and comments"
# Use a slash command
caly-xano oc run "/xano-table Create a users table with email and password"
# Simple prompt
caly-xano oc run "Help me understand this XanoScript function"
Server Mode
Run OpenCode as an HTTP server for programmatic access:
# Start server on default port (4096)
caly-xano oc serve
# Start on a specific port
caly-xano oc serve --port 8080
# Start in background (detached)
caly-xano oc serve --detach
Agents & Slash Commands
Specialized Agents
Use @agent-name to delegate to specialized agents:
| Agent | Use Case |
|---|---|
@xano-planner | Plan features and create implementation roadmaps |
@xano-table-designer | Design database tables with schemas and indexes |
@xano-function-writer | Create reusable functions with business logic |
@xano-api-writer | Create REST API endpoints |
@xano-addon-writer | Create addons for related data fetching |
@xano-task-writer | Create scheduled tasks for background processing |
@xano-ai-builder | Build AI agents, tools, and MCP servers |
@xano-expert | General Xano expertise and troubleshooting |
@debug-helper | Debug API and function issues |
Examples
# Plan a feature
caly-xano oc run "@xano-planner Plan a subscription billing system with Stripe"
# Design a table
caly-xano oc run "@xano-table-designer Create a products table for an e-commerce store"
# Create an API
caly-xano oc run "@xano-api-writer Create CRUD endpoints for user management"
# Debug an issue
caly-xano oc run "@debug-helper My API is returning 500 errors on POST requests"
Slash Commands
Use /command for quick actions:
| Command | Description |
|---|---|
/xano-plan | Plan a feature or project implementation |
/xano-table | Create a XanoScript database table |
/xano-function | Create a XanoScript function |
/xano-api | Create a XanoScript API endpoint |
/xano-addon | Create a XanoScript addon |
/xano-task | Create a XanoScript scheduled task |
/xano-ai | Build AI agents, tools, or MCP servers |
/xano-docs | Search Xano documentation |
/debug-api | Debug an API endpoint |
/generate-sdk | Generate TypeScript SDK from OpenAPI |
Examples
# Create a table
caly-xano oc run "/xano-table users with email, password_hash, role enum (admin, user)"
# Create a function
caly-xano oc run "/xano-function calculate_order_total that sums line items with tax"
# Create an API
caly-xano oc run "/xano-api POST /checkout that processes payment and creates order"
Skills
Skills provide domain-specific knowledge that agents can reference. They are loaded automatically when relevant tasks are detected.
Available Skills
| Skill | Description |
|---|---|
xano-database-best-practices | PostgreSQL best practices for Xano |
xano-query-performance | Query optimization, N+1 prevention, indexing |
xano-schema-design | Schema normalization, data types, constraints |
xano-security | Row Level Security, injection prevention, auth |
xano-data-access | Addons, batch operations, caching patterns |
xano-monitoring | Query Analytics, debugging slow queries |
caly-xano-cli | CalyCode CLI commands and workflows |
Skill Selection Guide
| Task | Primary Skill | Supporting Skills |
|---|---|---|
| New table design | xano-schema-design | xano-database-best-practices |
| Slow API response | xano-query-performance | xano-monitoring |
| N+1 query issues | xano-query-performance | xano-data-access |
| Security audit | xano-security | xano-data-access |
| CLI commands | caly-xano-cli | - |
| Production debugging | xano-monitoring | xano-query-performance |
Using Skills Explicitly
You can reference skills in your prompts:
caly-xano oc run "Use the xano-security skill to review this login endpoint"
caly-xano oc run "Apply xano-query-performance patterns to optimize this data fetching"
Configuration Files
opencode.json
The main OpenCode configuration at ~/.calycode/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"model": "github-copilot/claude-sonnet-4.5",
"small_model": "github-copilot/claude-haiku-4.5",
"autoupdate": true,
"instructions": ["~/.config/opencode/AGENTS.md"],
"permission": {
"edit": "ask",
"bash": {
"*": "ask",
"git status": "allow",
"git diff": "allow",
"git log": "allow",
"npm test": "allow",
"pnpm test": "allow"
}
}
}
Customizing Configuration
You can modify the configuration to:
- Change the default model
- Add custom instructions
- Adjust permission settings
- Enable auto-approve for specific commands
Environment Variables
| Variable | Description |
|---|---|
OPENCODE_CONFIG_DIR | Override OpenCode config directory |
CALY_EXTRA_CORS_ORIGINS | Additional CORS origins for server mode (comma-separated) |
Native Host for Browser Extension
The CLI can act as a native messaging host for the CalyCode Chrome extension, enabling browser-to-local communication.
How It Works
- Browser extension sends messages via Chrome's Native Messaging API
- The native host (CLI) receives and processes requests
- OpenCode server can be started/stopped from the browser
- Results are returned to the extension
Setup
The native host is automatically configured during xano oc setup. For manual setup:
# Install native host manifest
caly-xano oc setup
# The manifest is created at:
# Windows: %USERPROFILE%\.calycode\com.calycode.host.json
# macOS: ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/
# Linux: ~/.config/google-chrome/NativeMessagingHosts/
Testing Native Host
# Start native host directly (for debugging)
caly-xano oc native-host
# The native host listens for JSON messages on stdin
# and responds on stdout using Chrome's native messaging protocol
Troubleshooting
Common Issues
| Issue | Solution |
|---|---|
| "OpenCode not found" | Run xano oc setup to install configuration |
| "Agent not recognized" | Check agent name spelling, run xano oc setup --force |
| "Permission denied" | Adjust permissions in opencode.json |
| Templates out of date | Run xano oc setup --force to update |
| Native host not working | Re-run xano oc setup, check registry (Windows) |
| Server won't start | Check if port is in use, try different port |
Checking Installation Status
# Check what's installed
ls ~/.calycode/opencode/
# View configuration
cat ~/.calycode/opencode/opencode.json
# List available agents
ls ~/.calycode/opencode/agents/
# List available commands
ls ~/.calycode/opencode/commands/
# List available skills
ls ~/.calycode/opencode/skills/
Logs
Native host logs are written to ~/.calycode/logs/native-host.log:
# View logs (Unix)
tail -f ~/.calycode/logs/native-host.log
# View logs (Windows PowerShell)
Get-Content -Wait $env:USERPROFILE\.calycode\logs\native-host.log
Clearing Cache
# Clear template cache and re-download
caly-xano oc setup --force
Best Practices
1. Recommended Workflow
- Plan first - Use
@xano-plannerto create an implementation plan - Tables first - Create database schemas before APIs
- Functions for reuse - Extract common logic into functions
- APIs last - Build endpoints that use tables and functions
- Tasks for automation - Add scheduled jobs as needed
2. Organize Your Prompts
# Be specific about what you want
caly-xano oc run "@xano-table-designer Create a products table with:
- name (text, required, max 255)
- price (decimal, required, min 0)
- description (text, optional)
- category_id (foreign key to categories)
- created_at (timestamp, auto)"
# Provide context
caly-xano oc run "@xano-api-writer Create a checkout API that:
- Uses the orders table we just created
- Validates cart items exist
- Calculates total with tax
- Returns order confirmation"
3. Use Skills for Complex Tasks
For optimization or security-sensitive work, reference the appropriate skill:
# Security review
caly-xano oc run "Use xano-security skill to audit this user registration endpoint"
# Performance optimization
caly-xano oc run "Apply xano-query-performance to optimize this dashboard query"