npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-db-search

v1.1.0

Published

Search and inspect the OpenCode SQLite database from the command line

Readme

opencode-db-search

Where did my session go?

A CLI tool for searching and inspecting OpenCode sessions directly from the SQLite database -- without the filters, lookback windows, or project scoping that can hide them in the TUI.

The problem

OpenCode's session list applies several invisible filters:

  • 30-day lookback -- sessions older than 30 days disappear from the TUI
  • Project scoping -- only sessions matching the current git repo are shown
  • Fork filtering -- subagent/fork sessions are hidden by default
  • Channel isolation -- dev builds (opencode-local.db) and release builds (opencode.db) use separate databases

When a session goes missing, there's no built-in way to find it. This tool queries the raw SQLite database with no filters, so you can always find any session.

Install

Requires Bun v1.0+.

# From npm
bun install -g opencode-db-search

# From GitHub
bun install -g github:rmk40/opencode-db-search

# From a local clone
git clone https://github.com/rmk40/opencode-db-search && cd opencode-db-search && bun link

If ~/.bun/bin is not on your PATH, add it:

export PATH="$HOME/.bun/bin:$PATH"

Quick start

# What databases exist?
opencode-db-search dbs

# List all sessions across all projects
opencode-db-search sessions --all

# Search for a session by keyword
opencode-db-search search "refactor auth"

# Why isn't -c picking my session?
opencode-db-search latest

# Get full details on a session
opencode-db-search inspect ses_abc123...

# Open a session in OpenCode
opencode-db-search load ses_abc123...

Example output

$ opencode-db-search sessions --all --limit 5
┌──────────────────────────┬───────────────────────────┬──────────────────────────┬──────────┬──────┐
│ ID                       │ Title                     │ Directory                │ Updated  │ Msgs │
├──────────────────────────┼───────────────────────────┼──────────────────────────┼──────────┼──────┤
│ ses_27b4926f3ffe9q475j…  │ Refactor auth middleware  │ /home/user/projects/app  │ just now │  142 │
│ ses_2be0ef954ffeImu3vl…  │ Fix pagination bug        │ /home/user/projects/api  │ 1h ago   │ 1050 │
│ ses_2957fa195ffemZs3FU…  │ Add dark mode             │ /home/user/projects/web  │ 3h ago   │   64 │
│ ses_2c40c9050ffeYUwQ75…  │ Deploy pipeline           │ /home/user/infra         │ 2d ago   │  737 │
│ ses_1b632aafa8931d2e61…  │ Initial setup             │ /home/user/projects/app  │ 12d ago  │   79 │
└──────────────────────────┴───────────────────────────┴──────────────────────────┴──────────┴──────┘
5 session(s)
$ opencode-db-search latest
Project
ID      4b0ea68d7af9a6031a7ffda7ad66e0cb83315750
Source  inferred from cwd

TUI mode (-c)
Session    ses_27b4926f3ffe9q475jVn131I3j
Title      Refactor auth middleware
Updated    2026-04-13 03:40:18
Directory  /home/user/projects/app

Headless mode (run -c)
  Same as TUI mode

Root sessions       12
Outside 30d window  3

Commands

| Command | Description | | ---------------- | --------------------------------------------------------- | | dbs | List available database files with size, age, and channel | | projects | List all projects with session counts | | sessions | List sessions with filtering by project, date, status | | messages <id> | Show messages in a session | | parts <id> | Show message parts (text, tool calls, reasoning) | | search <query> | Full-text search across titles and content | | inspect <id> | Detailed session info: stats, tokens, cost, todos | | latest | Debug why -c picks (or doesn't pick) a session | | load <id> | Open a session directly in OpenCode |

Every command supports --json for machine-readable output.

Key flags

# Show sessions from all projects, not just current
opencode-db-search sessions --all

# Include archived and fork sessions
opencode-db-search sessions --archived --forks

# Filter by date range
opencode-db-search sessions --since 2024-01-01 --before 2024-02-01

# Use a specific database file
opencode-db-search sessions --db ~/.local/share/opencode/opencode-local.db

# Search only titles, or only content
opencode-db-search search "query" --scope title
opencode-db-search search "query" --scope content

# Preview what load would do
opencode-db-search load ses_abc123 --dry-run

How it finds the database

  1. --db <path> flag (explicit)
  2. $OPENCODE_DB environment variable
  3. --channel <name> flag (local -> opencode-local.db, etc.)
  4. Auto-detect: most recently modified opencode*.db in ~/.local/share/opencode/

How it scopes to your project

By default, sessions and latest filter to the current project, inferred from:

  1. Cached ID in .git/opencode (matches OpenCode's own logic)
  2. Git root commit hash
  3. Falls back to "global" outside git repos

Use --all to see everything, or --project <id> to target a specific project.

License

MIT