Problem
I was trying to configure OpenCode with a custom provider and MCP servers by creating an opencode.json configuration file. However, I couldn’t determine the correct path to place this file on Windows. Documentation suggested various standard locations, but none of them seemed to work. (I later found out that I had customised the XDG_CONFIG_HOME environment variable to something else, so that’s why the standard locations didn’t work for me.)
Solution
After much trial and error, I discovered an undocumented command that shows all the system and environmental paths that OpenCode uses:
opencode debug pathsThis command revealed the exact directory structure where OpenCode looks for configuration files, making it clear where to place opencode.json. The output looks something like this:
home C:\Users\hungy
data D:\appdata\opencode
bin D:\appdata\opencode\bin
log D:\appdata\opencode\log
cache D:\appdata\temp\opencode
config D:\appdata\opencode
state D:\appdata\opencode
Source
I found the debug command in a GitHub issue: https://github.com/sst/opencode/issues/1235