LIVE DEMO → Home Product
FeaturesUse CasesCompareEnterprise
Docs
DocumentationQuickstartMCP ServerIntegrations
Pricing Blog DASHBOARD → LOG IN →
Tutorial MCP OpenCode May 4, 2026 · 7 min read

Persistent Memory for
OpenCode via MCP

OpenCode is a fast, open-source terminal AI coding tool built in Go — think Claude Code but fully open and model-agnostic. It lives in your terminal, has no GUI to paste context into, and supports MCP servers natively. This guide shows you how to connect Kronvex persistent memory so OpenCode actually remembers what happened in previous sessions.

In this article
  1. What is OpenCode?
  2. Why terminal AI coding needs memory most
  3. Prerequisites
  4. Configure Kronvex MCP in opencode.json
  5. Global vs project-level configuration
  6. Verify the MCP connection
  7. Using memory in OpenCode sessions
  8. Custom agent instructions for memory
  9. Real-world use cases
  10. Tips and best practices

What is OpenCode?

OpenCode is a terminal-based AI coding assistant written in Go, designed to be the open-source answer to tools like Claude Code and Gemini CLI. It provides an autonomous agent loop that can read files, run shell commands, apply code edits, and iterate on tasks — entirely from the terminal without requiring VS Code or any other editor.

Key characteristics that differentiate OpenCode:

Why terminal AI coding needs memory most

Terminal AI tools face an acute version of the memory problem. In VS Code, you can at least keep a chat window open across sessions and scroll back through history. In a terminal TUI, when you close OpenCode, that history is gone. There's no GUI state to preserve, no chat history panel to re-read — you start from blank every time.

The consequences compound quickly on real engineering work:

Kronvex solves this at the protocol layer. The MCP server runs as a subprocess managed by OpenCode, and the agent can call memory tools as naturally as it calls bash commands or reads files.

Prerequisites

Configure Kronvex MCP in opencode.json

OpenCode reads its configuration from ~/.config/opencode/opencode.json (global) or .opencode/opencode.json in the current project directory (project-local). Add the Kronvex MCP server under the mcp key:

opencode.json — Kronvex MCP server
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-6",
  "mcp": {
    "kronvex": {
      "type": "local",
      "command": [
        "npx",
        "-y",
        "@kronvex/mcp-server"
      ],
      "environment": {
        "KRONVEX_API_KEY": "kv-your-api-key-here",
        "KRONVEX_AGENT_ID": "your-agent-uuid-here"
      }
    }
  }
}
Environment variable substitution: OpenCode supports reading values from your shell environment. Instead of hardcoding credentials, use: "KRONVEX_API_KEY": "$KRONVEX_API_KEY" — OpenCode will substitute the value from your shell's environment at runtime. Add export KRONVEX_API_KEY="kv-..." to your .bashrc or .zshrc.

Global vs project-level configuration

OpenCode supports two levels of configuration that merge at runtime:

.opencode/opencode.json — project-local override
{
  "mcp": {
    "kronvex": {
      "type": "local",
      "command": ["npx", "-y", "@kronvex/mcp-server"],
      "environment": {
        "KRONVEX_API_KEY": "$KRONVEX_API_KEY",
        "KRONVEX_AGENT_ID": "project-specific-agent-uuid",
        "KRONVEX_DEFAULT_SESSION": "my-api-service"
      }
    }
  }
}
Should you commit .opencode/opencode.json? Yes — but only if you use environment variable substitution ($KRONVEX_API_KEY) rather than hardcoded keys. The project config file itself is safe to commit; the actual secret stays in each developer's shell environment.

Verify the MCP connection

Start OpenCode in your project directory. When it initialises, it will spin up the Kronvex MCP server as a background subprocess. You can verify the connection from the OpenCode TUI:

1
Run opencode in your terminal to start the TUI
2
Press / or open the command palette and type mcp
3
Select MCP Servers — you should see kronvex listed as connected with the available tools
4
In the chat, type: "Use Kronvex to recall anything relevant to this project." — the agent should call kronvex_inject_context or kronvex_recall

