Skip to content
@calycode/cli docs
GitHub Discord

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

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

Bash
# 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:

Bash
caly-xano oc setup [options]

Options

OptionDescription
--forceRe-download and overwrite existing configuration
--skip-configSkip template/skill installation
--extension-idRegister additional Chrome extension IDs

What Gets Installed

The setup command installs files to ~/.calycode/opencode/:

Code
~/.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:

Bash
# 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:

Bash
# 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:

Bash
# 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:

Bash
# 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:

AgentUse Case
@xano-plannerPlan features and create implementation roadmaps
@xano-table-designerDesign database tables with schemas and indexes
@xano-function-writerCreate reusable functions with business logic
@xano-api-writerCreate REST API endpoints
@xano-addon-writerCreate addons for related data fetching
@xano-task-writerCreate scheduled tasks for background processing
@xano-ai-builderBuild AI agents, tools, and MCP servers
@xano-expertGeneral Xano expertise and troubleshooting
@debug-helperDebug API and function issues

Examples

Bash
# 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:

CommandDescription
/xano-planPlan a feature or project implementation
/xano-tableCreate a XanoScript database table
/xano-functionCreate a XanoScript function
/xano-apiCreate a XanoScript API endpoint
/xano-addonCreate a XanoScript addon
/xano-taskCreate a XanoScript scheduled task
/xano-aiBuild AI agents, tools, or MCP servers
/xano-docsSearch Xano documentation
/debug-apiDebug an API endpoint
/generate-sdkGenerate TypeScript SDK from OpenAPI

Examples

Bash
# 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

SkillDescription
xano-database-best-practicesPostgreSQL best practices for Xano
xano-query-performanceQuery optimization, N+1 prevention, indexing
xano-schema-designSchema normalization, data types, constraints
xano-securityRow Level Security, injection prevention, auth
xano-data-accessAddons, batch operations, caching patterns
xano-monitoringQuery Analytics, debugging slow queries
caly-xano-cliCalyCode CLI commands and workflows

Skill Selection Guide

TaskPrimary SkillSupporting Skills
New table designxano-schema-designxano-database-best-practices
Slow API responsexano-query-performancexano-monitoring
N+1 query issuesxano-query-performancexano-data-access
Security auditxano-securityxano-data-access
CLI commandscaly-xano-cli-
Production debuggingxano-monitoringxano-query-performance

Using Skills Explicitly

You can reference skills in your prompts:

Bash
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:

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

VariableDescription
OPENCODE_CONFIG_DIROverride OpenCode config directory
CALY_EXTRA_CORS_ORIGINSAdditional 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

  1. Browser extension sends messages via Chrome's Native Messaging API
  2. The native host (CLI) receives and processes requests
  3. OpenCode server can be started/stopped from the browser
  4. Results are returned to the extension

Setup

The native host is automatically configured during xano oc setup. For manual setup:

Bash
# 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

Bash
# 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

IssueSolution
"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 dateRun xano oc setup --force to update
Native host not workingRe-run xano oc setup, check registry (Windows)
Server won't startCheck if port is in use, try different port

Checking Installation Status

Bash
# 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:

Bash
# 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

Bash
# Clear template cache and re-download
caly-xano oc setup --force

Best Practices

1. Recommended Workflow

  1. Plan first - Use @xano-planner to create an implementation plan
  2. Tables first - Create database schemas before APIs
  3. Functions for reuse - Extract common logic into functions
  4. APIs last - Build endpoints that use tables and functions
  5. Tasks for automation - Add scheduled jobs as needed

2. Organize Your Prompts

Bash
# 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:

Bash
# 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"

Resources