The `opencode-local` package provides a Node.js interface for programmatic access to local Opencode project data. It allows developers to read information directly from the local Opencode SQLite database, bypassing the need to shell out to `opencode db` for each query. Additionally, it supports querying a running Opencode server for project lists, offering flexibility to retrieve data from either the local database or a live instance. The current stable version is 1.3.11, and while a specific release cadence isn't documented, its versioning suggests ongoing maintenance. A key differentiator is its dual capability to interface with both the local SQLite file and a remote Opencode server's API, along with dedicated utilities for exporting project data to JSON, making it a powerful tool for integrating Opencode project insights into developer workflows or custom tooling. It requires Node.js >=22.5.0 and an existing local Opencode installation.
npm install opencode-localVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize the client, list projects from the local Opencode database, and then fetch sessions for a subset of those projects, logging the first results.
Ensure Opencode is installed locally and that the database file exists and is readable. Use the `dbPath` option in `createLocal()` if the database is not in its default location.
Upgrade your Node.js environment to version 22.5.0 or newer. Use `nvm` or `volta` to manage Node.js versions if necessary.
Verify that your Opencode server is running and listening on the specified `baseUrl` (default is `http://localhost:4096`). Check firewall rules if connection issues persist.
Always import `exportProjects` using `import { exportProjects } from 'opencode-local/export'`.Verify the absolute path provided to `dbPath` in `createLocal()` and ensure the current user has read permissions for the file. Check if Opencode is installed and has created its database.
Ensure the `opencode` CLI is installed and accessible in your system's PATH, or provide the absolute path to the `opencode` binary using the `bin` option in `createLocal()`.
Start your Opencode server. If it's already running, confirm the `baseUrl` in `createLocal().search()` options (or similar) is correct and matches the server's listening address and port.