{"library":"opencode-local","title":"Opencode Local Data Access","description":"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install opencode-local"],"cli":null},"imports":["import { createLocal } from 'opencode-local'","import { exportProjects } from 'opencode-local/export'","import type { ProjectRow } from 'opencode-local'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createLocal } from \"opencode-local\"\n\nasync function run() {\n  const client = createLocal()\n\n  try {\n    const projects = await client.listProjects()\n    // Get IDs of the first 5 projects to list sessions\n    const projectIds = projects.slice(0, 5).map((project) => project.id)\n    const sessions = await client.listSessions(projectIds)\n\n    console.log(\"First project:\", projects[0])\n    console.log(\"First session:\", sessions[0])\n  } catch (error) {\n    console.error(\"Failed to fetch data:\", error)\n  } finally {\n    client.close()\n  }\n}\n\nrun()","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}