Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/opencode/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Log Sources

- OpenCode session usage is recorded under `${OPENCODE_DATA_DIR:-~/.local/share/opencode}/storage/message/` (the CLI resolves `OPENCODE_DATA_DIR` and falls back to `~/.local/share/opencode`).
- Each message is stored as an individual JSON file (not JSONL like Claude or Codex).
- Message structure includes `tokens.input`, `tokens.output`, `tokens.cache.read`, and `tokens.cache.write`.
- OpenCode session usage is recorded in `${OPENCODE_DATA_DIR:-~/.local/share/opencode}/opencode.db`.
- Usage is read from the SQLite `message` and `session` tables.
- Assistant message payloads are stored as JSON in `message.data` and include `tokens.input`, `tokens.output`, `tokens.cache.read`, and `tokens.cache.write`.

## Token Fields

Expand Down
10 changes: 5 additions & 5 deletions apps/opencode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ Useful environment variables:

## Cost Calculation

OpenCode stores `cost: 0` in message files, so this CLI calculates accurate costs from token usage data using the LiteLLM pricing database. All models supported by LiteLLM will have accurate pricing.
OpenCode stores `cost: 0` in the SQLite database, so this CLI calculates accurate costs from token usage data using the LiteLLM pricing database. All models supported by LiteLLM will have accurate pricing.

## Data Location

OpenCode stores usage data in:
OpenCode stores usage data in `~/.local/share/opencode/opencode.db`.

- **Messages**: `~/.local/share/opencode/storage/message/{sessionID}/msg_{messageID}.json`
- **Sessions**: `~/.local/share/opencode/storage/session/{projectHash}/{sessionID}.json`
- **Messages**: `message` table (`data` JSON column contains assistant message payloads)
- **Sessions**: `session` table (session metadata such as title, parent, project, and directory)

Each message file contains token counts (`input`, `output`, `cache.read`, `cache.write`) and model information.
The CLI reads assistant message token counts from `data.tokens.input`, `data.tokens.output`, `data.tokens.cache.read`, and `data.tokens.cache.write`.

## Documentation

Expand Down
4 changes: 1 addition & 3 deletions apps/opencode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"engines": {
"node": ">=20.19.4"
"node": ">=22.13.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping this since node:sqlite was introduced in Node v22. We can stick with v20 if adding a dependency is okay.

},
"scripts": {
"build": "tsdown",
Expand All @@ -53,12 +53,10 @@
"clean-pkg-json": "catalog:release",
"es-toolkit": "catalog:runtime",
"eslint": "catalog:lint",
"fast-sort": "catalog:runtime",
"fs-fixture": "catalog:testing",
"gunshi": "catalog:runtime",
"path-type": "catalog:runtime",
"picocolors": "catalog:runtime",
"tinyglobby": "catalog:runtime",
"tsdown": "catalog:build",
"unplugin-macros": "catalog:build",
"unplugin-unused": "catalog:build",
Expand Down
Loading