Opencode Personal Knowledge is a dual-interface knowledge management system designed for AI agents and power users. It combines a robust CLI for manual management with a Model Context Protocol (MCP) server that exposes your knowledge base to AI assistants (like Claude or Opencode Agents), enabling them to semantically search and retrieve information from your personal library.
!NOTE This tool uses hybrid search, combining standard SQLite text matching with LanceDB vector embeddings (via FastEmbed) for semantic understanding, ensuring high recall for both exact keywords and conceptual queries.
Clone the repository and install dependencies:
git clone https://github.com/NocturnLabs/opencode-personal-knowledge.git
cd opencode-personal-knowledge
bun install
Build the project:
bun run build
Link the binary globally:
bun link
bunxYou can run commands directly without installation:
bunx opencode-personal-knowledge --help
Start by adding your first knowledge entry. The database is automatically initialized on the first write.
# Add a simple text entry
pk add "TypeScript interface vs type" "Interfaces are better for objects, types for unions." --tags typescript,tips
# Add with source reference
pk add "React useEffect" "Runs after render. Cleanup function runs before next effect." --source "https://react.dev"
Once you have entries, vector embeddings are generated automatically. You can search by meaning, not just keywords.
# Search for concepts (even if words don't match exactly)
pk search "difference between types in TS"
To let AI agents access your knowledge, run the MCP server.
# Start the server (usually done by your AI client config)
pk mcp
# OR directly:
bun run src/mcp-server.ts
The system uses a two-layer storage approach to maximize reliability and searchability:
bun:sqlite~/.local/share/opencode-personal-knowledge/knowledge.dbget, list, stats, and text (keyword) search.~/.local/share/opencode-personal-knowledge/vectorsBGESmallENV15 (FlagEmbedding), running locally on CPU.search to find "nearest neighbors" in meaning.When you add, update, or delete an entry via the CLI or MCP, the service automatically coordinates between SQLite and LanceDB.
Each entry in the database follows this strict schema:
| Field | Type | Required | Description |
|---|---|---|---|
id | Integer | Yes | Unique auto-incrementing identifier. |
title | String | Yes | Short summary or headline. |
content | String | Yes | Full markdown or plain text body. |
source | String | No | URL, filepath, or citation string. |
tags | Array | No | List of categorization tags. |
created_at | ISO Date | Yes | Creation timestamp. |
updated_at | ISO Date | Yes | Last modification timestamp. |
The vector database stores a subset of data optimized for search:
| Field | Description |
|---|---|
vector | 384-dimensional float array (embedding). |
content_preview | First 500 characters of content. |
_distance | Internal metric for similarity ranking. |
The tool is zero-config by default, adhering to XDG Base Directory standards. However, you can override defaults:
| Variable | Default | Description |
|---|---|---|
OPENCODE_PK_DATA_DIR | ~/.local/share/opencode-personal-knowledge | Directory path for storing knowledge.db and vectors/. |
!IMPORTANT Changing
OPENCODE_PK_DATA_DIRwill result in an empty database unless you migrate existing files manually.
trustedDependencies (protobufjs, @biomejs/biome) for security compliance.The CLI is accessed via the pk alias (if linked) or bun run src/index.ts.
pk addAdd a new knowledge entry.
Usage:
pk add <title> <content> [options]
Options:
-s, --source <source>: Source URL or reference.-t, --tags <tags>: Comma-separated tags (e.g., "coding,tips").Example:
$ pk add "Vim Save" "Type :w to save" -t vim,editors
✅ Added entry #42: "Vim Save"
📊 Indexed for semantic search
pk searchSearch knowledge entries. Defaults to semantic search.
Usage:
pk search <query> [options]
Options:
-t, --text: Force keyword-only text search (bypasses vector DB).-l, --limit <number>: Max results (default: 5).Example:
$ pk search "how to write files in terminal editor"
Found 1 similar entries:
[42] Vim Save (89% similar)
Type :w to save...
Tags: vim, editors
pk getRetrieve a specific entry by ID.
Usage:
pk get <id>
Example:
$ pk get 42
# Vim Save
ID: 42
Created: 2024-12-14T10:00:00.000Z
Updated: 2024-12-14T10:00:00.000Z
Tags: vim, editors
Type :w to save
pk updateModify an existing entry.
Usage:
pk update <id> [options]
Options:
--title <text>--content <text>-s, --source <text>-t, --tags <text>Example:
$ pk update 42 --content "Type :w to save, :wq to save and quit"
✅ Updated entry #42
📊 Re-indexed
pk listList all entries chronologically.
Usage:
pk list [options]
Options:
-l, --limit <number>: Items per page (default: 20).-o, --offset <number>: Pagination offset.-t, --tags <tags>: Filter by tags.pk statsView database health and tag distribution.
Example:
$ pk stats
📊 Knowledge Base Stats
Total Entries: 156
Vectors Indexed: 156
Oldest: 2024-01-15T08:30:00.000Z
Newest: 2024-12-14T10:00:00.000Z
Top Tags:
typescript: 45
linux: 30
ideas: 12
pk vectorsDirect management of the vector database.
Subcommands:
convert: Scans SQLite and ensures all items are indexed in LanceDB. Useful after importing bulk data or if indexing failed.stats: Show vector specific stats.clear: Wipe the vector index (does not delete SQLite data).Example:
$ pk vectors convert
Converting entries to vectors...
Progress: 156/156
✅ Converted 156 entries (0 skipped)
When running as an MCP server (pk mcp), the following tools are exposed to AI agents.
| Tool | Description |
|---|---|
store_knowledge | Store a new knowledge entry with optional tags |
search_knowledge | Semantic similarity search |
search_knowledge_text | Keyword-based text search |
get_knowledge | Retrieve entry by ID |
update_knowledge | Update an existing entry |
delete_knowledge | Delete an entry |
list_knowledge | List entries with filters |
get_knowledge_stats | Database statistics |
Log and search across entire OpenCode conversations.
| Tool | Description |
|---|---|
start_logging_session | Begin logging a session |
log_message | Log a user/agent message to the session |
search_session | Semantic search within a session |
search_all_sessions | Search across ALL logged sessions |
list_sessions | List all sessions |
get_session | Get session details and messages |
end_session | End session with optional summary |
!TIP Session memory enables semantic search across past conversations. Start a session when debugging complex issues to review later.
User: "Start logging this session, call it 'auth debugging'"
Agent: Calls start_logging_session and logs exchanges:
✅ Started session #1: "auth debugging"
Later...
User: "Search this session for JWT"
Agent: Calls search_session:
Found 2 matches in session #1:
### 1. [user] (92% match)
The JWT token expires too fast...
### 2. [agent] (88% match)
The TTL is set to 60 instead of 3600...
OpenCode Forger: Autonomous Development Engine
OpenCode Forger is an elite Rust-based CLI orchestration tool designed to automate the "Vibe Loop" for OpenCode. It transforms high-level product specifications into production-ready codebases by managing an iterative cycle of implementation, verification, and refinement.
OpenCode Conductor
Context-Driven Development plugin for OpenCode that grounds AI agents in your project's mission, architecture, and standards.