Setup Guides/Kilo Code
Kilo Code

Memstate + Kilo Code

Give Kilo Code long-term memory that persists across VS Code sessions.

Kilo Code is a VS Code AI coding agent that starts fresh every session. Memstate gives Kilo Code a structured, versioned memory layer via MCP — so it remembers your architecture, past decisions, and project context without you having to re-explain everything.

1

Get Your API Key

Sign up for free — no credit card required.

Sign Up Free

Already have an account? Go to API Keys →

2

Add MCP Configuration

Add this to your Kilo Code MCP config file. Replace YOUR_API_KEY_HERE with your key.

MCP Configuration (JSON)
{
  "mcpServers": {
    "memstate": {
      "command": "npx",
      "args": ["-y", "@memstate/mcp"],
      "env": {
        "MEMSTATE_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}
📁

Save to:

.kilocode/mcp.json

Scoped to this project. Commit this file to share the Memstate setup with your team.

Opening Kilo Code MCP Settings

In VS Code, open the Kilo Code sidebar → click the Settings icon → Agent Behaviour tab → MCP Servers sub-tab → Edit Project MCP. This creates and opens .kilocode/mcp.json directly.

3

Add Agent Rule

This rule tells Kilo Code to load your project context before tasks and save summaries after — automatically, every session.

.kilocode/rules/use-memstate-memory.md
# Memstate MCP - Memory Storage

This project uses Memstate MCP for persistent, versioned memory across sessions.

## REQUIRED: Start and end every task with memory

**BEFORE starting any task**, load relevant context so you don't redo past work or revert intentional decisions. **Prefer targeted retrieval** — do not dump the full memory tree by default.

**Default — search by what you're working on:**
```
memstate_search(query="<task topic>", project_id="<your_project>")
```

**When you know the exact keypath — fetch that subtree only:**
```
memstate_get(project_id="<your_project>", keypath="<subtree>")
```

**Full tree (discovery only):** `memstate_get(project_id="<your_project>")` with **no keypath** returns **every memory** in the project. Use this only when you need to explore the full tree to discover keypaths and values — not as the default before every task.

**AFTER completing any task**, save what you did so the next session has context:
```
memstate_remember(project_id="<your_project>", content="## Task Summary\n- What was done\n- Key decisions made\n- Files modified", source="agent")
```

Reading before tasks and saving after are both important. Skipping them means the next session starts blind.

## Tool reference

| Tool | When to use |
|------|-------------|
| memstate_search | **Default before tasks.** Find relevant memories by meaning. Returns ranked results without flooding context. |
| memstate_get | Fetch a **specific subtree** when you know the keypath. With no keypath, returns the **full project tree** — discovery/exploration only. |
| memstate_remember | **End of every task.** Save markdown summaries, notes, decisions. |
| memstate_set | Store a single key=value fact (e.g. config.port). Not for summaries. |
| memstate_history | View version history of a keypath. |
| memstate_delete | Soft-delete a keypath (history preserved). |

## Project naming
Use a short snake_case name matching your repo or topic (e.g. my_app, api_service). All related memories should share the same project_id.

Create this file at: .kilocode/rules/use-memstate-memory.mdKilo rules docs

Test It — Onboard Your Project

Restart Kilo Code, open a project, and paste this prompt. It will create your first memories and confirm everything is working.

Replace <your_project> with a short name for your repo (e.g. my_app).

Paste into your AI agent
I'm onboarding Memstate AI memory for this project. Please:
1. Analyze this codebase and write a concise high-level architecture overview in markdown — covering the main components, tech stack, key directories, and how data flows through the system.
2. Save it to Memstate using: memstate_remember(project_id="<your_project>", content="<the markdown>", source="agent")
3. Then call memstate_search(query="architecture overview", project_id="<your_project>") and show me the results so I can confirm it worked.

What to expect

Your agent will analyze the codebase, write an architecture overview, save it to Memstate, then confirm with search results. You'll see structured memories like project.my_app.architecture — this context is now available in every future session automatically.