If the server fails to connect, check that Node.js is available in the PATH that OpenCode uses. On macOS with nvm or fnm, you may need to hardcode the node path: replace "npx" with "/Users/you/.nvm/versions/node/v20.0.0/bin/npx".

Using memory in OpenCode sessions

Once connected, the Kronvex tools are available to the agent. The MCP server exposes five tools:

You can ask the agent to use these tools in natural language:

OpenCode chat — natural language memory commands
# Store a decision
Remember that we're using Temporal.io for workflow orchestration,
not a custom queue. Decision was made to avoid reimplementing retry logic.

# Retrieve context before a task
Before we start, recall everything you know about our payment integration.

# Search for a specific past event
Have we encountered race conditions in this codebase before?

# Store a procedural pattern
Remember as a procedural memory: always run 'go vet ./...' before
submitting PRs in this repo. CI checks it but local dev often misses it.

Custom agent instructions for memory

OpenCode supports custom agent instructions through the instructions field in opencode.json. Adding memory instructions here ensures the agent uses Kronvex proactively without needing to be prompted every session:

opencode.json — agent instructions with memory
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-6",
  "instructions": "You have access to persistent memory via Kronvex MCP tools. At the start of each new task, call kronvex_inject_context with the task description to retrieve relevant past decisions and context. After completing significant work — architectural decisions, root cause findings, important patterns — call kronvex_remember to store them. Use memory_type semantic for facts, episodic for events, procedural for recurring patterns. Always include session_id matching the project name.",
  "mcp": {
    "kronvex": {
      "type": "local",
      "command": ["npx", "-y", "@kronvex/mcp-server"],
      "environment": {
        "KRONVEX_API_KEY": "$KRONVEX_API_KEY",
        "KRONVEX_AGENT_ID": "$KRONVEX_AGENT_ID"
      }
    }
  }
}

Real-world use cases

Remote server coding over SSH

One of the most compelling use cases for OpenCode + Kronvex is coding on remote servers over SSH. When you SSH into a production server to diagnose an issue, OpenCode runs in the terminal and can recall previous debugging sessions, known failure modes, and runbook knowledge. When the SSH session ends, the memories persist in Kronvex — so the next engineer who connects has the benefit of your work.

Infrastructure-as-code development

Terraform and Pulumi codebases accumulate layers of decisions over years — why a specific resource was named a certain way, why a default was overridden, what the blast radius of a change is. Storing this as procedural and semantic memories in Kronvex means OpenCode can surface "we disabled deletion protection on this bucket during the 2025-08 migration — do not re-enable until the data pipeline is updated" before any agent makes a destructive change.

Multi-service backend development

When working across multiple microservices, use different Kronvex agents per service with a shared session_id for cross-service concerns (shared API contracts, service mesh config, shared database schemas). OpenCode can pull relevant context from the right scope depending on what it's working on.

Tips and best practices

Terminal-specific memory patterns

Terminal AI tools tend to work on tasks that have clearer start and end points than chat-based GUI tools. Use this structure: at the start of a task, explicitly ask the agent to recall context. At the end, explicitly ask it to summarize and store. This two-step pattern gives you the most reliable memory persistence.

SSH and remote server memory

When using OpenCode on a remote server, the Kronvex MCP server runs on the remote machine (where OpenCode is running) and makes outbound HTTPS calls to api.kronvex.io. Ensure the remote server has outbound internet access on port 443 and Node.js installed. If Node.js is not available, consider using the Kronvex REST API directly with curl-based memory scripts instead.

Give OpenCode persistent memory across every session

Free plan — 500 memories, 3 agents. No credit card. Ready in 3 minutes.

Get your free API key →

Or read the full OpenCode integration docs

Integration guide
OpenCode Persistent Memory — Setup Guide
Step-by-step setup · code snippets · 2 min
Read the guide →
Related articles
Free demo key
Try Kronvex free
Get a demo API key instantly. No credit card required.