MoonshotAI / MoonshotAI/kimi-code

Cross-session personal memory (memory.md + auto memory)

Open
#1,335 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What feature would you like to see?

Each session starts fresh — the agent has no memory of user preferences, project patterns, or lessons learned from previous sessions. Users repeatedly provide the same context ("I use uv not pip", "reply in Chinese", "push directly without asking"). This wastes tokens and degrades the experience over time.

Current state

Kimi Code has AGENTS.md for project/team instructions (loaded via profile/context.ts), but:

  • No mechanism for personal, cross-session preferences (e.g. "I prefer uv over pip")
  • No mechanism for the agent to learn from past sessions (e.g. "this project uses pnpm test, not npm test")
  • ContextMemory and compaction are session-scoped — nothing survives session end
Comparison with other agents
Agent Manual memory Auto memory
Claude Code CLAUDE.md Auto Memory (~/.claude/memdir/, AI-extracted)
Codex CLI AGENTS.md Memories (~/.codex/memories/, async background)
kimi-code AGENTS.md None
Proposed approach

A two-phase design that reuses existing infrastructure (AGENTS.md loading, injection system, compaction hooks).

Phase 1: Manual memory file (MVP)

Load memory.md files alongside AGENTS.md, injected into the system prompt as a separate section:

~/.kimi-code/memory.md          ← User-global personal preferences
.kimi-code/memory.md            ← Project-level personal memory (gitignored)

Example ~/.kimi-code/memory.md:

## Preferences
- Use `uv` for Python package management
- Push directly after commit, no need to confirm
- Reply in Chinese

## Workflow
- Run tests with `pnpm test` before committing

Why a separate file instead of extending AGENTS.md:

  • AGENTS.md is team-shared (checked into VCS); personal preferences shouldn't be
  • Different precedence and lifecycle — memory.md is personal, AGENTS.md is project/team
  • Keeps the conceptual boundary clean: AGENTS.md = instructions, memory = preferences/learnings

Implementation surface (small):

  • profile/context.ts: add loadMemory() mirroring loadAgentsMdForRoots()
  • profile/types.ts: add memory?: string to SystemPromptContext
  • profile/default/system.md: add {{ KIMI_MEMORY }} section
  • Tests in test/profile/context.test.ts
Phase 2: Auto memory (follow-up)

Agent extracts durable facts from sessions and writes them to ~/.kimi-code/memories/<project>/memory.md:

  • Triggered after compaction (reuse PostCompact hook) or on session end
  • A new remember tool lets the agent actively save a note
  • Loaded at session start, capped at a token budget (like Claude Code's 200-line / 25KB limit)
  • User can audit/edit via /memory command
Design principles
  1. File-based, no new dependencies — plain Markdown, same as AGENTS.md
  2. Reuse existing patterns — loading, merging, injection all mirror AGENTS.md
  3. User-controlled — files are readable/editable, auto-memory can be disabled
  4. Decoupled from compaction — compaction is session-scoped; memory is cross-session

Additional information

Phase 1 is a small, self-contained change (~4 files). Happy to implement it as a PR once there's alignment on the approach.

Key design decisions that could use maintainer input:

  1. Separate memory.md file vs. extending AGENTS.md with a personal section — I lean toward separate for the reasons above, but open to alternatives
  2. Project-level memory.md default .gitignore behavior — should kimi-code auto-add it?
  3. Token budget for memory content (Claude Code uses 25KB; kimi-code's AGENTS.md uses 32KB recommended max)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with profile/context.ts and loadAgentsMdForRoots(), then inspect profile/types.ts, profile/default/system.md, and test/profile/context.test.ts. Determine the agreed Phase 1 behavior for global and project memory files, precedence, limits, and gitignore handling before implementation. Done means the accepted memory-loading and system-prompt behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.