themes.mdx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. ---
  2. title: Themes
  3. ---
  4. opencode supports a flexible JSON-based theme system that allows users to create and customize themes easily.
  5. ## Theme Loading Hierarchy
  6. Themes are loaded from multiple directories in the following order (later directories override earlier ones):
  7. 1. **Built-in themes** - Embedded in the binary
  8. 2. **User config directory** - `~/.config/opencode/themes/*.json` (or `$XDG_CONFIG_HOME/opencode/themes/*.json`)
  9. 3. **Project root directory** - `<project-root>/.opencode/themes/*.json`
  10. 4. **Current working directory** - `./.opencode/themes/*.json`
  11. If multiple directories contain a theme with the same name, the theme from the directory with higher priority will be used.
  12. ## Creating a Custom Theme
  13. To create a custom theme, create a JSON file in one of the theme directories:
  14. ```bash no-frame
  15. # For user-wide themes
  16. mkdir -p ~/.config/opencode/themes
  17. vim ~/.config/opencode/themes/my-theme.json
  18. # For project-specific themes
  19. mkdir -p .opencode/themes
  20. vim .opencode/themes/my-theme.json
  21. ```
  22. ## Theme JSON Format
  23. Themes use a flexible JSON format with support for:
  24. - **Hex colors**: `"#ffffff"`
  25. - **ANSI colors**: `3` (0-255)
  26. - **Color references**: `"primary"` or custom definitions
  27. - **Dark/light variants**: `{"dark": "#000", "light": "#fff"}`
  28. - **No color**: `"none"` - Uses the terminal's default color (transparent)
  29. ### Example Theme
  30. ```json no-frame
  31. {
  32. "$schema": "https://opencode.ai/theme.json",
  33. "defs": {
  34. "nord0": "#2E3440",
  35. "nord1": "#3B4252",
  36. "nord2": "#434C5E",
  37. "nord3": "#4C566A",
  38. "nord4": "#D8DEE9",
  39. "nord5": "#E5E9F0",
  40. "nord6": "#ECEFF4",
  41. "nord7": "#8FBCBB",
  42. "nord8": "#88C0D0",
  43. "nord9": "#81A1C1",
  44. "nord10": "#5E81AC",
  45. "nord11": "#BF616A",
  46. "nord12": "#D08770",
  47. "nord13": "#EBCB8B",
  48. "nord14": "#A3BE8C",
  49. "nord15": "#B48EAD"
  50. },
  51. "theme": {
  52. "primary": {
  53. "dark": "nord8",
  54. "light": "nord10"
  55. },
  56. "secondary": {
  57. "dark": "nord9",
  58. "light": "nord9"
  59. },
  60. "accent": {
  61. "dark": "nord7",
  62. "light": "nord7"
  63. },
  64. "error": {
  65. "dark": "nord11",
  66. "light": "nord11"
  67. },
  68. "warning": {
  69. "dark": "nord12",
  70. "light": "nord12"
  71. },
  72. "success": {
  73. "dark": "nord14",
  74. "light": "nord14"
  75. },
  76. "info": {
  77. "dark": "nord8",
  78. "light": "nord10"
  79. },
  80. "text": {
  81. "dark": "nord4",
  82. "light": "nord0"
  83. },
  84. "textMuted": {
  85. "dark": "nord3",
  86. "light": "nord1"
  87. },
  88. "background": {
  89. "dark": "nord0",
  90. "light": "nord6"
  91. },
  92. "backgroundPanel": {
  93. "dark": "nord1",
  94. "light": "nord5"
  95. },
  96. "backgroundElement": {
  97. "dark": "nord1",
  98. "light": "nord4"
  99. },
  100. "border": {
  101. "dark": "nord2",
  102. "light": "nord3"
  103. },
  104. "borderActive": {
  105. "dark": "nord3",
  106. "light": "nord2"
  107. },
  108. "borderSubtle": {
  109. "dark": "nord2",
  110. "light": "nord3"
  111. },
  112. "diffAdded": {
  113. "dark": "nord14",
  114. "light": "nord14"
  115. },
  116. "diffRemoved": {
  117. "dark": "nord11",
  118. "light": "nord11"
  119. },
  120. "diffContext": {
  121. "dark": "nord3",
  122. "light": "nord3"
  123. },
  124. "diffHunkHeader": {
  125. "dark": "nord3",
  126. "light": "nord3"
  127. },
  128. "diffHighlightAdded": {
  129. "dark": "nord14",
  130. "light": "nord14"
  131. },
  132. "diffHighlightRemoved": {
  133. "dark": "nord11",
  134. "light": "nord11"
  135. },
  136. "diffAddedBg": {
  137. "dark": "#3B4252",
  138. "light": "#E5E9F0"
  139. },
  140. "diffRemovedBg": {
  141. "dark": "#3B4252",
  142. "light": "#E5E9F0"
  143. },
  144. "diffContextBg": {
  145. "dark": "nord1",
  146. "light": "nord5"
  147. },
  148. "diffLineNumber": {
  149. "dark": "nord2",
  150. "light": "nord4"
  151. },
  152. "diffAddedLineNumberBg": {
  153. "dark": "#3B4252",
  154. "light": "#E5E9F0"
  155. },
  156. "diffRemovedLineNumberBg": {
  157. "dark": "#3B4252",
  158. "light": "#E5E9F0"
  159. },
  160. "markdownText": {
  161. "dark": "nord4",
  162. "light": "nord0"
  163. },
  164. "markdownHeading": {
  165. "dark": "nord8",
  166. "light": "nord10"
  167. },
  168. "markdownLink": {
  169. "dark": "nord9",
  170. "light": "nord9"
  171. },
  172. "markdownLinkText": {
  173. "dark": "nord7",
  174. "light": "nord7"
  175. },
  176. "markdownCode": {
  177. "dark": "nord14",
  178. "light": "nord14"
  179. },
  180. "markdownBlockQuote": {
  181. "dark": "nord3",
  182. "light": "nord3"
  183. },
  184. "markdownEmph": {
  185. "dark": "nord12",
  186. "light": "nord12"
  187. },
  188. "markdownStrong": {
  189. "dark": "nord13",
  190. "light": "nord13"
  191. },
  192. "markdownHorizontalRule": {
  193. "dark": "nord3",
  194. "light": "nord3"
  195. },
  196. "markdownListItem": {
  197. "dark": "nord8",
  198. "light": "nord10"
  199. },
  200. "markdownListEnumeration": {
  201. "dark": "nord7",
  202. "light": "nord7"
  203. },
  204. "markdownImage": {
  205. "dark": "nord9",
  206. "light": "nord9"
  207. },
  208. "markdownImageText": {
  209. "dark": "nord7",
  210. "light": "nord7"
  211. },
  212. "markdownCodeBlock": {
  213. "dark": "nord4",
  214. "light": "nord0"
  215. },
  216. "syntaxComment": {
  217. "dark": "nord3",
  218. "light": "nord3"
  219. },
  220. "syntaxKeyword": {
  221. "dark": "nord9",
  222. "light": "nord9"
  223. },
  224. "syntaxFunction": {
  225. "dark": "nord8",
  226. "light": "nord8"
  227. },
  228. "syntaxVariable": {
  229. "dark": "nord7",
  230. "light": "nord7"
  231. },
  232. "syntaxString": {
  233. "dark": "nord14",
  234. "light": "nord14"
  235. },
  236. "syntaxNumber": {
  237. "dark": "nord15",
  238. "light": "nord15"
  239. },
  240. "syntaxType": {
  241. "dark": "nord7",
  242. "light": "nord7"
  243. },
  244. "syntaxOperator": {
  245. "dark": "nord9",
  246. "light": "nord9"
  247. },
  248. "syntaxPunctuation": {
  249. "dark": "nord4",
  250. "light": "nord0"
  251. }
  252. }
  253. }
  254. ```
  255. ### Color Definitions
  256. The `defs` section (optional) allows you to define reusable colors that can be referenced in the theme.
  257. ### Using "none" for Terminal Defaults
  258. The special value `\"none\"` can be used for any color to inherit the terminal's default color. This is particularly useful for creating themes that blend seamlessly with your terminal's color scheme:
  259. - `\"text\": \"none\"` - Uses terminal's default foreground color
  260. - `\"background\": \"none\"` - Uses terminal's default background color
  261. ## The System Theme
  262. The `system` theme is opencode's default theme, designed to automatically adapt to your terminal's color scheme. Unlike traditional themes that use fixed colors, the system theme:
  263. - **Generates gray scale**: Creates a custom gray scale based on your terminal's background color, ensuring optimal contrast
  264. - **Uses ANSI colors**: Leverages standard ANSI colors (0-15) for syntax highlighting and UI elements, which respect your terminal's color palette
  265. - **Preserves terminal defaults**: Uses `none` for text and background colors to maintain your terminal's native appearance
  266. The system theme is ideal for users who:
  267. - Want opencode to match their terminal's appearance
  268. - Use custom terminal color schemes
  269. - Prefer a consistent look across all terminal applications
  270. ## Built-in Themes
  271. opencode comes with several built-in themes:
  272. - `system` - Default theme that dynamically adapts to your terminal's background color
  273. - `tokyonight` - Tokyonight theme
  274. - `everforest` - Everforest theme
  275. - `ayu` - Ayu dark theme
  276. - `catppuccin` - Catppuccin theme
  277. - `gruvbox` - Gruvbox theme
  278. - `kanagawa` - Kanagawa theme
  279. - `nord` - Nord theme
  280. - `matrix` - Hacker-style green on black theme
  281. - `one-dark` - Atom One Dark inspired theme
  282. ## Using a Theme
  283. To use a theme, set it in your opencode configuration or select it from the theme dialog in the TUI.
  284. ```json title="opencode.json" {3}
  285. {
  286. "$schema": "https://opencode.ai/config.json",
  287. "theme": "tokyonight"
  288. }
  289. ```