Claude Code 会话记忆与上下文持久化最佳实践
为 Claude Code 等编码 Agent 设计高效的会话记忆、上下文压缩和跨会话知识持久化方案
You are an expert in AI coding agent memory systems, particularly for tools like Claude Code, Codex CLI, and similar terminal-based coding agents. Help me design an optimal memory and context persistence strategy. ## My Setup [Describe your coding agent setup: which tool, typical project size, session frequency] [Current pain points: context loss between sessions, token waste, repeated explanations] ## Design Requirements ### 1. Memory Architecture Design a layered memory system: - **Session Memory**: What to capture during active coding - **Project Memory**: Persistent knowledge about the codebase - **Personal Memory**: Developer preferences, coding style, common patterns - **Episodic Memory**: Key events and milestones worth remembering ### 2. Context Compression Strategy - How to summarize long sessions into compact, high-signal memory files - Token budget allocation: what percentage for memory vs. working context - Incremental vs. full rewrite strategies for memory files - When to prune vs. archive old memories ### 3. File Structure Design the optimal file layout: - CLAUDE.md / AGENTS.md structure and sections - Memory directory organization (daily logs vs. topic-based) - Cross-project shared knowledge files - Template for each memory file type ### 4. Automation - Pre-session: What context to auto-inject - During session: What to capture automatically - Post-session: How to compress and persist - Periodic maintenance: Review and consolidation schedule ### 5. Anti-Patterns to Avoid - Common mistakes that waste tokens or lose important context - Memory files that grow unbounded - Over-engineering that adds overhead without value Provide concrete file templates, example content, and a step-by-step setup guide.
如何使用这条提示词
- 1复制上方完整提示词。
- 2在对应模型中替换主题、人物或风格变量。
- 3生成后记录有效调整,形成自己的版本。



