Back to Everything Claude Code

Migration Guide: Claude Code to OpenCode

.opencode/MIGRATION.md

1.10.011.0 KB
Original Source

Migration Guide: Claude Code to OpenCode

This guide helps you migrate from Claude Code to OpenCode while using the Everything Claude Code (ECC) configuration.

Overview

OpenCode is an alternative CLI for AI-assisted development that supports all the same features as Claude Code, with some differences in configuration format.

Key Differences

FeatureClaude CodeOpenCodeNotes
ConfigurationCLAUDE.md, plugin.jsonopencode.jsonDifferent file formats
AgentsMarkdown frontmatterJSON objectFull parity
Commandscommands/*.mdcommand object or .md filesFull parity
Skillsskills/*/SKILL.mdinstructions arrayLoaded as context
Hookshooks.json (3 phases)Plugin system (20+ events)Full parity + more!
Rulesrules/*.mdinstructions arrayConsolidated or separate
MCPFull supportFull supportFull parity

Hook Migration

OpenCode fully supports hooks via its plugin system, which is actually MORE sophisticated than Claude Code with 20+ event types.

Hook Event Mapping

Claude Code HookOpenCode Plugin EventNotes
PreToolUsetool.execute.beforeCan modify tool input
PostToolUsetool.execute.afterCan modify tool output
Stopsession.idle or session.statusSession lifecycle
SessionStartsession.createdSession begins
SessionEndsession.deletedSession ends
N/Afile.editedOpenCode-only: file changes
N/Afile.watcher.updatedOpenCode-only: file system watch
N/Amessage.updatedOpenCode-only: message changes
N/Alsp.client.diagnosticsOpenCode-only: LSP integration
N/Atui.toast.showOpenCode-only: notifications

Converting Hooks to Plugins

Claude Code hook (hooks.json):

json
{
  "PostToolUse": [{
    "matcher": "tool == \"Edit\" && tool_input.file_path matches \"\\\\.(ts|tsx|js|jsx)$\"",
    "hooks": [{
      "type": "command",
      "command": "prettier --write \"$file_path\""
    }]
  }]
}

OpenCode plugin (.opencode/plugins/prettier-hook.ts):

typescript
export const PrettierPlugin = async ({ $ }) => {
  return {
    "file.edited": async (event) => {
      if (event.path.match(/\.(ts|tsx|js|jsx)$/)) {
        await $`prettier --write ${event.path}`
      }
    }
  }
}

ECC Plugin Hooks Included

The ECC OpenCode configuration includes translated hooks:

HookOpenCode EventPurpose
Prettier auto-formatfile.editedFormat JS/TS files after edit
TypeScript checktool.execute.afterRun tsc after editing .ts files
console.log warningfile.editedWarn about console.log statements
Session notificationsession.idleNotify when task completes
Security checktool.execute.beforeCheck for secrets before commit

Migration Steps

1. Install OpenCode

bash
# Install OpenCode CLI
npm install -g opencode
# or
curl -fsSL https://opencode.ai/install | bash

2. Use the ECC OpenCode Configuration

The .opencode/ directory in this repository contains the translated configuration:

.opencode/
├── opencode.json              # Main configuration
├── plugins/                   # Hook plugins (translated from hooks.json)
│   ├── ecc-hooks.ts           # All ECC hooks as plugins
│   └── index.ts               # Plugin exports
├── tools/                     # Custom tools
│   ├── run-tests.ts           # Run test suite
│   ├── check-coverage.ts      # Check coverage
│   └── security-audit.ts      # npm audit wrapper
├── commands/                  # All 23 commands (markdown)
│   ├── plan.md
│   ├── tdd.md
│   └── ... (21 more)
├── prompts/
│   └── agents/                # Agent prompt files (12)
├── instructions/
│   └── INSTRUCTIONS.md        # Consolidated rules
├── package.json               # For npm distribution
├── tsconfig.json              # TypeScript config
└── MIGRATION.md               # This file

3. Run OpenCode

bash
# In the repository root
opencode

# The configuration is automatically detected from .opencode/opencode.json

Concept Mapping

Agents

Claude Code:

markdown
---
name: planner
description: Expert planning specialist...
tools: ["Read", "Grep", "Glob"]
model: opus
---

You are an expert planning specialist...

OpenCode:

json
{
  "agent": {
    "planner": {
      "description": "Expert planning specialist...",
      "mode": "subagent",
      "model": "anthropic/claude-opus-4-5",
      "prompt": "{file:prompts/agents/planner.txt}",
      "tools": { "read": true, "bash": true }
    }
  }
}

Commands

Claude Code:

markdown
---
name: plan
description: Create implementation plan
---

Create a detailed implementation plan for: {input}

OpenCode (JSON):

json
{
  "command": {
    "plan": {
      "description": "Create implementation plan",
      "template": "Create a detailed implementation plan for: $ARGUMENTS",
      "agent": "planner"
    }
  }
}

OpenCode (Markdown - .opencode/commands/plan.md):

markdown
---
description: Create implementation plan
agent: planner
---

Create a detailed implementation plan for: $ARGUMENTS

Skills

Claude Code: Skills are loaded from skills/*/SKILL.md files.

