Skip to main content

Persistent memory system for Kimi Code CLI โ€” remember context across sessions

Project description

๐Ÿง  kimi-mem

PyPI Python License Tests

Persistent memory system for Kimi Code CLI.
Remember context across sessions. Never repeat yourself.

Inspired by claude-mem, built for the Kimi ecosystem.


โœจ Features

  • ๐Ÿ” Persistent Memory โ€” Context survives across Kimi sessions
  • ๐Ÿช Native Hooks โ€” Uses Kimi CLI's built-in lifecycle hooks (Beta)
  • ๐Ÿ” Full-Text + Semantic Search โ€” SQLite FTS5 + sqlite-vec for hybrid retrieval
  • ๐ŸŽฏ Progressive Disclosure โ€” 3-layer retrieval: index โ†’ timeline โ†’ get
  • ๐Ÿค– AI Summarization โ€” Automatically compresses sessions into actionable memories via Moonshot API
  • ๐Ÿท๏ธ Tagged & Typed โ€” Memories categorized as pattern, decision, bugfix, architecture
  • ๐Ÿ”’ Privacy Tags โ€” <private> blocks are automatically excluded from search/storage
  • ๐ŸŒ Web Viewer โ€” Local dashboard at http://localhost:37777
  • ๐ŸŒ™ Token-Efficient โ€” Injects only the most relevant memories, respects context limits
  • โšก Zero External Services โ€” SQLite is all you need; vector search included

๐Ÿ“ฆ Installation

1. Install the package

pip install kimi-mem

# With web viewer support
pip install "kimi-mem[web]"

Or from source:

git clone https://github.com/theretech/kimi-mem.git
cd kimi-mem
pip install -e ".[web]"

2. Install hooks into Kimi CLI

kimi-mem install

This appends hook entries to your ~/.config/kimi/config.toml.

๐Ÿ”„ Restart Kimi Code CLI for the hooks to take effect.

3. Set your API key (optional, for AI summarization)

export KIMI_API_KEY="your-moonshot-api-key"

If not set, kimi-mem still works โ€” it just won't auto-summarize sessions with AI.


๐Ÿš€ Quick Start

Let it run automatically

Once installed, kimi-mem works in the background:

  1. Start a Kimi session โ†’ relevant memories are injected into .kimi/session-memory.md
  2. Use tools (ReadFile, Shell, etc.) โ†’ observations are captured silently
  3. End the session โ†’ session is summarized and memories are stored

CLI Commands

# Search your memory (full-text)
kimi-mem search "authentication bug"

# Semantic search (vector)
kimi-mem search "how to handle jwt errors" --semantic

# Progressive disclosure
kimi-mem index "database migration"           # Layer 1: compact index
kimi-mem timeline <id>                        # Layer 2: chronological context
kimi-mem get <id>                             # Layer 3: full detail

# Recent memories
kimi-mem recent --limit 5

# Add a memory manually
kimi-mem add "Use jwt.ParseWithClaims for custom claims" \
  --type pattern --tag go --tag jwt

# Start web viewer
kimi-mem serve

# Check status
kimi-mem status

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Kimi CLI   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   Hooks     โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  kimi-mem core  โ”‚
โ”‚  (session)  โ”‚     โ”‚ (config.toml)โ”‚     โ”‚  (Python + SQLite)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  SQLite + FTS5  โ”‚
              โ”‚  + sqlite-vec   โ”‚
              โ”‚  (memories +    โ”‚
              โ”‚   observations) โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Hooks used

Event What it does
SessionStart Retrieves relevant memories โ†’ writes .kimi/session-memory.md
PostToolUse Captures tool calls/outputs as observations
Stop / SessionEnd Summarizes session with AI โ†’ stores compressed memories

Progressive Disclosure (3 layers)

Inspired by claude-mem, kimi-mem uses token-efficient layered retrieval:

Layer Command Tokens Purpose
L1 kimi-mem index <query> ~50-100/result Compact preview with IDs
L2 kimi-mem timeline <id> ~200-500/result Chronological context around a memory
L3 kimi-mem get <id> ~500-1000/result Full content + metadata

๐Ÿ”’ Privacy

kimi-mem respects your privacy:

  • <private>...</private> tags in any content are automatically detected and excluded from search, vector index, and session injection
  • Private memories are still stored (for your reference) but never retrieved automatically
  • Heuristics detect secrets, passwords, and API keys in observations
  • Use --include-private to explicitly search private memories

โš™๏ธ Configuration

Environment variables:

Variable Description Default
KIMI_API_KEY Moonshot API key for summarization โ€”
KIMI_MEM_DATA_DIR Where to store the SQLite DB ~/.kimi-mem
KIMI_MEM_DB_PATH Direct path to SQLite file ~/.kimi-mem/memory.db
KIMI_MEM_MODEL Model for summarization moonshot-v1-8k
KIMI_MEM_EMBEDDING_MODEL Model for embeddings moonshot-v1-embedding
KIMI_MEM_EMBEDDING_DIM Embedding dimension 1024

๐Ÿ› ๏ธ Development

# Setup
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,web]"

# Run tests
pytest

# Lint
ruff check .

# Format
ruff format .

๐Ÿ“‹ Roadmap

  • SQLite + FTS5 persistent storage
  • Native Kimi CLI hooks
  • AI-powered session summarization
  • Semantic vector search (sqlite-vec)
  • Progressive disclosure (3-layer retrieval)
  • Web viewer dashboard
  • Privacy tags (<private> exclusion)
  • PyPI publication
  • Cross-project memory linking
  • Memory import/export
  • Team/shared memory

๐Ÿค Contributing

This is an early alpha built by the community for the community.
PRs, issues, and ideas are welcome!

  1. Fork the repo
  2. Create a feature branch
  3. Make your changes
  4. Submit a PR

๐Ÿ“„ License

MIT โ€” see LICENSE for details.


Built with ๐ŸŒ™ by The Retech and friends.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kimi_mem-0.1.1.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kimi_mem-0.1.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file kimi_mem-0.1.1.tar.gz.

File metadata

  • Download URL: kimi_mem-0.1.1.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kimi_mem-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a58023130d36deb298606ff99a5226bc844cde33b9facb5d684b889522d947fa
MD5 1068dc7bafc2c0a00c5a9c3cd9ce6519
BLAKE2b-256 d822ced1f431faa54a09d3e538b468d0ee109975778559e3b368e4673ebd94fe

See more details on using hashes here.

File details

Details for the file kimi_mem-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kimi_mem-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kimi_mem-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f16d3d0fb64d660c396db6928cd8c327ca830dbc34f95fa0cf8afcc0c00b8ec4
MD5 6e158b33e98c0d579ee08a11f8822907
BLAKE2b-256 e9072a6d309f18b28e3694e8347eb6fba51e3b188f804296b442ebc21b9e4c1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page