mdcontext 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/.changeset/README.md +28 -0
  2. package/.changeset/config.json +11 -0
  3. package/.claude/settings.local.json +25 -0
  4. package/.github/workflows/ci.yml +83 -0
  5. package/.github/workflows/claude-code-review.yml +44 -0
  6. package/.github/workflows/claude.yml +85 -0
  7. package/.github/workflows/release.yml +113 -0
  8. package/.tldrignore +112 -0
  9. package/BACKLOG.md +338 -0
  10. package/CONTRIBUTING.md +186 -0
  11. package/NOTES/NOTES +44 -0
  12. package/README.md +434 -11
  13. package/biome.json +36 -0
  14. package/cspell.config.yaml +14 -0
  15. package/dist/chunk-23UPXDNL.js +3044 -0
  16. package/dist/chunk-2W7MO2DL.js +1366 -0
  17. package/dist/chunk-3NUAZGMA.js +1689 -0
  18. package/dist/chunk-7TOWB2XB.js +366 -0
  19. package/dist/chunk-7XOTOADQ.js +3065 -0
  20. package/dist/chunk-AH2PDM2K.js +3042 -0
  21. package/dist/chunk-BNXWSZ63.js +3742 -0
  22. package/dist/chunk-BTL5DJVU.js +3222 -0
  23. package/dist/chunk-HDHYG7E4.js +104 -0
  24. package/dist/chunk-HLR4KZBP.js +3234 -0
  25. package/dist/chunk-IP3FRFEB.js +1045 -0
  26. package/dist/chunk-KHU56VDO.js +3042 -0
  27. package/dist/chunk-KRYIFLQR.js +88 -0
  28. package/dist/chunk-LBSDNLEM.js +287 -0
  29. package/dist/chunk-MNTQ7HCP.js +2643 -0
  30. package/dist/chunk-MUJELQQ6.js +1387 -0
  31. package/dist/chunk-MXJGMSLV.js +2199 -0
  32. package/dist/chunk-N6QJGC3Z.js +2636 -0
  33. package/dist/chunk-OBELGBPM.js +1713 -0
  34. package/dist/chunk-OT7R5XTA.js +3192 -0
  35. package/dist/chunk-P7X4RA2T.js +106 -0
  36. package/dist/chunk-PIDUQNC2.js +3185 -0
  37. package/dist/chunk-POGCDIH4.js +3187 -0
  38. package/dist/chunk-PSIEOQGZ.js +3043 -0
  39. package/dist/chunk-PVRT3IHA.js +3238 -0
  40. package/dist/chunk-QNN4TT23.js +1430 -0
  41. package/dist/chunk-RE3R45RJ.js +3042 -0
  42. package/dist/chunk-S7E6TFX6.js +803 -0
  43. package/dist/chunk-SG6GLU4U.js +1378 -0
  44. package/dist/chunk-SJCDV2ST.js +274 -0
  45. package/dist/chunk-SYE5XLF3.js +104 -0
  46. package/dist/chunk-T5VLYBZD.js +103 -0
  47. package/dist/chunk-TOQB7VWU.js +3238 -0
  48. package/dist/chunk-VFNMZ4ZQ.js +3228 -0
  49. package/dist/chunk-VVTGZNBT.js +1629 -0
  50. package/dist/chunk-W7Q4RFEV.js +104 -0
  51. package/dist/chunk-XTYYVRLO.js +3190 -0
  52. package/dist/chunk-Y6MDYVJD.js +3063 -0
  53. package/dist/cli/main.d.ts +1 -0
  54. package/dist/cli/main.js +5458 -0
  55. package/dist/index.d.ts +653 -0
  56. package/dist/index.js +79 -0
  57. package/dist/mcp/server.d.ts +1 -0
  58. package/dist/mcp/server.js +472 -0
  59. package/dist/schema-BAWSG7KY.js +22 -0
  60. package/dist/schema-E3QUPL26.js +20 -0
  61. package/dist/schema-EHL7WUT6.js +20 -0
  62. package/docs/019-USAGE.md +625 -0
  63. package/docs/020-current-implementation.md +364 -0
  64. package/docs/021-DOGFOODING-FINDINGS.md +175 -0
  65. package/docs/BACKLOG.md +80 -0
  66. package/docs/CONFIG.md +1123 -0
  67. package/docs/DESIGN.md +439 -0
  68. package/docs/ERRORS.md +383 -0
  69. package/docs/PROJECT.md +88 -0
  70. package/docs/ROADMAP.md +407 -0
  71. package/docs/summarization.md +320 -0
  72. package/docs/test-links.md +9 -0
  73. package/justfile +40 -0
  74. package/package.json +74 -9
  75. package/pnpm-workspace.yaml +5 -0
  76. package/research/INDEX.md +315 -0
  77. package/research/code-review/README.md +90 -0
  78. package/research/code-review/cli-error-handling-review.md +979 -0
  79. package/research/code-review/code-review-validation-report.md +464 -0
  80. package/research/code-review/main-ts-review.md +1128 -0
  81. package/research/config-analysis/01-current-implementation.md +470 -0
  82. package/research/config-analysis/02-strategy-recommendation.md +428 -0
  83. package/research/config-analysis/03-task-candidates.md +715 -0
  84. package/research/config-analysis/033-research-configuration-management.md +828 -0
  85. package/research/config-analysis/034-research-effect-cli-config.md +1504 -0
  86. package/research/config-analysis/04-consolidated-task-candidates.md +277 -0
  87. package/research/config-docs/SUMMARY.md +357 -0
  88. package/research/config-docs/TEST-RESULTS.md +776 -0
  89. package/research/config-docs/TODO.md +542 -0
  90. package/research/config-docs/analysis.md +744 -0
  91. package/research/config-docs/fix-validation.md +502 -0
  92. package/research/config-docs/help-audit.md +264 -0
  93. package/research/config-docs/help-system-analysis.md +890 -0
  94. package/research/dogfood/consolidated-tool-evaluation.md +373 -0
  95. package/research/dogfood/strategy-a/a-synthesis.md +184 -0
  96. package/research/dogfood/strategy-a/a1-docs.md +226 -0
  97. package/research/dogfood/strategy-a/a2-amorphic.md +156 -0
  98. package/research/dogfood/strategy-a/a3-llm.md +164 -0
  99. package/research/dogfood/strategy-b/b-synthesis.md +228 -0
  100. package/research/dogfood/strategy-b/b1-architecture.md +207 -0
  101. package/research/dogfood/strategy-b/b2-gaps.md +258 -0
  102. package/research/dogfood/strategy-b/b3-workflows.md +250 -0
  103. package/research/dogfood/strategy-c/c-synthesis.md +451 -0
  104. package/research/dogfood/strategy-c/c1-explorer.md +192 -0
  105. package/research/dogfood/strategy-c/c2-diver-memory.md +145 -0
  106. package/research/dogfood/strategy-c/c3-diver-control.md +148 -0
  107. package/research/dogfood/strategy-c/c4-diver-failure.md +151 -0
  108. package/research/dogfood/strategy-c/c5-diver-execution.md +221 -0
  109. package/research/dogfood/strategy-c/c6-diver-org.md +221 -0
  110. package/research/effect-cli-error-handling.md +845 -0
  111. package/research/effect-errors-as-values.md +943 -0
  112. package/research/errors-task-analysis/00-consolidated-tasks.md +207 -0
  113. package/research/errors-task-analysis/cli-commands-analysis.md +909 -0
  114. package/research/errors-task-analysis/embeddings-analysis.md +709 -0
  115. package/research/errors-task-analysis/index-search-analysis.md +812 -0
  116. package/research/frontmatter/COMMENTS-ARE-SKIPPED.md +149 -0
  117. package/research/frontmatter/LLM-CODE-NAVIGATION.md +276 -0
  118. package/research/issue-review.md +603 -0
  119. package/research/llm-summarization/agent-cli-tools-2026.md +1082 -0
  120. package/research/llm-summarization/alternative-providers-2026.md +1428 -0
  121. package/research/llm-summarization/anthropic-2026.md +367 -0
  122. package/research/llm-summarization/claude-cli-integration.md +1706 -0
  123. package/research/llm-summarization/cli-integration-patterns.md +3155 -0
  124. package/research/llm-summarization/openai-2026.md +473 -0
  125. package/research/llm-summarization/openai-compatible-providers-2026.md +1022 -0
  126. package/research/llm-summarization/opencode-cli-integration.md +1552 -0
  127. package/research/llm-summarization/prompt-engineering-2026.md +1426 -0
  128. package/research/llm-summarization/prototype-results.md +56 -0
  129. package/research/llm-summarization/provider-switching-patterns-2026.md +2153 -0
  130. package/research/llm-summarization/typescript-llm-libraries-2026.md +2436 -0
  131. package/research/mdcontext-error-analysis.md +521 -0
  132. package/research/mdcontext-pudding/00-EXECUTIVE-SUMMARY.md +282 -0
  133. package/research/mdcontext-pudding/01-index-embed.md +956 -0
  134. package/research/mdcontext-pudding/02-search-COMMANDS.md +142 -0
  135. package/research/mdcontext-pudding/02-search-SUMMARY.md +146 -0
  136. package/research/mdcontext-pudding/02-search.md +970 -0
  137. package/research/mdcontext-pudding/03-context.md +779 -0
  138. package/research/mdcontext-pudding/04-navigation-and-analytics.md +803 -0
  139. package/research/mdcontext-pudding/04-tree.md +704 -0
  140. package/research/mdcontext-pudding/05-config.md +1038 -0
  141. package/research/mdcontext-pudding/06-links-summary.txt +87 -0
  142. package/research/mdcontext-pudding/06-links.md +679 -0
  143. package/research/mdcontext-pudding/07-stats.md +693 -0
  144. package/research/mdcontext-pudding/BUG-FIX-PLAN.md +388 -0
  145. package/research/mdcontext-pudding/P0-BUG-VALIDATION.md +167 -0
  146. package/research/mdcontext-pudding/README.md +168 -0
  147. package/research/mdcontext-pudding/TESTING-SUMMARY.md +128 -0
  148. package/research/npm_publish/011-npm-workflow-research-agent2.md +792 -0
  149. package/research/npm_publish/012-npm-workflow-research-agent1.md +530 -0
  150. package/research/npm_publish/013-npm-workflow-research-agent3.md +722 -0
  151. package/research/npm_publish/014-npm-workflow-synthesis.md +556 -0
  152. package/research/npm_publish/031-npm-workflow-task-analysis.md +134 -0
  153. package/research/research-quality-review.md +834 -0
  154. package/research/semantic-search/002-research-embedding-models.md +490 -0
  155. package/research/semantic-search/003-research-rag-alternatives.md +523 -0
  156. package/research/semantic-search/004-research-vector-search.md +841 -0
  157. package/research/semantic-search/032-research-semantic-search.md +427 -0
  158. package/research/semantic-search/embedding-text-analysis.md +156 -0
  159. package/research/semantic-search/multi-word-failure-reproduction.md +171 -0
  160. package/research/semantic-search/query-processing-analysis.md +207 -0
  161. package/research/semantic-search/root-cause-and-solution.md +114 -0
  162. package/research/semantic-search/threshold-validation-report.md +69 -0
  163. package/research/semantic-search/vector-search-analysis.md +63 -0
  164. package/research/task-management-2026/00-synthesis-recommendations.md +295 -0
  165. package/research/task-management-2026/01-ai-workflow-tools.md +416 -0
  166. package/research/task-management-2026/02-agent-framework-patterns.md +476 -0
  167. package/research/task-management-2026/03-lightweight-file-based.md +567 -0
  168. package/research/task-management-2026/04-established-tools-ai-features.md +541 -0
  169. package/research/task-management-2026/linear/01-core-features-workflow.md +771 -0
  170. package/research/task-management-2026/linear/02-api-integrations.md +930 -0
  171. package/research/task-management-2026/linear/03-ai-features.md +368 -0
  172. package/research/task-management-2026/linear/04-pricing-setup.md +205 -0
  173. package/research/task-management-2026/linear/05-usage-patterns-best-practices.md +605 -0
  174. package/research/test-path-issues.md +276 -0
  175. package/review/ALP-76/1-error-type-design.md +962 -0
  176. package/review/ALP-76/2-error-handling-patterns.md +906 -0
  177. package/review/ALP-76/3-error-presentation.md +624 -0
  178. package/review/ALP-76/4-test-coverage.md +625 -0
  179. package/review/ALP-76/5-migration-completeness.md +440 -0
  180. package/review/ALP-76/6-effect-best-practices.md +755 -0
  181. package/scripts/apply-branch-protection.sh +47 -0
  182. package/scripts/branch-protection-templates.json +79 -0
  183. package/scripts/prototype-summarization.ts +346 -0
  184. package/scripts/rebuild-hnswlib.js +58 -0
  185. package/scripts/setup-branch-protection.sh +64 -0
  186. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/active-provider.json +7 -0
  187. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.json +541 -0
  188. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.meta.json +5 -0
  189. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/config.json +8 -0
  190. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
  191. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
  192. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/documents.json +60 -0
  193. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/links.json +13 -0
  194. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/sections.json +1197 -0
  195. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/configuration-management.md +99 -0
  196. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/distributed-systems.md +92 -0
  197. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/error-handling.md +78 -0
  198. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/failure-automation.md +55 -0
  199. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/job-context.md +69 -0
  200. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/process-orchestration.md +99 -0
  201. package/src/cli/argv-preprocessor.test.ts +210 -0
  202. package/src/cli/argv-preprocessor.ts +202 -0
  203. package/src/cli/cli.test.ts +627 -0
  204. package/src/cli/commands/backlinks.ts +54 -0
  205. package/src/cli/commands/config-cmd.ts +642 -0
  206. package/src/cli/commands/context.ts +285 -0
  207. package/src/cli/commands/duplicates.ts +122 -0
  208. package/src/cli/commands/embeddings.ts +529 -0
  209. package/src/cli/commands/index-cmd.ts +480 -0
  210. package/src/cli/commands/index.ts +16 -0
  211. package/src/cli/commands/links.ts +52 -0
  212. package/src/cli/commands/search.ts +1281 -0
  213. package/src/cli/commands/stats.ts +149 -0
  214. package/src/cli/commands/tree.ts +128 -0
  215. package/src/cli/config-layer.ts +176 -0
  216. package/src/cli/error-handler.test.ts +235 -0
  217. package/src/cli/error-handler.ts +655 -0
  218. package/src/cli/flag-schemas.ts +341 -0
  219. package/src/cli/help.ts +588 -0
  220. package/src/cli/index.ts +9 -0
  221. package/src/cli/main.ts +435 -0
  222. package/src/cli/options.ts +41 -0
  223. package/src/cli/shared-error-handling.ts +199 -0
  224. package/src/cli/typo-suggester.test.ts +105 -0
  225. package/src/cli/typo-suggester.ts +130 -0
  226. package/src/cli/utils.ts +259 -0
  227. package/src/config/file-provider.test.ts +320 -0
  228. package/src/config/file-provider.ts +273 -0
  229. package/src/config/index.ts +72 -0
  230. package/src/config/integration.test.ts +667 -0
  231. package/src/config/precedence.test.ts +277 -0
  232. package/src/config/precedence.ts +451 -0
  233. package/src/config/schema.test.ts +414 -0
  234. package/src/config/schema.ts +603 -0
  235. package/src/config/service.test.ts +320 -0
  236. package/src/config/service.ts +243 -0
  237. package/src/config/testing.test.ts +264 -0
  238. package/src/config/testing.ts +110 -0
  239. package/src/core/index.ts +1 -0
  240. package/src/core/types.ts +113 -0
  241. package/src/duplicates/detector.test.ts +183 -0
  242. package/src/duplicates/detector.ts +414 -0
  243. package/src/duplicates/index.ts +18 -0
  244. package/src/embeddings/embedding-namespace.test.ts +300 -0
  245. package/src/embeddings/embedding-namespace.ts +947 -0
  246. package/src/embeddings/heading-boost.test.ts +222 -0
  247. package/src/embeddings/hnsw-build-options.test.ts +198 -0
  248. package/src/embeddings/hyde.test.ts +272 -0
  249. package/src/embeddings/hyde.ts +264 -0
  250. package/src/embeddings/index.ts +10 -0
  251. package/src/embeddings/openai-provider.ts +414 -0
  252. package/src/embeddings/pricing.json +22 -0
  253. package/src/embeddings/provider-constants.ts +204 -0
  254. package/src/embeddings/provider-errors.test.ts +967 -0
  255. package/src/embeddings/provider-errors.ts +565 -0
  256. package/src/embeddings/provider-factory.test.ts +240 -0
  257. package/src/embeddings/provider-factory.ts +225 -0
  258. package/src/embeddings/provider-integration.test.ts +788 -0
  259. package/src/embeddings/query-preprocessing.test.ts +187 -0
  260. package/src/embeddings/semantic-search-threshold.test.ts +508 -0
  261. package/src/embeddings/semantic-search.ts +1270 -0
  262. package/src/embeddings/types.ts +359 -0
  263. package/src/embeddings/vector-store.ts +708 -0
  264. package/src/embeddings/voyage-provider.ts +313 -0
  265. package/src/errors/errors.test.ts +845 -0
  266. package/src/errors/index.ts +533 -0
  267. package/src/index/ignore-patterns.test.ts +354 -0
  268. package/src/index/ignore-patterns.ts +305 -0
  269. package/src/index/index.ts +4 -0
  270. package/src/index/indexer.ts +684 -0
  271. package/src/index/storage.ts +260 -0
  272. package/src/index/types.ts +147 -0
  273. package/src/index/watcher.ts +189 -0
  274. package/src/index.ts +30 -0
  275. package/src/integration/search-keyword.test.ts +678 -0
  276. package/src/mcp/server.ts +612 -0
  277. package/src/parser/index.ts +1 -0
  278. package/src/parser/parser.test.ts +291 -0
  279. package/src/parser/parser.ts +394 -0
  280. package/src/parser/section-filter.test.ts +277 -0
  281. package/src/parser/section-filter.ts +392 -0
  282. package/src/search/__tests__/hybrid-search.test.ts +650 -0
  283. package/src/search/bm25-store.ts +366 -0
  284. package/src/search/cross-encoder.test.ts +253 -0
  285. package/src/search/cross-encoder.ts +406 -0
  286. package/src/search/fuzzy-search.test.ts +419 -0
  287. package/src/search/fuzzy-search.ts +273 -0
  288. package/src/search/hybrid-search.ts +448 -0
  289. package/src/search/path-matcher.test.ts +276 -0
  290. package/src/search/path-matcher.ts +33 -0
  291. package/src/search/query-parser.test.ts +260 -0
  292. package/src/search/query-parser.ts +319 -0
  293. package/src/search/searcher.test.ts +280 -0
  294. package/src/search/searcher.ts +724 -0
  295. package/src/search/wink-bm25.d.ts +30 -0
  296. package/src/summarization/cli-providers/claude.ts +202 -0
  297. package/src/summarization/cli-providers/detection.test.ts +273 -0
  298. package/src/summarization/cli-providers/detection.ts +118 -0
  299. package/src/summarization/cli-providers/index.ts +8 -0
  300. package/src/summarization/cost.test.ts +139 -0
  301. package/src/summarization/cost.ts +102 -0
  302. package/src/summarization/error-handler.test.ts +127 -0
  303. package/src/summarization/error-handler.ts +111 -0
  304. package/src/summarization/index.ts +102 -0
  305. package/src/summarization/pipeline.test.ts +498 -0
  306. package/src/summarization/pipeline.ts +231 -0
  307. package/src/summarization/prompts.test.ts +269 -0
  308. package/src/summarization/prompts.ts +133 -0
  309. package/src/summarization/provider-factory.test.ts +396 -0
  310. package/src/summarization/provider-factory.ts +178 -0
  311. package/src/summarization/types.ts +184 -0
  312. package/src/summarize/budget-bugs.test.ts +620 -0
  313. package/src/summarize/formatters.ts +419 -0
  314. package/src/summarize/index.ts +20 -0
  315. package/src/summarize/summarizer.test.ts +275 -0
  316. package/src/summarize/summarizer.ts +597 -0
  317. package/src/summarize/verify-bugs.test.ts +238 -0
  318. package/src/types/huggingface-transformers.d.ts +66 -0
  319. package/src/utils/index.ts +1 -0
  320. package/src/utils/tokens.test.ts +142 -0
  321. package/src/utils/tokens.ts +186 -0
  322. package/tests/fixtures/cli/.mdcontext/active-provider.json +7 -0
  323. package/tests/fixtures/cli/.mdcontext/config.json +8 -0
  324. package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
  325. package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
  326. package/tests/fixtures/cli/.mdcontext/indexes/documents.json +33 -0
  327. package/tests/fixtures/cli/.mdcontext/indexes/links.json +12 -0
  328. package/tests/fixtures/cli/.mdcontext/indexes/sections.json +247 -0
  329. package/tests/fixtures/cli/README.md +9 -0
  330. package/tests/fixtures/cli/api-reference.md +11 -0
  331. package/tests/fixtures/cli/getting-started.md +11 -0
  332. package/tests/integration/embed-index.test.ts +712 -0
  333. package/tests/integration/search-context.test.ts +469 -0
  334. package/tests/integration/search-semantic.test.ts +522 -0
  335. package/tsconfig.json +26 -0
  336. package/vitest.config.ts +16 -0
  337. package/vitest.setup.ts +12 -0
