OpenCode Integration

MCP-based integration for task management and persistent memory in OpenCode sessions.

New in v3.7: One-command setup with sugar opencode setup, plus memory slash commands (/sugar-remember, /sugar-recall, /sugar-context).

Overview

The OpenCode integration provides:

  • MCP servers - Task queue and memory system accessible as OpenCode tools
  • Slash commands - 11 commands for task and memory management
  • One-command setup - Automatic configuration with sugar opencode setup
  • Persistent memory - Remember decisions, preferences, and patterns across sessions

What is OpenCode?

OpenCode is an open-source AI coding agent with 80k+ GitHub stars, built in TypeScript. It's provider-agnostic, supporting 75+ LLMs including Claude, GPT, Gemini, and local models.

Quick Start

# One-command setup - configures OpenCode automatically
sugar opencode setup

# Restart OpenCode to load the MCP servers

# Verify setup
sugar opencode status

The setup command automatically:

  • Finds your OpenCode config file (~/.config/opencode/opencode.json or .opencode/opencode.json)
  • Adds sugar-tasks and sugar-memory MCP servers
  • Preserves your existing configuration

Setup Options

# Preview changes without applying
sugar opencode setup --dry-run

# Non-interactive mode (for scripts/CI)
sugar opencode setup --yes

# Only add task management (no memory)
sugar opencode setup --no-memory

Slash Commands

After setup, you'll have access to 11 slash commands in OpenCode:

# Task Management
/sugar-add       # Add tasks to queue
/sugar-list      # List queued tasks
/sugar-view      # View task details
/sugar-remove    # Remove tasks
/sugar-status    # System health
/sugar-priority  # Change priority
/sugar-run       # Start autonomous mode

# Memory System
/sugar-remember  # Store learnings, decisions, preferences
/sugar-recall    # Search memory for relevant context
/sugar-context   # Load full project context

Using Memory Commands

Store important context with /sugar-remember:

# Store a preference
/sugar-remember "Always use async/await in this project"

# Store a decision
/sugar-remember "Using PostgreSQL for ACID compliance"

# Store an error pattern
/sugar-remember "Login loop bug was caused by missing return statement"

Search memory with /sugar-recall:

# Search for context
/sugar-recall "authentication"

# Get project context at session start
/sugar-context

# The AI will search Sugar's memory and return relevant information

MCP Tools

The integration exposes these MCP tools that OpenCode can call programmatically:

# Task Tools (from sugar-tasks MCP server)
sugar_add_task      # Add a task to the queue
sugar_list_tasks    # List tasks with filtering
sugar_view_task     # Get task details
sugar_update_task   # Update task properties
sugar_remove_task   # Remove a task
sugar_task_status   # Get queue statistics

# Memory Tools (from sugar-memory MCP server)
search_memory       # Search for relevant memories
store_learning      # Store new memories
recall              # Get formatted context about a topic
get_project_context # Get full project context
list_recent_memories # Browse recent entries

Configuration

Optional settings in .sugar/config.yaml:

integrations:
  opencode:
    enabled: true
    server_url: "http://localhost:4096"
    timeout: 30.0

    # Auto-injection settings
    auto_inject: true
    inject_memory_types:
      - decision
      - preference
      - error_pattern
    memory_limit: 5

    # Notification settings
    notify_on_completion: true
    notify_on_failure: true

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Sugar       β”‚                    β”‚    OpenCode     β”‚
β”‚                 β”‚                    β”‚                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚       MCP          β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚sugar-tasks│◄─┼────────────────────┼─►│  Session  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   stdio transport  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚                    β”‚                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚       MCP          β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚sugar-memory│◄┼────────────────────┼─►│   Tools   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   stdio transport  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚                    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Sugar provides two MCP servers that OpenCode connects to via stdio transport. This gives OpenCode full access to Sugar's task queue and memory system.

Comparison with Claude Code

Feature Claude Code OpenCode
Integration method MCP Server MCP Server
Setup command claude mcp add sugar sugar opencode setup
Slash commands 11 commands 11 commands
Memory access Full (MCP tools) Full (MCP tools)
Task management Full (MCP tools) Full (MCP tools)

Both integrations provide equivalent functionality via MCP servers.

Troubleshooting

"Could not find OpenCode config file"

Create the config directory and file:

mkdir -p ~/.config/opencode
echo '{"$schema": "https://opencode.ai/config.json"}' > ~/.config/opencode/opencode.json
sugar opencode setup

"Sugar MCP servers already configured"

The setup command is idempotent - this means it already worked! Restart OpenCode to load the servers.

Commands not appearing in OpenCode

  1. Run sugar opencode setup to verify configuration
  2. Restart OpenCode completely (not just the session)
  3. Check that the MCP servers are listed in your OpenCode config

Memory commands not working

  1. Ensure you have memories stored: sugar memories
  2. Initialize Sugar in your project: sugar init
  3. Check that sugar-memory MCP server is configured

Learn More