index.mdx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. ---
  2. title: Intro
  3. description: Get started with opencode.
  4. ---
  5. import { Tabs, TabItem } from "@astrojs/starlight/components"
  6. [**opencode**](/) is an AI coding agent built for the terminal.
  7. ![opencode TUI with the opencode theme](../../assets/lander/screenshot.png)
  8. Let's get started.
  9. ---
  10. #### Prerequisites
  11. To use opencode, you'll need:
  12. 1. A modern terminal emulator like:
  13. - [WezTerm](https://wezterm.org), cross-platform
  14. - [Alacritty](https://alacritty.org), cross-platform
  15. - [Ghostty](https://ghostty.org), Linux and macOS
  16. - [Kitty](https://sw.kovidgoyal.net/kitty/), Linux and macOS
  17. 2. API keys for the LLM providers you want to use.
  18. ---
  19. ## Install
  20. The easiest way to install opencode is through the install script.
  21. ```bash
  22. curl -fsSL https://opencode.ai/install | bash
  23. ```
  24. You can also install it with the following:
  25. - **Using Node.js**
  26. <Tabs>
  27. <TabItem label="npm">```bash npm install -g opencode-ai ```</TabItem>
  28. <TabItem label="Bun">```bash bun install -g opencode-ai ```</TabItem>
  29. <TabItem label="pnpm">```bash pnpm install -g opencode-ai ```</TabItem>
  30. <TabItem label="Yarn">```bash yarn global add opencode-ai ```</TabItem>
  31. </Tabs>
  32. - **Using Homebrew on macOS and Linux**
  33. ```bash
  34. brew install sst/tap/opencode
  35. ```
  36. - **Using Paru on Arch Linux**
  37. ```bash
  38. paru -S opencode-bin
  39. ```
  40. #### Windows
  41. Right now the automatic installation methods do not work properly on Windows. However you can grab the binary from the [Releases](https://github.com/sst/opencode/releases).
  42. ---
  43. ## Configure
  44. With opencode you can use any LLM provider by configuring their API keys.
  45. We recommend signing up for [Claude Pro](https://www.anthropic.com/news/claude-pro) or [Max](https://www.anthropic.com/max), it's the most cost-effective way to use opencode.
  46. Once you've signed up, run `opencode auth login` and select Anthropic.
  47. ```bash
  48. $ opencode auth login
  49. ┌ Add credential
  50. ◆ Select provider
  51. │ ● Anthropic
  52. │ ○ OpenAI
  53. │ ○ Google
  54. │ ○ Amazon Bedrock
  55. │ ○ Azure
  56. │ ○ DeepSeek
  57. │ ○ Groq
  58. │ ...
  59. ```
  60. Alternatively, you can select one of the other providers. [Learn more](/docs/providers#directory).
  61. ---
  62. ## Initialize
  63. Now that you've configured a provider, you can navigate to a project that
  64. you want to work on.
  65. ```bash
  66. cd /path/to/project
  67. ```
  68. And run opencode.
  69. ```bash
  70. opencode
  71. ```
  72. Next, initialize opencode for the project by running the following command.
  73. ```bash frame="none"
  74. /init
  75. ```
  76. This will get opencode to analyze your project and create an `AGENTS.md` file in
  77. the project root.
  78. :::tip
  79. You should commit your project's `AGENTS.md` file to Git.
  80. :::
  81. This helps opencode understand the project structure and the coding patterns
  82. used.
  83. ---
  84. ## Usage
  85. You are now ready to use opencode to work on your project. Feel free to ask it
  86. anything!
  87. If you are new to using an AI coding agent, here are some examples that might
  88. help.
  89. ---
  90. ### Ask questions
  91. You can ask opencode to explain the codebase to you.
  92. :::tip
  93. Use the `@` key to fuzzy search for files in the project.
  94. :::
  95. ```txt frame="none" "@packages/functions/src/api/index.ts"
  96. How is authentication handled in @packages/functions/src/api/index.ts
  97. ```
  98. This is helpful if there's a part of the codebase that you didn't work on.
  99. ---
  100. ### Add features
  101. You can ask opencode to add new features to your project. Though we first recommend asking it to create a plan.
  102. 1. **Create a plan**
  103. opencode has a _Plan mode_ that disables its ability to make changes and
  104. instead suggest _how_ it'll implement the feature.
  105. Switch to it using the **Tab** key. You'll see an indicator for this in the lower right corner.
  106. ```bash frame="none" title="Switch to Plan mode"
  107. <TAB>
  108. ```
  109. Now let's describe what we want it to do.
  110. ```txt frame="none"
  111. When a user deletes a note, we'd like to flag it as deleted in the database.
  112. Then create a screen that shows all the recently deleted notes.
  113. From this screen, the user can undelete a note or permanently delete it.
  114. ```
  115. You want to give opencode enough details to understand what you want. It helps
  116. to talk to it like you are talking to a junior developer on your team.
  117. :::tip
  118. Give opencode plenty of context and examples to help it understand what you
  119. want.
  120. :::
  121. 2. **Iterate on the plan**
  122. Once it gives you a plan, you can give it feedback or add more details.
  123. ```txt frame="none"
  124. We'd like to design this new screen using a design I've used before.
  125. [Image #1] Take a look at this image and use it as a reference.
  126. ```
  127. :::tip
  128. Drag and drop images into the terminal to add them to the prompt.
  129. :::
  130. opencode can scan any images you give it and add them to the prompt. You can
  131. do this by dragging and dropping an image into the terminal.
  132. 3. **Build the feature**
  133. Once you feel comfortable with the plan, switch back to _Build mode_ by
  134. hitting the **Tab** key again.
  135. ```bash frame="none"
  136. <TAB>
  137. ```
  138. And asking it to make the changes.
  139. ```bash frame="none"
  140. Sounds good! Go ahead and make the changes.
  141. ```
  142. ---
  143. ### Make changes
  144. For more straightforward changes, you can ask opencode to directly build it
  145. without having to review the plan first.
  146. ```txt frame="none" "@packages/functions/src/settings.ts" "@packages/functions/src/notes.ts"
  147. We need to add authentication to the /settings route. Take a look at how this is
  148. handled in the /notes route in @packages/functions/src/notes.ts and implement
  149. the same logic in @packages/functions/src/settings.ts
  150. ```
  151. You want to make sure you provide a good amount of detail so opencode makes the right
  152. changes.
  153. ---
  154. ### Undo changes
  155. Let's say you ask opencode to make some changes.
  156. ```txt frame="none" "@packages/functions/src/api/index.ts"
  157. Can you refactor the function in @packages/functions/src/api/index.ts?
  158. ```
  159. But you realize that it is not what you wanted. You **can undo** the changes
  160. using the `/undo` command.
  161. ```bash frame="none"
  162. /undo
  163. ```
  164. opencode will now revert the changes you made and show your original message
  165. again.
  166. ```txt frame="none" "@packages/functions/src/api/index.ts"
  167. Can you refactor the function in @packages/functions/src/api/index.ts?
  168. ```
  169. From here you can tweak the prompt and ask opencode to try again.
  170. :::tip
  171. You can run `/undo` multiple times to undo multiple changes.
  172. :::
  173. Or you **can redo** the changes using the `/redo` command.
  174. ```bash frame="none"
  175. /redo
  176. ```
  177. ---
  178. ## Share
  179. The conversations that you have with opencode can be [shared with your
  180. team](/docs/share).
  181. ```bash frame="none"
  182. /share
  183. ```
  184. This will create a link to the current conversation and copy it to your clipboard.
  185. :::note
  186. Conversations are not shared by default.
  187. :::
  188. Here's an [example conversation](https://opencode.ai/s/4XP1fce5) with opencode.
  189. ---
  190. ## Customize
  191. And that's it! You are now a pro at using opencode.
  192. To make it your own, we recommend [picking a theme](/docs/themes), [customizing the keybinds](/docs/keybinds), [configuring code formatters](/docs/formatters), [creating custom commands](/docs/commands), or playing around with the [opencode config](/docs/config).