@@ -0,0 +1,1552 @@
1
+ # OpenCode CLI Integration Research
2
+
3
+ **Research Date:** 2026-01-26
4
+ **Purpose:** Evaluate OpenCode CLI for non-interactive programmatic usage in mdcontext
5
+ **Status:** Complete
6
+
7
+ ## Executive Summary
8
+
9
+ OpenCode CLI is a Go-based, open-source AI coding agent supporting 75+ LLM providers with robust non-interactive capabilities. It offers flexible provider selection, local-first privacy, and comprehensive CLI automation features. While it matches Claude CLI's output quality when using the same models, it lacks some advanced features like Claude's parallel subagent system and exclusive access to Opus 4.5.
10
+
11
+ **Key Verdict:** OpenCode is viable for mdcontext integration with caveats around timeout management and JSON output format documentation.
12
+
13
+ ---
14
+
15
+ ## 1. Non-Interactive Command Syntax
16
+
17
+ ### Primary Command Structure
18
+
19
+ ```bash
20
+ opencode run [message..]
21
+ ```
22
+
23
+ The `run` command executes OpenCode in non-interactive mode, processing the prompt and exiting.
24
+
25
+ ### Complete Flag Reference
26
+
27
+ | Flag | Short | Type | Purpose |
28
+ |------|-------|------|---------|
29
+ | `--command` | - | string | Specify custom command with arguments |
30
+ | `--continue` | `-c` | boolean | Resume previous session |
31
+ | `--session` | `-s` | string | Continue specific session by ID |
32
+ | `--model` | `-m` | string | Select model (format: provider/model) |
33
+ | `--agent` | - | string | Choose specific agent |
34
+ | `--file` | `-f` | path | Attach file(s) to message |
35
+ | `--format` | - | enum | Output format: "default" or "json" |
36
+ | `--title` | - | string | Custom session title |
37
+ | `--attach` | - | URL | Connect to running server (e.g., http://localhost:4096) |
38
+ | `--port` | - | number | Local server port (random default) |
39
+ | `--share` | - | boolean | Share the session |
40
+ | `--quiet` | `-q` | boolean | Suppress spinner animation |
41
+ | `--timeout` | - | number | Custom timeout in milliseconds (default: 120000) |
42
+ | `--print-logs` | - | boolean | Print logs to stderr |
43
+ | `--log-level` | - | enum | DEBUG, INFO, WARN, ERROR |
44
+ | `--cwd` | `-c` | path | Override working directory |
45
+ | `--debug` | `-d` | boolean | Enable debug mode |
46
+
47
+ ### Additional Global Flags
48
+
49
+ ```bash
50
+ opencode [global flags] [command]
51
+ --refresh # Update cached model list
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 2. Passing Prompts Without Interactive Mode
57
+
58
+ ### Direct Prompt Syntax
59
+
60
+ ```bash
61
+ # Basic usage
62
+ opencode run "Explain the use of context in Go"
63
+
64
+ # Legacy syntax (deprecated but still works)
65
+ opencode -p "Your prompt here"
66
+ ```
67
+
68
+ ### Context Injection Mechanisms
69
+
70
+ #### File Attachment with @
71
+
72
+ ```bash
73
+ opencode run "Review the component in @src/components/Button.tsx"
74
+ opencode run "Compare @file1.ts and @file2.ts"
75
+ ```
76
+
77
+ **Behavior:** File content is automatically included in the prompt.
78
+
79
+ #### Command Output Injection with !
80
+
81
+ ```bash
82
+ opencode run "Analyze the git status: !git status"
83
+ opencode run "Review test failures: !npm test"
84
+ ```
85
+
86
+ **Behavior:** Commands run in project root directory; output becomes part of prompt.
87
+
88
+ ### Model Selection
89
+
90
+ ```bash
91
+ # Specify model inline
92
+ opencode run -m anthropic/claude-sonnet-4-20250514 "Your prompt"
93
+
94
+ # Or via config
95
+ opencode run --model openai/gpt-4.1 "Your prompt"
96
+ ```
97
+
98
+ **Format:** `provider/model-id`
99
+
100
+ ### Session Continuation
101
+
102
+ ```bash
103
+ # Continue last session
104
+ opencode run -c "Follow-up question"
105
+
106
+ # Continue specific session
107
+ opencode run -s session-uuid "Follow-up question"
108
+ ```
109
+
110
+ ---
111
+
112
+ ## 3. Output Format
113
+
114
+ ### Default Output
115
+
116
+ **Mode:** Formatted text stream to stdout
117
+ **Behavior:** Real-time streaming with optional spinner animation
118
+
119
+ ```bash
120
+ opencode run "What is Go context?"
121
+ # Output: Formatted markdown-style response
122
+ ```
123
+
124
+ ### JSON Output
125
+
126
+ **Mode:** Structured JSON events
127
+ **Activation:** `--format json` flag
128
+
129
+ ```bash
130
+ opencode run --format json "Your prompt"
131
+ ```
132
+
133
+ #### JSON Schema Status
134
+
135
+ **Critical Gap:** Official JSON output schema is NOT documented. Search results confirm JSON format exists but provide no structure examples.
136
+
137
+ **Known Information:**
138
+ - Output appears to be event-based (SSE-style JSON events)
139
+ - Each event likely contains message chunks and metadata
140
+ - No official schema at `https://opencode.ai/docs/` as of Jan 2026
141
+
142
+ **Recommendation:** Requires empirical testing or source code inspection to determine exact format.
143
+
144
+ ### Quiet Mode
145
+
146
+ ```bash
147
+ opencode run -q "Your prompt"
148
+ opencode run --format json -q "Your prompt" # Useful for scripting
149
+ ```
150
+
151
+ **Effect:** Disables spinner animation; critical for CI/CD pipelines.
152
+
153
+ ### Output Separation
154
+
155
+ **Stdout:** Agent responses and primary output
156
+ **Stderr:** Diagnostic information, logs (with `--print-logs`)
157
+
158
+ **Benefit:** CI/CD systems can capture streams separately.
159
+
160
+ ---
161
+
162
+ ## 4. Error Handling
163
+
164
+ ### Exit Codes
165
+
166
+ | Code | Meaning |
167
+ |------|---------|
168
+ | 0 | Success |
169
+ | 1 | Error/failure |
170
+ | Interrupted | Standard Unix interrupt codes |
171
+
172
+ **Source:** Standard Unix conventions; confirmed via error handling analysis.
173
+
174
+ ### Stderr Messages
175
+
176
+ ```bash
177
+ opencode run --print-logs --log-level ERROR "Your prompt" 2>errors.log
178
+ ```
179
+
180
+ **Behavior:**
181
+ - Errors formatted via `FormatError()` before display
182
+ - Detailed error information written to log files in `~/.local/share/opencode/logs/`
183
+ - Log format: timestamp-based (e.g., `2025-01-09T123456.log`)
184
+ - Auto-cleanup: keeps only 10 most recent log files
185
+
186
+ ### Known Error Handling Issues
187
+
188
+ #### Configuration Errors at Startup
189
+
190
+ **Issue:** TUI becomes unresponsive when config errors occur
191
+ **Workaround:** Validate config before launching
192
+ **Tracking:** [Issue #4245](https://github.com/sst/opencode/issues/4245)
193
+
194
+ #### Hanging on Certain Errors
195
+
196
+ **Issue:** `opencode run` hangs instead of exiting on certain errors
197
+ **Workaround:** Use timeout wrapper scripts
198
+ **Tracking:** [Issue #4506](https://github.com/sst/opencode/issues/4506)
199
+
200
+ #### Interactive Command Timeouts
201
+
202
+ **Issue:** Commands requiring interactive input (e.g., `npm create vite`) timeout
203
+ **Impact:** Cannot handle setup wizards
204
+ **Tracking:** [Issue #1656](https://github.com/sst/opencode/issues/1656)
205
+
206
+ ### Timeout Behavior
207
+
208
+ **Default:** 120,000ms (2 minutes)
209
+ **Customization:**
210
+
211
+ ```bash
212
+ # Command-line
213
+ opencode run --timeout 600000 "Long-running task"
214
+
215
+ # Config file
216
+ {
217
+ "timeout": 600000
218
+ }
219
+ ```
220
+
221
+ **Context:** Applies to bash command execution, not LLM response time.
222
+
223
+ ---
224
+
225
+ ## 5. Authentication & API Keys
226
+
227
+ ### Configuration Methods
228
+
229
+ #### 1. Interactive Setup (Recommended)
230
+
231
+ ```bash
232
+ opencode auth login
233
+ # Follow prompts to add provider credentials
234
+ ```
235
+
236
+ **Storage:** `~/.local/share/opencode/auth.json`
237
+
238
+ #### 2. Environment Variables
239
+
240
+ ```bash
241
+ # Anthropic
242
+ export ANTHROPIC_API_KEY="sk-ant-..."
243
+
244
+ # OpenAI
245
+ export OPENAI_API_KEY="sk-..."
246
+
247
+ # Google Gemini
248
+ export GEMINI_API_KEY="..."
249
+
250
+ # AWS Bedrock
251
+ export AWS_ACCESS_KEY_ID="..."
252
+ export AWS_SECRET_ACCESS_KEY="..."
253
+ export AWS_REGION="us-east-1"
254
+
255
+ # Azure OpenAI
256
+ export AZURE_OPENAI_ENDPOINT="..."
257
+ export AZURE_OPENAI_API_KEY="..."
258
+
259
+ # GitHub Copilot
260
+ export GITHUB_TOKEN="ghp_..."
261
+
262
+ # Self-hosted (OpenAI-compatible)
263
+ export LOCAL_ENDPOINT="http://localhost:11434/v1"
264
+ ```
265
+
266
+ #### 3. Config File References
267
+
268
+ ```json
269
+ {
270
+ "provider": {
271
+ "anthropic": {
272
+ "options": {
273
+ "apiKey": "{env:ANTHROPIC_API_KEY}"
274
+ }
275
+ }
276
+ }
277
+ }
278
+ ```
279
+
280
+ **Syntax:** `{env:VAR_NAME}` for environment variable substitution
281
+
282
+ ### List Authenticated Providers
283
+
284
+ ```bash
285
+ opencode auth list
286
+ ```
287
+
288
+ ### Logout from Provider
289
+
290
+ ```bash
291
+ opencode auth logout [provider-name]
292
+ ```
293
+
294
+ ### Error Handling
295
+
296
+ **Missing API Key:**
297
+ - Exit code 1
298
+ - Stderr message indicating missing credentials
299
+ - Prompts to run `opencode auth login`
300
+
301
+ **Invalid API Key:**
302
+ - Forwarded error from provider API
303
+ - Exit code 1
304
+ - Detailed error in logs
305
+
306
+ ---
307
+
308
+ ## 6. Provider Selection
309
+
310
+ ### Supported Providers (75+)
311
+
312
+ #### Major Providers
313
+
314
+ | Provider | Models | Notes |
315
+ |----------|--------|-------|
316
+ | **Anthropic** | Claude 3.5, Claude 4, Claude 3.7 Sonnet | Primary provider |
317
+ | **OpenAI** | GPT-4.1, GPT-4.5, GPT-4o, O1, O3 | Full family support |
318
+ | **Google** | Gemini 2.0, 2.5 variants | Native integration |
319
+ | **AWS Bedrock** | Claude 3.7 Sonnet | Requires AWS credentials |
320
+ | **Groq** | Llama, Deepseek | High-speed inference |
321
+ | **Azure OpenAI** | Same as OpenAI | Enterprise support |
322
+ | **GitHub Copilot** | GPT, Claude, Gemini access | Experimental |
323
+ | **Local/Self-hosted** | Any OpenAI-compatible | Via `LOCAL_ENDPOINT` |
324
+
325
+ #### Full Provider List
326
+
327
+ Access via:
328
+ ```bash
329
+ opencode models
330
+ opencode models --refresh # Update cached list
331
+ ```
332
+
333
+ ### Provider Configuration Syntax
334
+
335
+ #### Basic Setup
336
+
337
+ ```json
338
+ {
339
+ "provider": {
340
+ "anthropic": {
341
+ "options": {
342
+ "baseURL": "https://api.anthropic.com/v1",
343
+ "apiKey": "{env:ANTHROPIC_API_KEY}"
344
+ }
345
+ }
346
+ }
347
+ }
348
+ ```
349
+
350
+ #### Custom OpenAI-Compatible Provider
351
+
352
+ ```json
353
+ {
354
+ "provider": {
355
+ "myprovider": {
356
+ "npm": "@ai-sdk/openai-compatible",
357
+ "name": "My Custom Provider",
358
+ "options": {
359
+ "baseURL": "https://api.example.com/v1",
360
+ "apiKey": "{env:CUSTOM_API_KEY}"
361
+ },
362
+ "models": {
363
+ "custom-model-id": {
364
+ "name": "Custom Model Name",
365
+ "limit": {
366
+ "context": 200000,
367
+ "output": 65536
368
+ }
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+ ```
375
+
376
+ ### Provider Selection in Non-Interactive Mode
377
+
378
+ ```bash
379
+ # Via model flag (provider/model format)
380
+ opencode run -m anthropic/claude-sonnet-4-20250514 "Your prompt"
381
+ opencode run -m openai/gpt-4.1 "Your prompt"
382
+ opencode run -m google/gemini-2.5-flash "Your prompt"
383
+
384
+ # Via config file default
385
+ {
386
+ "model": "anthropic/claude-sonnet-4-20250514"
387
+ }
388
+ ```
389
+
390
+ ### OpenCode Zen (Curated List)
391
+
392
+ **Purpose:** Pre-tested, verified models optimized for OpenCode
393
+ **Authentication:** Via `opencode.ai/auth`
394
+ **Access:** Displayed in `/models` command
395
+
396
+ ---
397
+
398
+ ## 7. Model Selection
399
+
400
+ ### Command Syntax
401
+
402
+ ```bash
403
+ # List available models
404
+ opencode models
405
+
406
+ # List models for specific provider
407
+ opencode models anthropic
408
+ opencode models openai
409
+
410
+ # Refresh cached model list
411
+ opencode models --refresh
412
+ ```
413
+
414
+ ### Model Selection Methods
415
+
416
+ #### 1. Command-Line Flag
417
+
418
+ ```bash
419
+ opencode run -m anthropic/claude-sonnet-4-20250514 "Your prompt"
420
+ ```
421
+
422
+ #### 2. Config File Default
423
+
424
+ ```json
425
+ {
426
+ "model": "anthropic/claude-sonnet-4-20250514"
427
+ }
428
+ ```
429
+
430
+ #### 3. Custom Command Override
431
+
432
+ ```markdown
433
+ ---
434
+ description: Run tests with coverage
435
+ model: anthropic/claude-3-5-sonnet-20241022
436
+ ---
437
+ Run the full test suite...
438
+ ```
439
+
440
+ #### 4. Agent-Specific Model
441
+
442
+ ```json
443
+ {
444
+ "agents": {
445
+ "coder": {
446
+ "model": "claude-3.7-sonnet"
447
+ }
448
+ }
449
+ }
450
+ ```
451
+
452
+ ### Model Naming Format
453
+
454
+ **Standard:** `provider/model-id`
455
+ **Examples:**
456
+ - `anthropic/claude-sonnet-4-20250514`
457
+ - `openai/gpt-4.1`
458
+ - `google/gemini-2.5-flash`
459
+ - `groq/llama-3.1-70b`
460
+
461
+ ### Model Context Limits
462
+
463
+ Configured per model:
464
+
465
+ ```json
466
+ {
467
+ "provider": {
468
+ "custom": {
469
+ "models": {
470
+ "model-id": {
471
+ "limit": {
472
+ "context": 200000,
473
+ "output": 65536
474
+ }
475
+ }
476
+ }
477
+ }
478
+ }
479
+ }
480
+ ```
481
+
482
+ **Auto-compaction:** Sessions auto-compress at 95% context utilization.
483
+
484
+ ---
485
+
486
+ ## 8. Session Management
487
+
488
+ ### Session Persistence
489
+
490
+ **Architecture:** Stateful with SQLite backend
491
+ **Storage:** `~/.local/share/opencode/sessions.db`
492
+
493
+ **Features:**
494
+ - Message history preservation
495
+ - Token usage tracking
496
+ - Cost accounting per session
497
+ - Auto-summarization at context limits
498
+
499
+ ### Session Commands
500
+
501
+ ```bash
502
+ # List all sessions
503
+ opencode session list
504
+
505
+ # Export session to JSON
506
+ opencode export [sessionID]
507
+
508
+ # Import session from JSON or share URL
509
+ opencode import <file>
510
+ opencode import <share-url>
511
+
512
+ # View token usage statistics
513
+ opencode stats
514
+ ```
515
+
516
+ ### Continuation in Non-Interactive Mode
517
+
518
+ #### Resume Last Session
519
+
520
+ ```bash
521
+ opencode run -c "Follow-up question"
522
+ opencode run --continue "Follow-up question"
523
+ ```
524
+
525
+ **Behavior:** Loads previous conversation context.
526
+
527
+ #### Resume Specific Session
528
+
529
+ ```bash
530
+ opencode run -s <session-id> "Follow-up question"
531
+ opencode run --session <session-id> "Follow-up question"
532
+ ```
533
+
534
+ ### Stateless vs Stateful Behavior
535
+
536
+ **Default Mode:** Stateful
537
+ - Each `opencode run` creates/continues a session
538
+ - Context preserved between invocations with `-c` or `-s`
539
+
540
+ **Pseudo-Stateless Workaround:**
541
+ ```bash
542
+ # New session each time (no continuation flags)
543
+ opencode run "Independent question"
544
+ ```
545
+
546
+ **True Stateless:** Not explicitly supported; sessions always created.
547
+
548
+ ### Session Sharing
549
+
550
+ ```bash
551
+ # Enable sharing for session
552
+ opencode run --share "Your prompt"
553
+ ```
554
+
555
+ **Output:** Shareable URL for session export.
556
+
557
+ ### Context Compaction
558
+
559
+ **Trigger:** 95% context window utilization
560
+ **Mechanism:** `SummaryMessageID` field links to summary message
561
+ **Result:** Prior conversation summarized; token usage reduced
562
+
563
+ ---
564
+
565
+ ## 9. Context/File Passing
566
+
567
+ ### File Attachment Methods
568
+
569
+ #### 1. Direct File Reference (@syntax)
570
+
571
+ ```bash
572
+ opencode run "Review @src/App.tsx for bugs"
573
+ opencode run "Compare @package.json and @package-lock.json"
574
+ ```
575
+
576
+ **Behavior:**
577
+ - File content injected into prompt
578
+ - Supports multiple files
579
+ - Paths relative to working directory
580
+
581
+ #### 2. Command-Line Flag
582
+
583
+ ```bash
584
+ opencode run --file src/App.tsx "Review this file"
585
+ opencode run -f src/App.tsx -f src/utils.ts "Review these files"
586
+ ```
587
+
588
+ **Capability:** Multiple `-f` flags supported.
589
+
590
+ #### 3. Command Output Injection (!syntax)
591
+
592
+ ```bash
593
+ opencode run "Analyze git status: !git status"
594
+ opencode run "Review failing tests: !npm test 2>&1"
595
+ ```
596
+
597
+ **Behavior:**
598
+ - Commands executed in project root
599
+ - Stdout/stderr captured and injected into prompt
600
+
601
+ ### Working Directory Control
602
+
603
+ ```bash
604
+ # Override working directory
605
+ opencode run -c /path/to/project "Your prompt"
606
+ opencode run --cwd /path/to/project "Your prompt"
607
+ ```
608
+
609
+ **Default:** Current working directory.
610
+
611
+ ### Built-in Context Tools
612
+
613
+ When running in agent mode (default behavior), OpenCode provides:
614
+
615
+ | Tool | Purpose |
616
+ |------|---------|
617
+ | `glob` | File pattern matching |
618
+ | `grep` | Content search |
619
+ | `ls` | Directory listing |
620
+ | `view` | Read file contents |
621
+ | `write` | Create/overwrite files |
622
+ | `edit` | Modify existing files |
623
+ | `patch` | Apply diffs |
624
+ | `bash` | Execute shell commands |
625
+ | `diagnostics` | LSP-based code intelligence |
626
+ | `fetch` | HTTP requests |
627
+ | `sourcegraph` | Public code search |
628
+
629
+ **Impact:** AI can autonomously gather context without explicit file passing.
630
+
631
+ ---
632
+
633
+ ## 10. Streaming vs Non-Streaming
634
+
635
+ ### Interactive (TUI) Mode
636
+
637
+ **Architecture:** Real-time streaming via Server-Sent Events (SSE)
638
+
639
+ ```bash
640
+ opencode serve
641
+ # Exposes HTTP endpoint at http://localhost:4096
642
+ # SSE endpoint: http://localhost:4096/sse
643
+ ```
644
+
645
+ **Behavior:**
646
+ - Results persisted and broadcast to event bus in real-time
647
+ - TUI receives updates as they occur
648
+ - Any HTTP client subscribed to `/sse` can stream events
649
+
650
+ ### Non-Interactive Mode
651
+
652
+ **Architecture:** Batch processing with optional progress indicator
653
+
654
+ ```bash
655
+ # With spinner (default)
656
+ opencode run "Your prompt"
657
+
658
+ # Silent mode (no spinner)
659
+ opencode run -q "Your prompt"
660
+ opencode run --quiet "Your prompt"
661
+ ```
662
+
663
+ **Output Behavior:**
664
+ - AI processes entire prompt
665
+ - Final result printed to stdout after completion
666
+ - No intermediate streaming to terminal
667
+
668
+ ### Server-Attached Workflow
669
+
670
+ **Purpose:** Reduce cold-start times; maintain persistent backend
671
+
672
+ ```bash
673
+ # Terminal 1: Start server
674
+ opencode serve
675
+
676
+ # Terminal 2: Attach to server for fast responses
677
+ opencode run --attach http://localhost:4096 "Your prompt"
678
+ ```
679
+
680
+ **Benefit:** Server maintains loaded models and context; faster response times.
681
+
682
+ ### JSON Format Streaming
683
+
684
+ ```bash
685
+ opencode run --format json "Your prompt"
686
+ ```
687
+
688
+ **Expected Behavior:** JSON events (likely nd-JSON or SSE-style)
689
+ **Documentation Gap:** Exact streaming format undocumented.
690
+
691
+ ---
692
+
693
+ ## 11. Privacy Features
694
+
695
+ ### Local-First Architecture
696
+
697
+ **Core Principle:** Code never leaves your machine except via direct API calls to configured providers.
698
+
699
+ **Data Flow:**
700
+ 1. User prompt → OpenCode CLI (local)
701
+ 2. OpenCode → AI Provider API (direct HTTPS)
702
+ 3. AI response → OpenCode CLI (local)
703
+ 4. Results stored locally in SQLite
704
+
705
+ ### Data Storage Locations
706
+
707
+ | Data Type | Path |
708
+ |-----------|------|
709
+ | Sessions/conversations | `~/.local/share/opencode/sessions.db` |
710
+ | Authentication credentials | `~/.local/share/opencode/auth.json` |
711
+ | Logs | `~/.local/share/opencode/logs/` |
712
+ | Config | `~/.config/opencode/opencode.json` |
713
+ | Custom commands | `~/.config/opencode/commands/` |
714
+
715
+ **All data remains on local filesystem.**
716
+
717
+ ### Privacy with Local Models
718
+
719
+ When using self-hosted/local LLMs:
720
+
721
+ ```bash
722
+ export LOCAL_ENDPOINT="http://localhost:11434/v1"
723
+ opencode run -m local/llama-3.1-70b "Your prompt"
724
+ ```
725
+
726
+ **Maximum Privacy:** Code and data never leave your machine.
727
+
728
+ ### Enterprise Privacy
729
+
730
+ **Feature:** Central config and SSO integration
731
+ **Benefit:** Data remains within organization's infrastructure
732
+ **Documentation:** See `https://opencode.ai/docs/enterprise/`
733
+
734
+ ### Privacy Plugin: opencode-openmemory
735
+
736
+ **Repository:** `https://github.com/happycastle114/opencode-openmemory`
737
+ **Purpose:** Local-first, privacy-focused persistent memory for OpenCode agents
738
+ **Architecture:** Uses OpenMemory for local memory storage
739
+
740
+ ### Privacy Documentation Status
741
+
742
+ **Issue:** Privacy practices not clearly documented
743
+ **Tracking:** [Issue #459](https://github.com/sst/opencode/issues/459) requests clarification
744
+ **Recommendation:** Users should review provider privacy policies (Anthropic, OpenAI, etc.)
745
+
746
+ ### No Telemetry Confirmation
747
+
748
+ **Status:** Not explicitly documented
749
+ **Inference:** Local-first architecture suggests minimal telemetry
750
+ **Recommendation:** Inspect source code or network traffic for confirmation
751
+
752
+ ---
753
+
754
+ ## 12. Quirks & Gotchas
755
+
756
+ ### 1. Timeout Management
757
+
758
+ **Default:** 120 seconds for command execution
759
+ **Problem:** Insufficient for long-running tests or builds
760
+
761
+ ```bash
762
+ # Workaround: Increase timeout
763
+ opencode run --timeout 600000 "Run full test suite"
764
+ ```
765
+
766
+ **Config Alternative:**
767
+ ```json
768
+ {
769
+ "timeout": 600000
770
+ }
771
+ ```
772
+
773
+ **Reference:** [Issue #4197](https://github.com/sst/opencode/issues/4197)
774
+
775
+ ---
776
+
777
+ ### 2. Interactive Commands Fail
778
+
779
+ **Problem:** Commands requiring user input (e.g., `npm create vite`) timeout
780
+
781
+ ```bash
782
+ opencode run "Set up new Vite project"
783
+ # AI attempts: npm create vite
784
+ # Result: Hangs waiting for input, then timeout
785
+ ```
786
+
787
+ **Workaround:** Pre-configure projects outside OpenCode
788
+ **Reference:** [Issue #1656](https://github.com/sst/opencode/issues/1656)
789
+
790
+ ---
791
+
792
+ ### 3. Hanging on Errors
793
+
794
+ **Problem:** Some errors cause `opencode run` to hang instead of exiting
795
+
796
+ **Workaround:**
797
+ ```bash
798
+ timeout 300 opencode run "Your prompt"
799
+ ```
800
+
801
+ **Reference:** [Issue #4506](https://github.com/sst/opencode/issues/4506)
802
+
803
+ ---
804
+
805
+ ### 4. JSON Output Format Undocumented
806
+
807
+ **Problem:** `--format json` exists but schema not published
808
+
809
+ **Impact:** Integration requires empirical testing or source code inspection
810
+
811
+ **Workaround:** Test with sample prompts and analyze output structure
812
+
813
+ ```bash
814
+ opencode run --format json "Hello world" > output.json
815
+ cat output.json | jq .
816
+ ```
817
+
818
+ ---
819
+
820
+ ### 5. Model Selection Limitation (Resolved)
821
+
822
+ **Historical Issue:** Couldn't specify model in non-interactive mode
823
+ **Status:** Fixed; use `-m provider/model` flag
824
+ **Reference:** [Issue #277](https://github.com/opencode-ai/opencode/issues/277)
825
+
826
+ ---
827
+
828
+ ### 6. Code Reformatting Bug
829
+
830
+ **Problem:** Models attempt to reformat existing code unnecessarily
831
+
832
+ **Observation:** Multiple users report OpenCode reformatting code even when asked not to
833
+
834
+ **Impact:** May introduce style inconsistencies
835
+ **Workaround:** Use custom commands with explicit "do not reformat" instructions
836
+
837
+ ---
838
+
839
+ ### 7. Config File Ignored (Resolved)
840
+
841
+ **Historical Issue:** CLI ignored `~/.opencode.json`, always started in setup mode
842
+ **Status:** Fixed in recent versions
843
+ **Reference:** [Issue #698](https://github.com/sst/opencode/issues/698)
844
+
845
+ ---
846
+
847
+ ### 8. Help Output Incomplete
848
+
849
+ **Problem:** `opencode --help` doesn't list debug commands
850
+
851
+ **Cause:** Missing `describe` property in yargs command definitions
852
+ **Reference:** [Issue #7330](https://github.com/anomalyco/opencode/issues/7330)
853
+
854
+ **Workaround:** Check documentation at `https://opencode.ai/docs/cli/`
855
+
856
+ ---
857
+
858
+ ### 9. Auto-Approval in Non-Interactive Mode
859
+
860
+ **Behavior:** All permissions auto-approved when using `opencode run`
861
+
862
+ **Implication:** AI can execute bash commands, modify files without confirmation
863
+
864
+ **Mitigation:** Use with trusted prompts or implement wrapper script with approval logic
865
+
866
+ ---
867
+
868
+ ### 10. Session Auto-Creation
869
+
870
+ **Behavior:** Every `opencode run` creates a session, even for one-off queries
871
+
872
+ **Implication:** Session database grows over time
873
+
874
+ **Workaround:** Periodic cleanup via session management commands
875
+
876
+ ---
877
+
878
+ ## 13. Comparison: OpenCode CLI vs Claude CLI
879
+
880
+ ### Architecture
881
+
882
+ | Aspect | OpenCode | Claude CLI |
883
+ |--------|----------|------------|
884
+ | **Language** | Go | Node.js |
885
+ | **Open Source** | Yes (moved to Crush project) | No (Anthropic proprietary) |
886
+ | **Provider Support** | 75+ providers | Anthropic only |
887
+ | **Local Models** | Yes (OpenAI-compatible) | No |
888
+
889
+ ### Pricing
890
+
891
+ | Aspect | OpenCode | Claude CLI |
892
+ |--------|----------|------------|
893
+ | **Tool Cost** | Free (open source) | $17-100/month/developer |
894
+ | **API Costs** | Pay per provider | Anthropic API costs |
895
+ | **Total Cost** | API only | Subscription + API |
896
+
897
+ ### Performance & Quality
898
+
899
+ | Aspect | OpenCode | Claude CLI |
900
+ |--------|----------|------------|
901
+ | **Output Quality** | Matches Claude CLI when using same model | Native Claude integration |
902
+ | **Exclusive Models** | None | Opus 4.5 with thinking mode |
903
+ | **Speed** | Comparable | Comparable |
904
+ | **Reverse Engineering** | Based on Claude CLI logic | Original implementation |
905
+
906
+ **Source:** Andrea Grandi's testing confirms "can't tell the difference" in code quality when using same models.
907
+
908
+ ### Advanced Features
909
+
910
+ | Feature | OpenCode | Claude CLI |
911
+ |---------|----------|------------|
912
+ | **Parallel Subagents** | No | Yes (build frontend/backend simultaneously) |
913
+ | **Thinking Mode** | No | Yes (Opus 4.5 extended reasoning) |
914
+ | **Checkpoint System** | No | Yes (instant rewind to previous states) |
915
+ | **Custom Commands** | Yes (markdown templates) | Yes (slash commands) |
916
+ | **MCP Support** | Yes | Yes |
917
+ | **LSP Integration** | Yes (diagnostics tool) | Yes |
918
+ | **Remote Control** | Yes (Go architecture) | Limited |
919
+
920
+ ### Non-Interactive Mode
921
+
922
+ | Aspect | OpenCode | Claude CLI |
923
+ |--------|----------|------------|
924
+ | **Command** | `opencode run` | `claude -p` (headless mode) |
925
+ | **Model Selection** | `-m provider/model` | Built-in (Claude models only) |
926
+ | **File Attachment** | `-f` flag or `@file` syntax | Similar |
927
+ | **JSON Output** | `--format json` (undocumented schema) | Structured output options |
928
+ | **CI/CD Integration** | Supported | Explicitly designed for CI/CD |
929
+ | **Session Continuation** | `-c` or `-s session-id` | Similar |
930
+
931
+ ### Ecosystem Integration
932
+
933
+ | Aspect | OpenCode | Claude CLI |
934
+ |--------|----------|------------|
935
+ | **VS Code Extension** | Community projects | Official Anthropic extension |
936
+ | **npm Ecosystem** | Limited (Go-based) | Native (Node.js) |
937
+ | **GitHub Actions** | Community workflows | Official integration |
938
+ | **IDE Integration** | Via MCP | Native Anthropic integrations |
939
+
940
+ ### Privacy & Security
941
+
942
+ | Aspect | OpenCode | Claude CLI |
943
+ |--------|----------|------------|
944
+ | **Local-First** | Yes | Unclear (proprietary) |
945
+ | **Data Storage** | SQLite (local) | Unknown |
946
+ | **API Direct Calls** | Yes | Yes (via Anthropic) |
947
+ | **Telemetry** | Minimal/none (inferred) | Unknown |
948
+
949
+ ### User Experience
950
+
951
+ | Aspect | OpenCode | Claude CLI |
952
+ |--------|----------|------------|
953
+ | **Learning Curve** | Moderate | Low (Anthropic polish) |
954
+ | **Documentation** | Community-driven | Official Anthropic docs |
955
+ | **Bug Frequency** | Higher (open source) | Lower (commercial QA) |
956
+ | **Update Frequency** | Community-driven | Anthropic release schedule |
957
+
958
+ ### Recommendation Matrix
959
+
960
+ | Use Case | Recommended Tool | Reason |
961
+ |----------|------------------|--------|
962
+ | **Budget-constrained** | OpenCode | No subscription fee |
963
+ | **Multi-provider** | OpenCode | 75+ provider support |
964
+ | **Local/private LLMs** | OpenCode | OpenAI-compatible endpoint support |
965
+ | **Production reliability** | Claude CLI | Commercial support, QA |
966
+ | **Complex workflows** | Claude CLI | Parallel subagents, thinking mode |
967
+ | **Experimentation** | OpenCode | Model flexibility |
968
+ | **Enterprise (Anthropic)** | Claude CLI | Official support, SLA |
969
+ | **Quick prototyping** | Either | Both work well |
970
+
971
+ ### Expert Opinion
972
+
973
+ **Andrea Grandi (extensive testing):**
974
+ > "Claude was hands down the best overall… but if you have time to experiment, use OpenCode with Sonnet-4. Otherwise, use Claude Code."
975
+
976
+ **Key Insight:** OpenCode matches Claude in quality when using Claude models, but Claude CLI's exclusive features (Opus 4.5, subagents) provide edge for complex tasks.
977
+
978
+ ---
979
+
980
+ ## 14. mdcontext Integration Recommendations
981
+
982
+ ### Use Case Analysis
983
+
984
+ **mdcontext Goal:** Programmatic LLM invocation for file summarization
985
+
986
+ **Requirements:**
987
+ 1. Non-interactive batch processing
988
+ 2. File content as context
989
+ 3. Structured or parseable output
990
+ 4. Cost transparency (multiple provider support)
991
+ 5. Error handling for automation
992
+ 6. Timeout management for large files
993
+
994
+ ### Recommended Approach
995
+
996
+ #### 1. Primary Command Pattern
997
+
998
+ ```bash
999
+ opencode run \
1000
+ --format json \
1001
+ --quiet \
1002
+ --timeout 300000 \
1003
+ --model anthropic/claude-sonnet-4-20250514 \
1004
+ "Summarize this file in markdown format: @$FILE_PATH"
1005
+ ```
1006
+
1007
+ **Rationale:**
1008
+ - `--format json`: Structured output (requires testing to parse)
1009
+ - `--quiet`: No spinner for scripting
1010
+ - `--timeout 300000`: 5 minutes for large files
1011
+ - `--model`: Explicit provider/model selection
1012
+
1013
+ #### 2. Alternative: Text Output with Parsing
1014
+
1015
+ ```bash
1016
+ opencode run \
1017
+ --quiet \
1018
+ --timeout 300000 \
1019
+ --model anthropic/claude-sonnet-4-20250514 \
1020
+ "Summarize this file in markdown format with YAML frontmatter: @$FILE_PATH"
1021
+ ```
1022
+
1023
+ **Parse stdout** with regex or structured format enforcement.
1024
+
1025
+ #### 3. Server-Attached Mode (Performance)
1026
+
1027
+ ```bash
1028
+ # Startup (once)
1029
+ opencode serve --port 4096 &
1030
+
1031
+ # Per-file invocation (faster)
1032
+ opencode run \
1033
+ --attach http://localhost:4096 \
1034
+ --format json \
1035
+ --quiet \
1036
+ "Summarize @$FILE_PATH"
1037
+ ```
1038
+
1039
+ **Benefit:** Reduced cold-start latency for batch operations.
1040
+
1041
+ ### Configuration Setup
1042
+
1043
+ #### opencode.json
1044
+
1045
+ ```json
1046
+ {
1047
+ "$schema": "https://opencode.ai/config.json",
1048
+ "model": "anthropic/claude-sonnet-4-20250514",
1049
+ "timeout": 300000,
1050
+ "provider": {
1051
+ "anthropic": {
1052
+ "options": {
1053
+ "apiKey": "{env:ANTHROPIC_API_KEY}"
1054
+ }
1055
+ },
1056
+ "openai": {
1057
+ "options": {
1058
+ "apiKey": "{env:OPENAI_API_KEY}"
1059
+ }
1060
+ }
1061
+ }
1062
+ }
1063
+ ```
1064
+
1065
+ #### Custom Command (Optional)
1066
+
1067
+ **File:** `~/.config/opencode/commands/summarize-file.md`
1068
+
1069
+ ```markdown
1070
+ ---
1071
+ description: Summarize a file for mdcontext
1072
+ model: anthropic/claude-sonnet-4-20250514
1073
+ ---
1074
+ Analyze the following file and create a concise summary in markdown format.
1075
+
1076
+ Include:
1077
+ - Purpose of the file
1078
+ - Key functions/classes/exports
1079
+ - Dependencies
1080
+ - Notable patterns or algorithms
1081
+
1082
+ File: $1
1083
+
1084
+ Output format: Pure markdown, no code fences.
1085
+ ```
1086
+
1087
+ **Usage:**
1088
+ ```bash
1089
+ opencode run --command summarize-file --file path/to/file.ts
1090
+ ```
1091
+
1092
+ ### Error Handling Strategy
1093
+
1094
+ #### Wrapper Script Pattern
1095
+
1096
+ ```bash
1097
+ #!/usr/bin/env bash
1098
+
1099
+ set -euo pipefail
1100
+
1101
+ FILE_PATH="$1"
1102
+ OUTPUT_FILE="$2"
1103
+ TIMEOUT=300
1104
+
1105
+ # Run with timeout wrapper
1106
+ if ! timeout $TIMEOUT opencode run \
1107
+ --quiet \
1108
+ --format json \
1109
+ --model anthropic/claude-sonnet-4-20250514 \
1110
+ "Summarize @$FILE_PATH" > "$OUTPUT_FILE" 2>error.log; then
1111
+
1112
+ EXIT_CODE=$?
1113
+
1114
+ if [ $EXIT_CODE -eq 124 ]; then
1115
+ echo "Error: OpenCode timeout after ${TIMEOUT}s" >&2
1116
+ exit 2
1117
+ elif [ $EXIT_CODE -eq 1 ]; then
1118
+ echo "Error: OpenCode execution failed" >&2
1119
+ cat error.log >&2
1120
+ exit 1
1121
+ else
1122
+ echo "Error: Unknown failure (code $EXIT_CODE)" >&2
1123
+ exit $EXIT_CODE
1124
+ fi
1125
+ fi
1126
+
1127
+ # Validate JSON output
1128
+ if ! jq empty "$OUTPUT_FILE" 2>/dev/null; then
1129
+ echo "Error: Invalid JSON output" >&2
1130
+ exit 3
1131
+ fi
1132
+ ```
1133
+
1134
+ ### Output Parsing (JSON Format)
1135
+
1136
+ **Critical Action Required:** Empirical testing of `--format json` output.
1137
+
1138
+ **Test Command:**
1139
+ ```bash
1140
+ opencode run --format json --quiet "Say hello" > test-output.json
1141
+ cat test-output.json | jq .
1142
+ ```
1143
+
1144
+ **Expected Possibilities:**
1145
+ 1. Single JSON object with `response` field
1146
+ 2. nd-JSON (newline-delimited JSON events)
1147
+ 3. SSE-style JSON events
1148
+
1149
+ **Parsing Strategy:** Adjust based on actual format.
1150
+
1151
+ ### Cost Tracking Integration
1152
+
1153
+ **Advantage:** OpenCode supports multiple providers; mdcontext can compare costs.
1154
+
1155
+ **Providers to Support:**
1156
+ - `anthropic/claude-sonnet-4-20250514` (high quality)
1157
+ - `openai/gpt-4o` (alternative)
1158
+ - `google/gemini-2.5-flash` (cost-effective)
1159
+ - `groq/llama-3.1-70b` (high-speed, low-cost)
1160
+
1161
+ **Implementation:**
1162
+ ```bash
1163
+ # Provider rotation for cost testing
1164
+ for provider in "anthropic/claude-sonnet-4" "openai/gpt-4o" "google/gemini-2.5-flash"; do
1165
+ opencode run -m "$provider" "Summarize @$FILE_PATH" > "summary-${provider//\//-}.txt"
1166
+ done
1167
+ ```
1168
+
1169
+ **Cost Analysis:** Use `opencode stats` to track token usage and costs.
1170
+
1171
+ ### Integration Risks
1172
+
1173
+ | Risk | Mitigation |
1174
+ |------|------------|
1175
+ | **JSON format changes** | Version-pin OpenCode in docs; test before upgrades |
1176
+ | **Hanging on errors** | Wrap with `timeout` command |
1177
+ | **Session database growth** | Periodic cleanup in docs |
1178
+ | **Auto-approval risk** | Document security implications; recommend sandboxing |
1179
+ | **Provider API changes** | Test multiple providers; failover logic |
1180
+
1181
+ ### Testing Checklist
1182
+
1183
+ - [ ] Verify `--format json` output structure
1184
+ - [ ] Test timeout behavior with large files
1185
+ - [ ] Confirm exit codes for error scenarios
1186
+ - [ ] Validate stderr separation for errors
1187
+ - [ ] Benchmark server-attached vs direct invocation
1188
+ - [ ] Test file attachment with @syntax and --file flag
1189
+ - [ ] Verify model selection across providers
1190
+ - [ ] Test session continuation (if needed for multi-file context)
1191
+
1192
+ ---
1193
+
1194
+ ## 15. Official Documentation & Resources
1195
+
1196
+ ### Primary Sources
1197
+
1198
+ - **Official Docs:** [https://opencode.ai/docs/](https://opencode.ai/docs/)
1199
+ - **CLI Reference:** [https://opencode.ai/docs/cli/](https://opencode.ai/docs/cli/)
1200
+ - **Commands:** [https://opencode.ai/docs/commands/](https://opencode.ai/docs/commands/)
1201
+ - **Providers:** [https://opencode.ai/docs/providers/](https://opencode.ai/docs/providers/)
1202
+ - **Config:** [https://opencode.ai/docs/config/](https://opencode.ai/docs/config/)
1203
+ - **Troubleshooting:** [https://opencode.ai/docs/troubleshooting/](https://opencode.ai/docs/troubleshooting/)
1204
+
1205
+ ### GitHub Resources
1206
+
1207
+ - **Main Repository:** [https://github.com/opencode-ai/opencode](https://github.com/opencode-ai/opencode)
1208
+ - **Status:** Moved to Crush project (Charm team) as of Sept 2025
1209
+ - **Archive:** Read-only
1210
+ - **Crush (Successor):** [https://github.com/charmbracelet/crush](https://github.com/charmbracelet/crush)
1211
+ - **Awesome OpenCode:** [https://github.com/awesome-opencode/awesome-opencode](https://github.com/awesome-opencode/awesome-opencode)
1212
+
1213
+ ### Community Resources
1214
+
1215
+ - **DeepWiki OpenCode:** Multiple technical deep-dives
1216
+ - **Discord/Community:** Via opencode.ai (authentication flows)
1217
+
1218
+ ### Installation Guide
1219
+
1220
+ [https://opencode.ai/docs/](https://opencode.ai/docs/) - Installation section
1221
+
1222
+ ### Comparison Articles
1223
+
1224
+ - **OpenCode vs Claude Code (Builder.io):** [https://www.builder.io/blog/opencode-vs-claude-code](https://www.builder.io/blog/opencode-vs-claude-code)
1225
+ - **Andrea Grandi Comparison:** [https://www.andreagrandi.it/posts/comparing-claude-code-vs-opencode-testing-different-models/](https://www.andreagrandi.it/posts/comparing-claude-code-vs-opencode-testing-different-models/)
1226
+ - **NovaKit Blog:** [https://www.novakit.ai/blog/claude-code-vs-opencode-cli-comparison](https://www.novakit.ai/blog/claude-code-vs-opencode-cli-comparison)
1227
+
1228
+ ### GitHub Issues (Key)
1229
+
1230
+ - **Timeout Management:** [#4197](https://github.com/sst/opencode/issues/4197)
1231
+ - **Interactive Commands:** [#1656](https://github.com/sst/opencode/issues/1656)
1232
+ - **Hanging on Errors:** [#4506](https://github.com/sst/opencode/issues/4506)
1233
+ - **Config Errors:** [#4245](https://github.com/sst/opencode/issues/4245)
1234
+ - **Privacy Clarification:** [#459](https://github.com/sst/opencode/issues/459)
1235
+ - **Model Selection in Non-Interactive:** [#277](https://github.com/opencode-ai/opencode/issues/277) (resolved)
1236
+ - **Help Output Incomplete:** [#7330](https://github.com/anomalyco/opencode/issues/7330)
1237
+
1238
+ ---
1239
+
1240
+ ## 16. Concrete Command Examples
1241
+
1242
+ ### Example 1: Basic File Summarization
1243
+
1244
+ ```bash
1245
+ opencode run "Summarize this TypeScript file: @src/parser.ts"
1246
+ ```
1247
+
1248
+ **Output:** Formatted text to stdout.
1249
+
1250
+ ---
1251
+
1252
+ ### Example 2: JSON Output for Parsing
1253
+
1254
+ ```bash
1255
+ opencode run \
1256
+ --format json \
1257
+ --quiet \
1258
+ "Create a summary of @README.md in JSON format with fields: purpose, features, installation" \
1259
+ > summary.json
1260
+ ```
1261
+
1262
+ **Expected JSON** (format requires testing):
1263
+ ```json
1264
+ {
1265
+ "response": "...",
1266
+ "metadata": { ... }
1267
+ }
1268
+ ```
1269
+
1270
+ ---
1271
+
1272
+ ### Example 3: Multiple Files with Context
1273
+
1274
+ ```bash
1275
+ opencode run "Compare @src/old-api.ts and @src/new-api.ts. List breaking changes."
1276
+ ```
1277
+
1278
+ ---
1279
+
1280
+ ### Example 4: Command Output Integration
1281
+
1282
+ ```bash
1283
+ opencode run "Analyze the git diff: !git diff main...feature-branch"
1284
+ ```
1285
+
1286
+ ---
1287
+
1288
+ ### Example 5: Specific Model Selection
1289
+
1290
+ ```bash
1291
+ opencode run \
1292
+ -m google/gemini-2.5-flash \
1293
+ "Summarize this file cost-effectively: @data/large-dataset.json"
1294
+ ```
1295
+
1296
+ ---
1297
+
1298
+ ### Example 6: Session Continuation
1299
+
1300
+ ```bash
1301
+ # First invocation
1302
+ opencode run "Summarize @app.ts"
1303
+
1304
+ # Follow-up question (continues context)
1305
+ opencode run -c "What are the security implications?"
1306
+ ```
1307
+
1308
+ ---
1309
+
1310
+ ### Example 7: Server-Attached for Performance
1311
+
1312
+ ```bash
1313
+ # Terminal 1
1314
+ opencode serve --port 4096
1315
+
1316
+ # Terminal 2 (multiple fast invocations)
1317
+ for file in src/*.ts; do
1318
+ opencode run \
1319
+ --attach http://localhost:4096 \
1320
+ --quiet \
1321
+ "Summarize @$file" > "summaries/${file%.ts}.md"
1322
+ done
1323
+ ```
1324
+
1325
+ ---
1326
+
1327
+ ### Example 8: Custom Timeout for Large Files
1328
+
1329
+ ```bash
1330
+ opencode run \
1331
+ --timeout 600000 \
1332
+ --model anthropic/claude-sonnet-4-20250514 \
1333
+ "Analyze this large codebase: @monorepo/packages/**/*.ts"
1334
+ ```
1335
+
1336
+ **Note:** Glob patterns require testing; may need explicit listing.
1337
+
1338
+ ---
1339
+
1340
+ ### Example 9: Error Handling Wrapper
1341
+
1342
+ ```bash
1343
+ #!/usr/bin/env bash
1344
+ if ! opencode run -q "Summarize @$1" > output.txt 2>error.log; then
1345
+ echo "OpenCode failed. Error log:"
1346
+ cat error.log
1347
+ exit 1
1348
+ fi
1349
+ ```
1350
+
1351
+ ---
1352
+
1353
+ ### Example 10: Custom Command Invocation
1354
+
1355
+ ```bash
1356
+ # Using custom command (see section 14)
1357
+ opencode run --command summarize-file src/utils.ts
1358
+ ```
1359
+
1360
+ ---
1361
+
1362
+ ## 17. Recommendations for mdcontext
1363
+
1364
+ ### Immediate Actions
1365
+
1366
+ 1. **Test JSON Output Format**
1367
+ ```bash
1368
+ opencode run --format json -q "Hello world" > test.json
1369
+ jq . test.json
1370
+ ```
1371
+ Determine exact schema for parsing.
1372
+
1373
+ 2. **Create Wrapper Script** (see section 14) with:
1374
+ - Timeout handling
1375
+ - Exit code checking
1376
+ - Output validation
1377
+ - Error logging
1378
+
1379
+ 3. **Document Provider Options**
1380
+ - Anthropic (high quality)
1381
+ - OpenAI (alternative)
1382
+ - Gemini (cost-effective)
1383
+ - Groq (high-speed)
1384
+
1385
+ 4. **Establish Cost Baseline**
1386
+ ```bash
1387
+ opencode stats
1388
+ ```
1389
+ Track token usage across providers.
1390
+
1391
+ ### Integration Pattern
1392
+
1393
+ **Recommended Flow:**
1394
+ ```
1395
+ mdcontext → wrapper script → opencode run → JSON output → parser → summarized content
1396
+ ```
1397
+
1398
+ **Error Recovery:**
1399
+ - Retry with increased timeout
1400
+ - Fallback to alternative provider
1401
+ - Log failures for manual review
1402
+
1403
+ ### Performance Optimization
1404
+
1405
+ For batch processing:
1406
+ 1. Start `opencode serve` at mdcontext initialization
1407
+ 2. Use `--attach` for all file summarizations
1408
+ 3. Shutdown server at cleanup
1409
+
1410
+ **Expected Improvement:** 30-50% faster than cold starts (estimate; requires benchmarking).
1411
+
1412
+ ### Security Considerations
1413
+
1414
+ **Auto-Approval Risk:** OpenCode in non-interactive mode auto-approves all actions.
1415
+
1416
+ **Mitigation:**
1417
+ - Craft prompts to avoid bash execution (e.g., "Summarize" not "Analyze and fix")
1418
+ - Run in sandboxed environment (Docker/VM) if processing untrusted files
1419
+ - Review custom commands for unintended side effects
1420
+
1421
+ ### Maintenance Strategy
1422
+
1423
+ **Version Pinning:**
1424
+ - Document tested OpenCode version
1425
+ - Test before upgrading
1426
+ - Monitor Crush project (successor) for migration path
1427
+
1428
+ **Fallback Plan:**
1429
+ - Maintain Claude CLI integration as alternative
1430
+ - Document cost differences for user choice
1431
+
1432
+ ---
1433
+
1434
+ ## 18. Key Differences from Claude CLI
1435
+
1436
+ ### Syntax Differences
1437
+
1438
+ | Task | OpenCode CLI | Claude CLI |
1439
+ |------|-------------|------------|
1440
+ | **Non-interactive prompt** | `opencode run "prompt"` | `claude -p "prompt"` |
1441
+ | **Model selection** | `-m provider/model` | Built-in (Claude only) |
1442
+ | **File attachment** | `@file` or `-f file` | Similar |
1443
+ | **JSON output** | `--format json` | Structured output options |
1444
+ | **Quiet mode** | `-q` or `--quiet` | Similar |
1445
+ | **Session continuation** | `-c` or `-s id` | Similar |
1446
+
1447
+ ### Provider Flexibility
1448
+
1449
+ **OpenCode Advantage:**
1450
+ - 75+ providers (Anthropic, OpenAI, Google, Groq, Azure, AWS, local)
1451
+ - Cost comparison across providers
1452
+ - Custom OpenAI-compatible endpoints
1453
+
1454
+ **Claude CLI Limitation:**
1455
+ - Anthropic models only
1456
+ - No multi-provider support
1457
+
1458
+ ### Missing OpenCode Features (vs Claude CLI)
1459
+
1460
+ 1. **Parallel Subagents:** Claude can build frontend/backend simultaneously
1461
+ 2. **Thinking Mode:** Opus 4.5 extended reasoning (Claude exclusive)
1462
+ 3. **Checkpoint System:** Instant rewind to previous states
1463
+ 4. **Production Polish:** Claude CLI has commercial QA and support
1464
+
1465
+ ### OpenCode Advantages
1466
+
1467
+ 1. **Zero Subscription Cost:** Free tool (API costs only)
1468
+ 2. **Local Model Support:** Privacy-first option
1469
+ 3. **Provider Flexibility:** Switch based on cost/performance/features
1470
+ 4. **Open Source:** Community contributions, transparency
1471
+
1472
+ ### When to Choose OpenCode Over Claude CLI
1473
+
1474
+ - **Budget constraints:** No subscription fee
1475
+ - **Multi-provider experimentation:** Test cost/quality tradeoffs
1476
+ - **Local/private LLMs:** Maximum privacy
1477
+ - **Open source preference:** Transparency, customization
1478
+
1479
+ ### When to Choose Claude CLI Over OpenCode
1480
+
1481
+ - **Production critical systems:** Commercial support, SLA
1482
+ - **Complex workflows:** Parallel subagents, thinking mode
1483
+ - **Exclusive features:** Opus 4.5 access
1484
+ - **Minimal setup time:** Anthropic-optimized defaults
1485
+
1486
+ ---
1487
+
1488
+ ## 19. Conclusion
1489
+
1490
+ ### Summary
1491
+
1492
+ OpenCode CLI is a viable alternative to Claude CLI for mdcontext integration, offering:
1493
+
1494
+ **Strengths:**
1495
+ - Flexible multi-provider support (75+ models)
1496
+ - Cost-effective (no subscription)
1497
+ - Robust non-interactive mode
1498
+ - Local-first privacy
1499
+ - Active open source community
1500
+
1501
+ **Weaknesses:**
1502
+ - JSON output format undocumented (requires testing)
1503
+ - Occasional hanging on errors
1504
+ - Timeout management needs tuning
1505
+ - Less polished than commercial Claude CLI
1506
+
1507
+ ### Viability for mdcontext
1508
+
1509
+ **Verdict:** **Recommended with caveats**
1510
+
1511
+ OpenCode can serve as mdcontext's LLM integration layer, provided:
1512
+ 1. JSON output format is tested and validated
1513
+ 2. Wrapper script handles timeouts and errors
1514
+ 3. Provider options are documented for users
1515
+ 4. Security implications (auto-approval) are clear
1516
+
1517
+ **Alternative Strategy:** Support both OpenCode and Claude CLI, letting users choose based on budget/features.
1518
+
1519
+ ### Next Steps
1520
+
1521
+ 1. **Empirical Testing:** Validate JSON output format
1522
+ 2. **Wrapper Implementation:** Robust error handling and timeout management
1523
+ 3. **Cost Benchmarking:** Compare providers for file summarization task
1524
+ 4. **Documentation:** User-facing guide for provider selection
1525
+ 5. **Security Review:** Assess auto-approval risks for untrusted codebases
1526
+
1527
+ ---
1528
+
1529
+ ## Sources
1530
+
1531
+ - [CLI | OpenCode](https://opencode.ai/docs/cli/)
1532
+ - [GitHub - opencode-ai/opencode](https://github.com/opencode-ai/opencode)
1533
+ - [Commands | OpenCode](https://opencode.ai/docs/commands/)
1534
+ - [Providers | OpenCode](https://opencode.ai/docs/providers/)
1535
+ - [Config | OpenCode](https://opencode.ai/docs/config/)
1536
+ - [Troubleshooting | OpenCode](https://opencode.ai/docs/troubleshooting/)
1537
+ - [Comparing Claude Code vs OpenCode - Andrea Grandi](https://www.andreagrandi.it/posts/comparing-claude-code-vs-opencode-testing-different-models/)
1538
+ - [OpenCode vs Claude Code - Builder.io](https://www.builder.io/blog/opencode-vs-claude-code)
1539
+ - [OpenCode vs Claude Code - Daniel Miessler](https://danielmiessler.com/blog/opencode-vs-claude-code)
1540
+ - [Claude Code vs OpenCode CLI - NovaKit](https://www.novakit.ai/blog/claude-code-vs-opencode-cli-comparison)
1541
+ - [Set timeout for long running commands - Issue #4197](https://github.com/sst/opencode/issues/4197)
1542
+ - [Timeout when running commands - Issue #1656](https://github.com/sst/opencode/issues/1656)
1543
+ - [Bug: opencode run hangs - Issue #4506](https://github.com/sst/opencode/issues/4506)
1544
+ - [Unable to Exit OpenCode TUI - Issue #4245](https://github.com/sst/opencode/issues/4245)
1545
+ - [Privacy and Data Collection - Issue #459](https://github.com/sst/opencode/issues/459)
1546
+ - [Unable to specify model - Issue #277](https://github.com/opencode-ai/opencode/issues/277)
1547
+ - [Debug command not visible in help - Issue #7330](https://github.com/anomalyco/opencode/issues/7330)
1548
+ - [opencode-openmemory - Local-first memory plugin](https://github.com/happycastle114/opencode-openmemory)
1549
+
1550
+ ---
1551
+
1552
+ **End of Research Document**