OpenCode: Skills are added to the instructions array:

json
{
  "instructions": [
    "skills/tdd-workflow/SKILL.md",
    "skills/security-review/SKILL.md",
    "skills/coding-standards/SKILL.md"
  ]
}

Rules

Claude Code: Rules are in separate rules/*.md files.

OpenCode: Rules can be consolidated into instructions or kept separate:

json
{
  "instructions": [
    "instructions/INSTRUCTIONS.md",
    "rules/common/security.md",
    "rules/common/coding-style.md"
  ]
}

Model Mapping

Claude CodeOpenCode
opusanthropic/claude-opus-4-5
sonnetanthropic/claude-sonnet-4-5
haikuanthropic/claude-haiku-4-5

Available Commands

After migration, ALL 23 commands are available:

CommandDescription
/planCreate implementation plan
/tddEnforce TDD workflow
/code-reviewReview code changes
/securityRun security review
/build-fixFix build errors
/e2eGenerate E2E tests
/refactor-cleanRemove dead code
/orchestrateMulti-agent workflow
/learnExtract patterns mid-session
/checkpointSave verification state
/verifyRun verification loop
/evalRun evaluation
/update-docsUpdate documentation
/update-codemapsUpdate codemaps
/test-coverageCheck test coverage
/setup-pmConfigure package manager
/go-reviewGo code review
/go-testGo TDD workflow
/go-buildFix Go build errors
/skill-createGenerate skills from git history
/instinct-statusView learned instincts
/instinct-importImport instincts
/instinct-exportExport instincts
/evolveCluster instincts into skills
/promotePromote project instincts to global scope
/projectsList known projects and instinct stats

Available Agents

AgentDescription
plannerImplementation planning
architectSystem design
code-reviewerCode review
security-reviewerSecurity analysis
tdd-guideTest-driven development
build-error-resolverFix build errors
e2e-runnerE2E testing
doc-updaterDocumentation
refactor-cleanerDead code cleanup
go-reviewerGo code review
go-build-resolverGo build errors
database-reviewerDatabase optimization

Plugin Installation

Option 1: Use ECC Configuration Directly

The .opencode/ directory contains everything pre-configured.

Option 2: Install as npm Package

bash
npm install ecc-universal

Then in your opencode.json:

json
{
  "plugin": ["ecc-universal"]
}

This only loads the published ECC OpenCode plugin module (hooks/events and exported plugin tools). It does not automatically inject ECC's full agent, command, or instructions config into your project.

If you want the full ECC OpenCode workflow surface, use the repository's bundled .opencode/opencode.json as your base config or copy these pieces into your project:

  • .opencode/commands/
  • .opencode/prompts/
  • .opencode/instructions/INSTRUCTIONS.md
  • the agent and command sections from .opencode/opencode.json

Troubleshooting

Configuration Not Loading

  1. Verify .opencode/opencode.json exists in the repository root
  2. Check JSON syntax is valid: cat .opencode/opencode.json | jq .
  3. Ensure all referenced prompt files exist

Plugin Not Loading

  1. Verify plugin file exists in .opencode/plugins/
  2. Check TypeScript syntax is valid
  3. Ensure plugin array in opencode.json includes the path

Agent Not Found

  1. Check the agent is defined in opencode.json under the agent object
  2. Verify the prompt file path is correct
  3. Ensure the prompt file exists at the specified path

Command Not Working

  1. Verify the command is defined in opencode.json or as .md file in .opencode/commands/
  2. Check the referenced agent exists
  3. Ensure the template uses $ARGUMENTS for user input
  4. If you installed only plugin: ["ecc-universal"], note that npm plugin install does not auto-add ECC commands or agents to your project config

Best Practices

  1. Start Fresh: Don't try to run both Claude Code and OpenCode simultaneously
  2. Check Configuration: Verify opencode.json loads without errors
  3. Test Commands: Run each command once to verify it works
  4. Use Plugins: Leverage the plugin hooks for automation
  5. Use Agents: Leverage the specialized agents for their intended purposes

Reverting to Claude Code

If you need to switch back:

  1. Simply run claude instead of opencode
  2. Claude Code will use its own configuration (CLAUDE.md, plugin.json, etc.)
  3. The .opencode/ directory won't interfere with Claude Code

Feature Parity Summary

FeatureClaude CodeOpenCodeStatus
AgentsPASS: 12 agentsPASS: 12 agentsFull parity
CommandsPASS: 23 commandsPASS: 23 commandsFull parity
SkillsPASS: 16 skillsPASS: 16 skillsFull parity
HooksPASS: 3 phasesPASS: 20+ eventsOpenCode has MORE
RulesPASS: 8 rulesPASS: 8 rulesFull parity
MCP ServersPASS: FullPASS: FullFull parity
Custom ToolsPASS: Via hooksPASS: Native supportOpenCode is better

Feedback

For issues specific to: