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

chat-history-logger-plugin-opencode-claudecode

v0.1.1

Published

Install chat history logger plugin for OpenCode or hook for Claude Code. Logs all conversations to Markdown files with optional MongoDB/Supabase cloud sync for cross-device access.

Readme

Chat History Logger Plugin for OpenCode and Hook for Claude Code

A plugin for OpenCode and a hook for Claude Code that automatically logs all conversations between you and your AI coding assistant to readable Markdown files, directly in your own working folder, and can be mixed if you decide to work with OpenCode today and Claude Code tomorrow (and vice versa).

This plugin works with both OpenCode and Claude Code. Optionally, you can sync your chat history to MongoDB or Supabase for cloud backup and cross-device access.

Chat History Sync Example

Quick Installation (Recommended)

Run one command in your project directory:

# Interactive — prompts you to choose OpenCode or Claude Code
npx chat-history-logger-plugin-opencode-claudecode@latest

# Or specify directly
npx chat-history-logger-plugin-opencode-claudecode@latest --opencode
npx chat-history-logger-plugin-opencode-claudecode@latest --claude

The installer handles everything: copies files, installs dependencies, configures hooks/plugins, and sets file permissions.

To install for both runtimes, run the command twice — once with --opencode and once with --claude. They coexist without conflicts.

Uninstall:

npx chat-history-logger-plugin-opencode-claudecode@latest --opencode --uninstall
npx chat-history-logger-plugin-opencode-claudecode@latest --claude --uninstall

Run npx chat-history-logger-plugin-opencode-claudecode@latest --help for all options.

IMPORTANT: I did not add one .md file in chat_history folder to .gitignore here, just so you will be able to see how it looks like when you want to store the chat history locally. But, if you want to use this plugin, you should add the entire files in the chat_history folder to your .gitignore so you won't accidentally commit your chat history to GitHub or Gitlab.

IMPORTANT 2: For cloud sync, you must make sure there's only one provider there at a time (either MongoDB or Supabase). The command prompt attached to the slash commands will make sure of it, but you should always double-check. Also, once the AI assistant creates chat-history-cloud-config.json, it should automatically try to create chat-history-cloud-enabled file with "enabled" content.

If for whatever reason this file is not created, you can create it manually. Just check the content of chat-history-enabled in this repository, copy-paste it to a new file with the name chat-history-cloud-enabled in the same folder. That's it.

How It Works

