cli.mdx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. ---
  2. title: CLI
  3. description: opencode CLI options and commands.
  4. ---
  5. import { Tabs, TabItem } from "@astrojs/starlight/components"
  6. The opencode CLI accepts commands as documented on this page. You can run any of the available commands to interact with opencode programmatically.
  7. ```bash
  8. opencode run "Explain how closures work in JavaScript"
  9. ```
  10. ---
  11. ## Commands
  12. The opencode CLI also has the following commands.
  13. ---
  14. ### agent
  15. Manage agents for opencode.
  16. ```bash
  17. opencode agent [command]
  18. ```
  19. ---
  20. #### create
  21. Create a new agent with custom configuration.
  22. ```bash
  23. opencode agent create
  24. ```
  25. This command will guide you through creating a new agent with a custom system prompt and tool configuration.
  26. ---
  27. ### auth
  28. Command to manage credentials and login for providers.
  29. ```bash
  30. opencode auth [command]
  31. ```
  32. ---
  33. #### login
  34. opencode is powered by the provider list at [Models.dev](https://models.dev), so you can use `opencode auth login` to configure API keys for any provider you'd like to use. This is stored in `~/.local/share/opencode/auth.json`.
  35. ```bash
  36. opencode auth login
  37. ```
  38. When opencode starts up it loads the providers from the credentials file. And if there are any keys defined in your environments or a `.env` file in your project.
  39. ---
  40. #### list
  41. Lists all the authenticated providers as stored in the credentials file.
  42. ```bash
  43. opencode auth list
  44. ```
  45. Or the short version.
  46. ```bash
  47. opencode auth ls
  48. ```
  49. ---
  50. #### logout
  51. Logs you out of a provider by clearing it from the credentials file.
  52. ```bash
  53. opencode auth logout
  54. ```
  55. ---
  56. ### github
  57. Manage the GitHub agent for repository automation.
  58. ```bash
  59. opencode github [command]
  60. ```
  61. ---
  62. #### install
  63. Install the GitHub agent in your repository.
  64. ```bash
  65. opencode github install
  66. ```
  67. This sets up the necessary GitHub Actions workflow and guides you through the configuration process. [Learn more](/docs/github).
  68. ---
  69. #### run
  70. Run the GitHub agent. This is typically used in GitHub Actions.
  71. ```bash
  72. opencode github run
  73. ```
  74. ##### Flags
  75. | Flag | Description |
  76. | --------- | -------------------------------------- |
  77. | `--event` | GitHub mock event to run the agent for |
  78. | `--token` | GitHub personal access token |
  79. ---
  80. ### models
  81. List all available models from configured providers.
  82. ```bash
  83. opencode models
  84. ```
  85. This command displays all models available across your configured providers in the format `provider/model`.
  86. ---
  87. ### run
  88. Run opencode in non-interactive mode by passing a prompt directly.
  89. ```bash
  90. opencode run [message..]
  91. ```
  92. This is useful for scripting, automation, or when you want a quick answer without launching the full TUI. For example.
  93. ```bash "opencode run"
  94. opencode run Explain the use of context in Go
  95. ```
  96. #### Flags
  97. | Flag | Short | Description |
  98. | ------------ | ----- | ------------------------------------------ |
  99. | `--continue` | `-c` | Continue the last session |
  100. | `--session` | `-s` | Session ID to continue |
  101. | `--share` | | Share the session |
  102. | `--model` | `-m` | Model to use in the form of provider/model |
  103. | `--agent` | | Agent to use |
  104. ---
  105. ### serve
  106. Start a headless opencode server for API access.
  107. ```bash
  108. opencode serve
  109. ```
  110. This starts an HTTP server that provides API access to opencode functionality without the TUI interface.
  111. #### Flags
  112. | Flag | Short | Description |
  113. | ------------ | ----- | --------------------- |
  114. | `--port` | `-p` | Port to listen on |
  115. | `--hostname` | `-h` | Hostname to listen on |
  116. ---
  117. ### upgrade
  118. Updates opencode to the latest version or a specific version.
  119. ```bash
  120. opencode upgrade [target]
  121. ```
  122. To upgrade to the latest version.
  123. ```bash
  124. opencode upgrade
  125. ```
  126. To upgrade to a specific version.
  127. ```bash
  128. opencode upgrade v0.1.48
  129. ```
  130. #### Flags
  131. | Flag | Short | Description |
  132. | ---------- | ----- | ----------------------------------------------------------------- |
  133. | `--method` | `-m` | The installation method that was used; curl, npm, pnpm, bun, brew |
  134. ---
  135. ## Flags
  136. The opencode CLI takes the following global flags.
  137. | Flag | Short | Description |
  138. | -------------- | ----- | ------------------------------------------ |
  139. | `--help` | `-h` | Display help |
  140. | `--version` | | Print version number |
  141. | `--print-logs` | | Print logs to stderr |
  142. | `--log-level` | | Log level (DEBUG, INFO, WARN, ERROR) |
  143. | `--prompt` | `-p` | Prompt to use |
  144. | `--model` | `-m` | Model to use in the form of provider/model |
  145. | `--agent` | | Agent to use |
  146. | `--port` | | Port to listen on |
  147. | `--hostname` | | Hostname to listen on |