Quick answer
Install OpenCode with the package manager or install script, run `opencode auth login` to connect a provider, start `opencode` in a project, and pick a model with `/models`. Usage is written to the local data folder automatically, so you can review tokens and cost after the session.
Install and connect a provider
npm i -g opencode-ai
# or
brew install sst/tap/opencode
opencode auth loginauth login lists providers and asks for the credential each one needs. Use an API key for metered billing or a subscription-backed provider where supported.
Run your first task
- Change into a project directory and run
opencode. - Open
/modelsand choose a model. Start with a cheap one for exploration. - Describe the task and point at specific files rather than the whole repo.
- Use
/sessionsto return to an earlier conversation. - Run
opencode run "prompt"for a one-shot, non-interactive task.
Find the usage afterward
Every assistant message records tokens and, where available, cost. The data lives in ~/.local/share/opencode on macOS and Linux and %APPDATA%\opencode on Windows.
- Query the database for a total.
- Use
opencode statswhere available. - Or open UsageAtlas for history and a model split.
A first week that produces usable data
The point of a first week is not to learn every flag. It is to produce sessions you can measure, so the second week starts with evidence rather than impressions.
- Configure one provider key and confirm a session completes.
- Do three real tasks rather than toy prompts.
- At the end of each day, check the token total.
- After a week, compare per-task cost across the three tasks.
- Add a second provider only after the first is measured.
The OpenCode usage guide covers where the numbers live, and OpenCode free models covers the zero-cost option.
Questions, answered
Do I need an API key to use OpenCode?
You need a provider credential. Some providers offer free models, and local models need no key.
Where is the OpenCode config file?
In ~/.config/opencode on macOS and Linux, and under %APPDATA%\opencode on Windows. The exact filename depends on the version.
Can I use OpenCode offline?
Only with a local model. Hosted providers need a network connection.