Both implementations follow the same pattern:

  1. Intercept messages - Capture user prompts and assistant responses as they happen (right now it doesn't include the thinking, to-do, and the edits to the files)
  2. Format cleanly - Structure output as Markdown with timestamps
  3. Append to daily files - Write to chat_history/YYYY_MM_DD.md, append when the file already exists
  4. Toggle control - Enable/disable via a simple flag file
  5. Cloud sync (optional) - Sync messages to MongoDB or Supabase in real-time

Output Format

# Chat History - Tuesday, February 10, 2026

---

### User [14:32]

Hello, Claude Code. How are you?

---

### Assistant [14:32]

Hello! I'm doing great, thank you for asking. I'm available and ready to help you with anything you need.

---

For Manual Installation

If you prefer to set things up manually:

For OpenCode

  1. Copy the .opencode folder to your project root
  2. Create the enable flag: touch .opencode/chat-history-enabled if it's not there already

The plugin should be configured in .opencode/opencode.json:

{
  "plugin": ["./plugins/chat-history-logger.ts"]
}

Create .opencode/package.json and make sure it has the plugin dependencies. As of this writing, here are the versions that I use:

{
  "dependencies": {
    "@opencode-ai/plugin": "1.1.63",
    "@supabase/supabase-js": "^2.49.1",
    "bson": "^7.2.0",
    "mongodb": "^6.12.0"
  }
}

Then install dependencies:

cd .opencode && npm install

For Claude Code

  1. Copy the .claude folder to your project root
  2. Create the enable flag: touch .claude/chat-history-enabled if it's not there already

The hook is configured in .claude/settings.json to run on:

  • UserPromptSubmit - Captures your prompts
  • Stop - Captures assistant responses when the turn completes

Install Python packages (for cloud sync):

pip install pymongo supabase

For further guide on cloud sync, check the Cloud Sync section below.

Usage for Local Chat History

Once installed, logging happens automatically. Your conversations appear in chat_history folder in the project root directory.

chat_history/
  2026_02_08.md
  2026_02_09.md
  2026_02_10.md

IMPORTANT: You should add chat_history folder to your .gitignore so you won't accidentally commit your chat history to GitHub or Gitlab.

Enable/Disable Logging

OpenCode:

# Enable (creates flag file)
touch .opencode/chat-history-enabled

# Disable (removes flag file)
rm .opencode/chat-history-enabled

Claude Code:

# Enable
touch .claude/chat-history-enabled

# Disable
rm .claude/chat-history-enabled

Search Your History

# Find all discussions about "authentication"
grep -r "authentication" chat_history/

# Find what you discussed on a specific day
cat chat_history/2026_02_10.md

# Search with ripgrep for better formatting
rg "async" chat_history/ -C 2

Cloud Sync

Chat history cloud sync supports MongoDB and Supabase.

Quick Setup

The fastest way to set up cloud sync is via slash commands after you enter opencode or claude code:

/chat-history-cloud-config

The command will guide you through provider selection and configuration. Once you are done with the configuration, you may unexpectedly see some stdout and stderr messages. Just exit and reinitiate your session with OpenCode or Claude Code.

REMINDER: As mentioned above, for cloud sync, you must make sure there's only one provider there at a time (either MongoDB or Supabase). The command prompt attached to the slash command /chat-history-cloud-config will make sure of it, but you should always double-check. Also, once the AI assistant creates chat-history-cloud-config.json, it should automatically try to create chat-history-cloud-enabled file with "enabled" content.

If for whatever reason this file is not created, you can create it manually. Just check the content of chat-history-enabled in this repository, copy-paste it to a new file with the name chat-history-cloud-enabled in the same folder. That's it.

Manual Setup

1. Enable Cloud Sync

touch .opencode/chat-history-cloud-enabled

Make sure the content of this file is "enabled", exactly like chat-history-enabled

2. Create Configuration File

Create the config file with your cloud provider details.

For OpenCode: .opencode/chat-history-cloud-config.json For Claude Code: .claude/chat-history-cloud-config.json

MongoDB Configuration
{
  "provider": "mongodb",
  "connectionString": "mongodb+srv://username:[email protected]",
  "database": "your_db_name",
  "collection": "your_collection_name"
}
Supabase Configuration
{
  "provider": "supabase",
  "supabase_url": "https://your-project.supabase.co",
  "supabase_key": "your-anon-or-service-key",
  "supabase_table": "chat_history"
}

For Supabase, you need to create the table first. Run this SQL in the Supabase SQL Editor:

CREATE TABLE chat_history (
    id BIGSERIAL PRIMARY KEY,
    session_id TEXT NOT NULL,
    timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    date TEXT NOT NULL,
    role TEXT NOT NULL CHECK (role IN ('user', 'assistant')),
    content TEXT NOT NULL,
    source TEXT NOT NULL DEFAULT 'opencode',
    project_path TEXT,
    project_name TEXT,
    local_file TEXT,
    message_id TEXT,
    truncated BOOLEAN DEFAULT FALSE
);

3. Security

Add the cloud config files to your .gitignore to avoid committing credentials:

.opencode/chat-history-cloud-config.json
.claude/chat-history-cloud-config.json

Slash Commands

Both OpenCode and Claude Code support the following slash commands for managing cloud sync:

| Command | Description | |---------|-------------| | /chat-history-cloud-config | Update and guide you to the cloud sync configuration | | /chat-history-on | Enable local chat history logging | | /chat-history-off | Disable local chat history logging | | /chat-history-cloud-on | Enable cloud sync | | /chat-history-cloud-off | Disable cloud sync | | /chat-history-cloud-status | Check status of local logging and cloud sync |

The source field is either "opencode" or "claude-code", allowing you to append conversations from both tools into the same database.

Note: If a chat response exceeds 14MB, the content will be truncated and "...." will be appended. The truncated field in metadata will be set to true so you can query for truncated messages.

How Cloud Sync Works

  • Non-blocking: Cloud sync happens asynchronously. If the cloud connection fails, local logging continues normally.
  • Real-time: Each message is synced immediately after being logged locally.
  • Resilient: Connection errors are caught and logged to stderr, but never break local functionality.
  • Dynamic: The OpenCode plugin re-checks the cloud config on each event cycle, so you can enable/disable cloud sync without restarting.

License

MIT

Troubleshoot

If you encounter issue with OpenCode not working properly with cloud sync (e.g, with Supabase connection), you can try to delete the node_modules folder, delete package-lock.json, and try again with npm install

cd .opencode
rmdir /s node_modules
del package-lock.json

npm install