troubleshooting.mdx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ---
  2. title: "Troubleshooting"
  3. description: "Diagnose OpenCode startup, server, and session issues."
  4. ---
  5. <Tip>
  6. You can ask OpenCode to debug itself. Describe the problem and ask it to use this troubleshooting page; it can read the
  7. steps below, inspect its service and logs, and help identify the issue.
  8. </Tip>
  9. OpenCode runs as two processes: the TUI is a client, while a background server owns sessions, plugins, permissions, and
  10. other application state. Start by determining whether an issue is in the client, the shared server, or a specific project.
  11. ## Check the background service
  12. Show the current server status:
  13. ```bash
  14. opencode2 service status
  15. ```
  16. Verify that its API is healthy:
  17. ```bash
  18. opencode2 api get /api/health
  19. ```
  20. If the service is stuck or unhealthy, restart it:
  21. ```bash
  22. opencode2 service restart
  23. ```
  24. From inside the TUI, run `/reload` to restart the managed service and reconnect:
  25. ```text
  26. /reload
  27. ```
  28. You can also stop and start it explicitly:
  29. ```bash
  30. opencode2 service stop
  31. opencode2 service start
  32. ```
  33. <Note>
  34. OpenCode normally discovers or starts the shared background service automatically. The service commands are only needed
  35. when diagnosing its lifecycle.
  36. </Note>
  37. ## Run an isolated session
  38. Use standalone mode to run the TUI with a private server that exits with it:
  39. ```bash
  40. opencode2 --standalone
  41. ```
  42. If an issue disappears in standalone mode, it is likely related to the shared background service rather than the TUI or
  43. project itself.
  44. ## Inspect the API
  45. The `api` command uses the same discovery and authentication flow as the TUI. It accepts either an HTTP method and path or
  46. an OpenAPI operation ID.
  47. See the [API reference](/api) for all endpoints and operation IDs.
  48. Pass a JSON request body with `--data` or `-d`, and add headers with `--header` or `-H`.
  49. <Warning>
  50. Running `opencode2 api` may start the background service when no compatible healthy service is available.
  51. </Warning>
  52. ## Read logs
  53. Installed builds write logs to:
  54. ```text
  55. ~/.local/share/opencode/log/opencode.log
  56. ```
  57. Follow the log while reproducing the problem:
  58. ```bash
  59. tail -f ~/.local/share/opencode/log/opencode.log
  60. ```
  61. Each line includes a process `run` ID and a `role` field. Use `role=cli` for TUI and command startup, and `role=server` for
  62. session, provider, plugin, permission, and tool activity.
  63. ```bash
  64. grep 'role=cli' ~/.local/share/opencode/log/opencode.log
  65. grep 'role=server' ~/.local/share/opencode/log/opencode.log
  66. grep 'run=8fc3b1d5' ~/.local/share/opencode/log/opencode.log
  67. ```
  68. Increase verbosity for one reproduction:
  69. ```bash
  70. OPENCODE_LOG_LEVEL=DEBUG opencode2
  71. ```
  72. ## Service files
  73. The shared server registers itself at:
  74. ```text
  75. ~/.local/state/opencode/service.json
  76. ```
  77. Its private service configuration is stored separately at:
  78. ```text
  79. ~/.config/opencode/service.json
  80. ```
  81. The database normally lives at:
  82. ```text
  83. ~/.local/share/opencode/opencode-next.db
  84. ```
  85. `OPENCODE_DB` can override the database location.
  86. <Warning>
  87. Do not delete or edit service files or the database while troubleshooting. Use the service commands to manage the daemon,
  88. and make a backup before inspecting persistent data with external tools.
  89. </Warning>
  90. ## Explicit servers
  91. When connecting with `--server`, set `OPENCODE_PASSWORD` if the server requires authentication:
  92. ```bash
  93. OPENCODE_PASSWORD=secret opencode2 --server http://127.0.0.1:4096
  94. ```
  95. The CLI checks the server before opening the TUI and reports whether it is unreachable, requires a password, or rejected
  96. the supplied password.
  97. ## Report an issue
  98. Include the following when reporting a reproducible problem:
  99. - Output from `opencode2 --version`
  100. - Output from `opencode2 service status`
  101. - The smallest sequence of steps that reproduces the issue
  102. - Whether the issue also occurs with `opencode2 --standalone`
  103. - Relevant log lines, including their `run` and `role` fields
  104. Remove API keys, authorization headers, prompts, file contents, and other sensitive data before sharing logs.
  105. ## Local development
  106. When working from the OpenCode repository, run V2 commands from the repository root:
  107. ```bash
  108. bun dev
  109. ```
  110. The local development channel keeps its logs, SQLite database, and service registration separate from installed builds:
  111. ```text
  112. ~/.local/share/opencode/log/opencode-local.log
  113. ~/.local/share/opencode/opencode-local.db
  114. ~/.local/state/opencode/service-local.json
  115. ```
  116. Use the same diagnostics through the package development command:
  117. ```bash
  118. bun dev service status
  119. bun dev service restart
  120. bun dev api get /api/health
  121. ```