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.
Maintainers
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.

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 --claudeThe 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 --uninstallRun 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:
- 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)
- Format cleanly - Structure output as Markdown with timestamps
- Append to daily files - Write to
chat_history/YYYY_MM_DD.md, append when the file already exists - Toggle control - Enable/disable via a simple flag file
- 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
- Copy the
.opencodefolder to your project root - Create the enable flag:
touch .opencode/chat-history-enabledif 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 installFor Claude Code
- Copy the
.claudefolder to your project root - Create the enable flag:
touch .claude/chat-history-enabledif it's not there already
The hook is configured in .claude/settings.json to run on:
UserPromptSubmit- Captures your promptsStop- Captures assistant responses when the turn completes
Install Python packages (for cloud sync):
pip install pymongo supabaseFor 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.mdIMPORTANT: 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-enabledClaude Code:
# Enable
touch .claude/chat-history-enabled
# Disable
rm .claude/chat-history-enabledSearch 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 2Cloud 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-configThe 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-enabledMake 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.jsonSlash 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