migrate-v1.mdx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. ---
  2. title: "Migrate from V1"
  3. description: "Move from OpenCode V1 to the OpenCode 2.0 beta."
  4. ---
  5. <Callout type="note">
  6. OpenCode 1 and OpenCode 2 can be installed side by side. V1 runs as `opencode`, while V2 installs and runs separately
  7. as `opencode2`.
  8. </Callout>
  9. ## Breaking changes
  10. V2 has three intentional breaking changes:
  11. - [Plugins](#plugins) use a new plugin API.
  12. - The [server API and clients](#server-api-and-clients) have new contracts.
  13. - [TUI configuration](#tui-configuration) moves from layered `tui.json(c)` files to one global `cli.json` file (auto migrated).
  14. Supported V1 functionality outside those areas is intended to remain compatible with V1. Some fields accepted by the V1
  15. schema never had a V2 equivalent and are intentionally ignored; these are listed under
  16. [Accepted but unsupported fields](#accepted-but-unsupported-fields).
  17. Existing supported server config fields, agent definitions, command definitions, skills, and other files in `.opencode/`
  18. should continue to work without changes. If supported behavior described in this guide stops working in V2, treat it as a
  19. beta compatibility bug rather than an expected migration requirement.
  20. <Callout type="tip">
  21. Run `/report` if supported V1 functionality does not work in V2. The report skill collects diagnostics and helps you
  22. file a compatibility issue.
  23. </Callout>
  24. <Callout type="warning">
  25. OpenCode 2.0 is in beta. Beta data may be wiped, features may break unintentionally, and the server and plugin APIs
  26. may continue to change.
  27. </Callout>
  28. ## Install the beta
  29. Install the beta from the `next` distribution tag:
  30. ```bash
  31. npm install -g @opencode-ai/cli@next
  32. ```
  33. Start it in your project with:
  34. ```bash
  35. opencode2
  36. ```
  37. ## Configuration
  38. This section covers both JSON/JSONC configuration and file-based definitions under `.opencode/`.
  39. ### Use your existing configuration
  40. V2 reads existing global and project configuration from the same locations as V1:
  41. ```text
  42. ~/.config/opencode/opencode.json(c)
  43. <project>/opencode.json(c)
  44. <project>/.opencode/opencode.json(c)
  45. ```
  46. V2 reads these same locations. It normalizes supported V1 and native V2 fields in memory without rewriting the source
  47. file. Existing supported V1 configuration is intended to keep working, so you do not need to convert it to try or adopt
  48. V2.
  49. ### Ask OpenCode to migrate
  50. The V1 config format remains supported. The native V2 format is optional and makes several settings more explicit and
  51. ergonomic.
  52. The recommended migration path is to ask OpenCode to update the configuration for you:
  53. ```text
  54. Migrate my OpenCode configuration, including file-based definitions, from the V1 format to the native V2 format.
  55. Preserve its behavior and all unrelated settings.
  56. ```
  57. OpenCode can inspect the complete file, apply the relevant changes below, and avoid rewriting settings that do not need to
  58. change. Conversion does not need to happen all at once: supported V1 and native V2 fields may coexist at the top level.
  59. When both forms set the same canonical value, a valid native V2 value takes precedence regardless of JSON key order.
  60. Nested mixing is intentionally bounded. OpenCode recognizes mixed V1 and V2 members within `mcp`, `compaction`, and
  61. `experimental`, but it does not recursively infer formats inside individual agents, providers, commands, or models. Keep
  62. each of those nested entries entirely in one format. Supported V1 syntax remains quiet by itself; malformed values,
  63. unsupported legacy fields, and conflicting V1/V2 values produce warnings while unrelated valid settings continue to load.
  64. ### Sharing
  65. The deprecated V1 `autoshare` boolean becomes the explicit `share` policy:
  66. ```jsonc
  67. // V1
  68. { "autoshare": true }
  69. // V2
  70. { "share": "auto" }
  71. ```
  72. Use `"manual"`, `"auto"`, or `"disabled"`. If the V1 file already uses `share`, no change is needed.
  73. ### Permissions and tools
  74. V1 groups permission effects by tool. V2 uses one ordered `permissions` array, making precedence and exceptions explicit:
  75. ```jsonc
  76. // V1
  77. {
  78. "permission": {
  79. "bash": {
  80. "git push *": "ask"
  81. },
  82. "edit": "allow"
  83. },
  84. "tools": {
  85. "websearch": false
  86. }
  87. }
  88. // V2
  89. {
  90. "permissions": [
  91. { "action": "shell", "resource": "git push *", "effect": "ask" },
  92. { "action": "edit", "resource": "*", "effect": "allow" },
  93. { "action": "websearch", "resource": "*", "effect": "deny" }
  94. ]
  95. }
  96. ```
  97. Permission actions also changed: `bash` is now `shell`, `task` is now `subagent`, and `write` and `patch` are now `edit`.
  98. See [Permissions](/permissions) for the ordered V2 rule format.
  99. ### Agents and modes
  100. The singular `agent` and deprecated `mode` maps become `agents`. Agent fields become more consistent with the rest of the
  101. V2 config:
  102. ```jsonc
  103. // V1
  104. {
  105. "agent": {
  106. "reviewer": {
  107. "prompt": "Review for correctness and missing tests.",
  108. "model": "anthropic/claude-sonnet-4-5",
  109. "variant": "high",
  110. "disable": false,
  111. "permission": {
  112. "edit": "deny"
  113. }
  114. }
  115. }
  116. }
  117. // V2
  118. {
  119. "agents": {
  120. "reviewer": {
  121. "system": "Review for correctness and missing tests.",
  122. "model": "anthropic/claude-sonnet-4-5#high",
  123. "disabled": false,
  124. "permissions": [
  125. { "action": "edit", "resource": "*", "effect": "deny" }
  126. ]
  127. }
  128. }
  129. }
  130. ```
  131. `prompt` becomes `system`, `disable` becomes `disabled`, and a separate `variant` joins the model reference after `#`.
  132. `temperature`, `top_p`, and provider-specific `options` move under `request.body`. `maxSteps` becomes `steps`. Entries from
  133. the old `mode` map become primary agents.
  134. ### Snapshots
  135. Rename the singular `snapshot` field to `snapshots`. Its boolean value does not change:
  136. ```jsonc
  137. // V1
  138. { "snapshot": false }
  139. // V2
  140. { "snapshots": false }
  141. ```
  142. ### Media
  143. Rename the singular `attachment` object to `media`. Nested image settings keep the same names:
  144. ```jsonc
  145. // V1
  146. { "attachment": { "image": { "auto_resize": true } } }
  147. // V2
  148. { "media": { "image": { "auto_resize": true } } }
  149. ```
  150. ### MCP servers
  151. V2 groups servers under `mcp.servers`, replaces `enabled` with the inverse `disabled`, and separates timeout purposes:
  152. ```jsonc
  153. // V1
  154. {
  155. "mcp": {
  156. "playwright": {
  157. "type": "local",
  158. "command": ["npx", "@playwright/mcp"],
  159. "enabled": true,
  160. "timeout": 30000
  161. }
  162. }
  163. }
  164. // V2
  165. {
  166. "mcp": {
  167. "servers": {
  168. "playwright": {
  169. "type": "local",
  170. "command": ["npx", "@playwright/mcp"],
  171. "disabled": false,
  172. "timeout": {
  173. "catalog": 30000,
  174. "execution": 30000
  175. }
  176. }
  177. }
  178. }
  179. }
  180. ```
  181. Remote OAuth fields use snake case: `clientId` becomes `client_id`, `clientSecret` becomes `client_secret`,
  182. `callbackPort` becomes `callback_port`, and `redirectUri` becomes `redirect_uri`. The V1 `experimental.mcp_timeout` value
  183. also becomes the default `mcp.timeout.catalog` and `mcp.timeout.execution` values. See [MCP servers](/mcp-servers).
  184. ### Compaction
  185. V2 groups the retained-context token budget under `keep` and gives the reserve a clearer name:
  186. ```jsonc
  187. // V1
  188. {
  189. "compaction": {
  190. "preserve_recent_tokens": 8000,
  191. "reserved": 20000
  192. }
  193. }
  194. // V2
  195. {
  196. "compaction": {
  197. "keep": {
  198. "tokens": 8000
  199. },
  200. "buffer": 20000
  201. }
  202. }
  203. ```
  204. `auto` keeps its name. V2 has no native `tail_turns` or `prune` field; both legacy fields are ignored with a warning. Recent
  205. context is retained by token budget instead. See [Compaction](/compaction).
  206. ### Skills
  207. V1 separates extra skill paths and URLs. V2 combines both into one ordered array:
  208. ```jsonc
  209. // V1
  210. {
  211. "skills": {
  212. "paths": ["./team-skills"],
  213. "urls": ["https://example.com/skills/"]
  214. }
  215. }
  216. // V2
  217. {
  218. "skills": ["./team-skills", "https://example.com/skills/"]
  219. }
  220. ```
  221. Existing skill files and automatic `.opencode/skills/` discovery do not change. See [Skills](/skills).
  222. ### Commands
  223. Rename the singular `command` map to `commands`. Join a separate model `variant` to the model reference:
  224. ```jsonc
  225. // V1
  226. {
  227. "command": {
  228. "review": {
  229. "template": "Review the current changes.",
  230. "model": "anthropic/claude-sonnet-4-5",
  231. "variant": "high"
  232. }
  233. }
  234. }
  235. // V2
  236. {
  237. "commands": {
  238. "review": {
  239. "template": "Review the current changes.",
  240. "model": "anthropic/claude-sonnet-4-5#high"
  241. }
  242. }
  243. }
  244. ```
  245. `template`, `description`, `agent`, and `subtask` keep their names. Existing Markdown command definitions remain supported.
  246. See [Commands](/commands).
  247. ### References
  248. Rename the deprecated singular `reference` map to `references`:
  249. ```jsonc
  250. // V1
  251. { "reference": { "docs": "../docs" } }
  252. // V2
  253. { "references": { "docs": "../docs" } }
  254. ```
  255. V1 already accepts `references`, so no change is needed when the file uses it. Reference entries keep the
  256. same shapes. See [References](/references).
  257. ### Providers
  258. Rename the singular `provider` map to `providers`. V2 separates the runtime package, endpoint, and request settings:
  259. ```jsonc
  260. // V1
  261. {
  262. "provider": {
  263. "acme": {
  264. "npm": "@ai-sdk/openai-compatible",
  265. "api": "https://llm.example.com/v1",
  266. "options": {
  267. "apiKey": "{env:ACME_API_KEY}"
  268. }
  269. }
  270. }
  271. }
  272. // V2
  273. {
  274. "providers": {
  275. "acme": {
  276. "package": "aisdk:@ai-sdk/openai-compatible",
  277. "settings": {
  278. "baseURL": "https://llm.example.com/v1",
  279. "apiKey": "{env:ACME_API_KEY}"
  280. }
  281. }
  282. }
  283. }
  284. ```
  285. V1 `npm` becomes `package`, and AI SDK packages receive the `aisdk:` prefix. `api` becomes `settings.baseURL`. Provider
  286. `options` are separated into `settings`, `headers`, and `body` according to their request role. See [Providers](/providers).
  287. V2 consolidated two legacy provider namespaces:
  288. | V1 provider ID | Canonical V2 provider ID |
  289. | -------------------------- | ------------------------ |
  290. | `azure-cognitive-services` | `azure` |
  291. | `google-vertex-anthropic` | `google-vertex` |
  292. Migration of unambiguous V1 provider, agent, command, and provider-filter fields uses these canonical IDs. The shared
  293. top-level `model` field keeps its exact provider ID because the same syntax is valid in native V2 config; update that field
  294. to the canonical ID when migrating a legacy built-in provider.
  295. ### Models and variants
  296. Models remain nested under their provider, but several model fields become more explicit:
  297. - `id` becomes `modelID`.
  298. - `tool_call` and `modalities` become `capabilities.tools`, `capabilities.input`, and `capabilities.output`.
  299. - A `status` of `"deprecated"` becomes `disabled: true`.
  300. - Cache costs move from `cache_read` and `cache_write` to `cache.read` and `cache.write`.
  301. - Provider-specific `options` become `settings`.
  302. - A V1 variants object becomes a V2 array with an `id` on each entry.
  303. ```jsonc
  304. // V1
  305. {
  306. "variants": {
  307. "high": {
  308. "reasoningEffort": "high"
  309. }
  310. }
  311. }
  312. // V2
  313. {
  314. "variants": [
  315. {
  316. "id": "high",
  317. "settings": {
  318. "reasoningEffort": "high"
  319. }
  320. }
  321. ]
  322. }
  323. ```
  324. See [Models](/models) for the complete native model shape.
  325. ### Supported fields without direct native equivalents
  326. Most fields that keep the same shape, including `shell`, `model`, `default_agent`, `autoupdate`, `watcher`, `formatter`,
  327. `lsp`, `instructions`, `enterprise`, and `tool_output`, require no migration.
  328. The V1 provider filters do not have one-to-one native V2 config fields, but their behavior remains supported:
  329. - `enabled_providers` becomes an internal deny-by-default provider policy followed by allows for the listed providers.
  330. - `disabled_providers` becomes internal deny policies for the listed providers.
  331. - `small_model` becomes the `model` selection for the built-in `title` agent. Native V2 configuration should use
  332. `agents.title.model` instead.
  333. You may keep these fields in V1 syntax. OpenCode normalizes them without warning.
  334. ### Accepted but unsupported fields
  335. The V1 schema also accepted fields that have no supported V2 behavior. V2 ignores these values and emits a warning so
  336. they are not mistaken for active configuration:
  337. - `logLevel`: use `OPENCODE_LOG_LEVEL` when starting OpenCode.
  338. - `server`: use the V2 service and explicit server options; the server API is an intentional breaking change.
  339. - `layout`: remove it; V1 already treated it as deprecated and always used stretch layout.
  340. - Top-level `subagent_depth`: use `experimental.subagent_depth` instead.
  341. - `compaction.tail_turns` and `compaction.prune`: V2 uses `compaction.keep.tokens` and checkpoint-based compaction instead.
  342. - Agent `name` inside V1 JSON configuration.
  343. - An enabled-only V1 MCP entry without a `type`.
  344. - V1 experimental fields `disable_paste_summary`, `batch_tool`, `openTelemetry`, `primary_tools`, and
  345. `continue_loop_on_deny`.
  346. - V1 provider fields `id`, `whitelist`, and `blacklist`.
  347. - V1 provider-model fields `release_date`, `attachment`, `reasoning`, `temperature`, `experimental`, a non-`deprecated`
  348. `status`, and boolean `interleaved`.
  349. Ignoring these fields is intentional and is not a compatibility regression. If V2 does not preserve behavior identified
  350. as supported elsewhere in this guide, run `/report`.
  351. ### Agent files
  352. V1 agent files may use `agent/`, `agents/`, `mode/`, or `modes/`. V2 still discovers all four directories. The preferred
  353. V2 location is:
  354. ```text
  355. .opencode/agents/<name>.md
  356. ```
  357. Files under a V1 `mode/` or `modes/` directory represent primary agents. When moving one into `agents/`, add
  358. `mode: primary` to its frontmatter. Files under `agent/` can move to `agents/` without changing their path-derived ID.
  359. When converting the frontmatter to native V2 fields:
  360. - Keep the Markdown body as the agent's system instructions.
  361. - Rename `prompt` to `system` when it appears in JSON configuration; file bodies do not need a `system` field.
  362. - Rename `disable` to `disabled` and `permission` to `permissions`.
  363. - Join `model` and `variant` as `provider/model#variant`.
  364. - Move `temperature`, `top_p`, and provider-specific options under `request.body`.
  365. V2 translates legacy agent frontmatter automatically, so these edits are optional. See [Agents](/agents).
  366. ### Command files
  367. V1 command files may use `command/` or `commands/`. V2 discovers both. The preferred location is:
  368. ```text
  369. .opencode/commands/<name>.md
  370. ```
  371. Move files from `command/` to the same relative path under `commands/` to preserve command names. The Markdown body remains
  372. the command template, and `description`, `agent`, and `subtask` frontmatter keep the same names. If frontmatter has separate
  373. `model` and `variant` fields, append the variant to the model and remove `variant`:
  374. ```yaml
  375. # V1
  376. model: anthropic/claude-sonnet-4-5
  377. variant: high
  378. # V2
  379. model: anthropic/claude-sonnet-4-5#high
  380. ```
  381. See [Commands](/commands).
  382. ### Skill files
  383. V2 discovers skills from both `.opencode/skill/` and `.opencode/skills/`. The preferred layout is:
  384. ```text
  385. .opencode/skills/<skill-id>/SKILL.md
  386. ```
  387. Move the complete skill directory, not only `SKILL.md`, so relative scripts, references, and other supporting files remain
  388. available. Keep the directory name stable to preserve the skill ID. Existing skill frontmatter and Markdown bodies do not
  389. require a V2 rewrite. See [Skills](/skills).
  390. ### Instruction files
  391. Existing `AGENTS.md` files stay in place. V2 discovers the global `~/.config/opencode/AGENTS.md` and project `AGENTS.md`
  392. files from the current directory up to the project root.
  393. If a V1 setup relied on a `CLAUDE.md` fallback, move that guidance into the applicable `AGENTS.md`. V2 currently only
  394. discovers `AGENTS.md`; because non-API V1 behavior is intended to remain compatible, also run `/report` with the affected
  395. project details. See [Instructions](/instructions).
  396. ## TUI configuration
  397. V1 loaded `tui.json(c)` from the global config directory and from project directories discovered while walking up from
  398. the current directory. V2 instead stores CLI and TUI settings in one global file:
  399. ```text
  400. ~/.config/opencode/cli.json
  401. ```
  402. The CLI owns this file. The background service does not load it, and V2 does not discover or merge project-local
  403. `tui.json(c)` or `cli.json` files.
  404. The native V2 format groups related settings. For example:
  405. ```jsonc
  406. // V1: ~/.config/opencode/tui.json
  407. {
  408. "theme": "tokyonight",
  409. "scroll_speed": 2,
  410. "scroll_acceleration": {
  411. "enabled": true
  412. }
  413. }
  414. // V2: ~/.config/opencode/cli.json
  415. {
  416. "theme": {
  417. "name": "tokyonight"
  418. },
  419. "scroll": {
  420. "speed": 2,
  421. "acceleration": true
  422. }
  423. }
  424. ```
  425. V2 migrates the global TUI configuration automatically. On the first CLI or TUI startup, when `cli.json` does not already
  426. exist, it:
  427. - Reads `~/.config/opencode/tui.json`.
  428. - Reads persisted TUI preferences from the legacy `kv.json` state file.
  429. - Converts supported settings to the native grouped format and writes `~/.config/opencode/cli.json`.
  430. - Leaves the V1 files unchanged so V1 can continue using them.
  431. Migration runs only while `cli.json` is absent. Once that file exists, V2 treats it as the source of truth and does not
  432. continually synchronize later changes from `tui.json` or `kv.json`. If you created `cli.json` before starting V2, merge any
  433. V1 settings you still need into it manually.
  434. Project-local V1 TUI configuration is not migrated because V2 has no project-local CLI configuration. Move settings you
  435. still want into the global `cli.json`; when multiple projects used different values for the same setting, choose the
  436. global behavior you want V2 to use.
  437. ## Plugins
  438. Rename `plugin` to `plugins`. Replace a package-and-options tuple with an object:
  439. ```jsonc
  440. // V1
  441. {
  442. "plugin": [
  443. "opencode-example-plugin",
  444. ["./plugin/local.ts", { "enabled": true }]
  445. ]
  446. }
  447. // V2
  448. {
  449. "plugins": [
  450. "opencode-example-plugin",
  451. {
  452. "package": "./plugin/local.ts",
  453. "options": { "enabled": true }
  454. }
  455. ]
  456. }
  457. ```
  458. V2 discovers local plugins from both `.opencode/plugin/` and `.opencode/plugins/`; use `.opencode/plugins/` for V2 files.
  459. Moving a file between these directories does not migrate its implementation.
  460. <Callout type="warning">V1 plugins will not work in V2.</Callout>
  461. The config entry can be translated automatically, but plugin implementation code must be ported to the new API. The V2
  462. plugin API is still being finalized during beta, and detailed plugin migration guidance will be published when it is
  463. ready.
  464. Once the V2 plugin API is finalized, OpenCode should be able to migrate the majority of V1 plugins while keeping related
  465. local modules and dependencies together. See the current beta [Plugins guide](/build/plugins).
  466. ## Server API and clients
  467. OpenCode 2 has a revised, more ergonomic server API and a new set of clients. Integrations that call the V1 server API
  468. must migrate to the V2 API.
  469. Use the `@opencode-ai/client` package to access the new clients. The server API and clients are still being finalized
  470. during beta, so their contracts may continue to change. See the generated [API reference](/api) for the current endpoints,
  471. request types, and responses.
  472. ## Verify your setup
  473. Start `opencode2` in a project and verify your model, provider credentials, agents, permissions, MCP servers, and plugins
  474. before relying on the beta for regular work. Keep your V1 setup until you have confirmed the V2 behavior you need, and do
  475. not point V1 at configuration that you have converted to the native V2 shape.