English
Context & Prompt Caching
Long coding sessions get slow and expensive fast when every turn invalidates the provider's prompt cache. Most cache misses happen for avoidable reasons: putting current timestamps in the system prompt, mutating the tool list mid-session, or rewriting earlier messages.
iKi avoids those traps by keeping the front of every request as stable as possible.
Keep the System Prompt Fixed
Every request builds the system prompt in one place (@iki/system-prompt) in a fixed order:
- Your persona file (
~/.iki/PERSONA.md) — date-only, never per-second timestamps. - Static instructions for the active built-in tools.
- Any role-specific prompt (such as a Swarm coordinator).
- Project context (
AGENTS.md) and the static skills index.
Because none of these change from turn to turn—and the top-level tool list stays fixed in MCP Code Mode—the entire leading prefix stays byte-for-byte identical.
Pass Changes Forward, Never Backwards
Things do change during a session: you connect or disconnect an MCP server, enable a skill, or switch workspace state. Instead of editing the system prompt (which would bust the cache for the whole conversation), iKi appends a small <system_reminder> note right before the user turn where the change happened:
- Runtime facts (current workspace path and OS).
- Newly enabled skills (recorded once, not repeated on later turns).
- MCP server additions, tool updates, or disconnects (diff-only).
Earlier turns stay untouched, so everything before the change remains cached.
History Replay & Compaction
- Clean replay: Multi-step tool calls are replayed in exact
[assistant, tool, assistant, ...]order without extra wrapper layers, and every provider call passessessionId: threadIdto preserve cache affinity. - Compaction: When a thread approaches the context limit—or when you run
/compact—iKi summarizes older turns, writes a checkpoint event to~/.iki/sessions/<threadId>.jsonl, and continues cleanly from that summary without losing the raw log on disk.