目录

Claude Code Context Compact

目录

这一节我们来学习 Claude Code 里 Context Compact。

1. Compact


English 中文

Your task is to create a detailed summary of the conversation so far, paying close attention to the user’s explicit requests and your previous actions. This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.

你的任务是创建迄今为止对话的详细摘要,密切关注用户的明确请求和你之前的操作。 此摘要应全面捕捉技术细节、代码模式和架构决策,这些对于在不丢失上下文的情况下继续开发工作至关重要。

Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you’ve covered all necessary points. In your analysis process:

在提供最终摘要之前,将你的分析放在 <analysis> 标签中,以组织你的思路并确保你已覆盖所有必要要点。在你的分析过程中:

  1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
    • The user’s explicit requests and intents
    • Your approach to addressing the user’s requests
    • Key decisions, technical concepts and code patterns
    • Specific details like:
      • file names
      • full code snippets
      • function signatures
      • file edits
  • Errors that you ran into and how you fixed them
  • Pay special attention to specific user feedback that you received, especially if user told you to do something differently.
  1. 按时间顺序分析对话的每条消息和每个部分。对每个部分彻底识别:
    • 用户的明确请求和意图
    • 你处理用户请求的方法
    • 关键决策、技术概念和代码模式
    • 具体细节,如:
      • 文件名
      • 完整代码片段
      • 函数签名
      • 文件编辑
  • 你遇到的错误以及你如何修复它们
  • 特别注意你收到的具体用户反馈,尤其是用户告诉你以不同方式做事的时候。
  1. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
  1. 反复检查技术准确性和完整性,彻底处理每个必要元素。

Your summary should include the following sections:

你的摘要应包含以下部分:

  1. Primary Request and Intent: Capture all of the user’s explicit requests and intents in detail
  2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
  3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
  4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
  5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
  6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users’ feedback and changing intent.
  7. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
  8. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets as applicable.
  9. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user’s explicit requests, and the task you were working on immediately before this summary. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests without confirming with the user first. If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure that there is no drift in task interpretation.
  1. 主要请求和意图:详细捕捉用户的所有明确请求和意图
  2. 关键技术概念:列出所有讨论过的重要技术概念、技术和框架。
  3. 文件和代码部分:列举已检查、修改或创建的具体文件和代码部分。特别关注最新的消息,并在适用时包含完整代码片段,以及说明此文件读取或编辑为何重要的摘要。
  4. 错误和修复:列出你遇到的所有错误以及你如何修复它们。特别注意你收到的具体用户反馈,尤其是用户告诉你以不同方式做事的时候。
  5. 问题解决:记录已解决的问题和任何正在进行的故障排除工作。
  6. 所有用户消息:列出所有非工具结果的用户消息。这些对于理解用户的反馈和意图变化至关重要。
  7. 待办任务:概述你被明确要求处理的待办任务。
  8. 当前工作:详细描述在此摘要请求之前正在进行的工作,特别关注用户和助手的最新消息。在适用时包含文件名和代码片段。
  9. 可选的下一步:列出与你在摘要请求之前正在进行的工作相关的下一步。重要:确保此步骤与用户的明确请求直接一致,且与你在摘要请求之前正在处理的任务一致。如果你的上一个任务已结束,则仅列出与用户请求直接一致的下一步。在未先与用户确认之前,不要开始偏离主题的请求。 如果有下一步,请包含来自最近对话的直接引用,准确显示你正在处理的任务以及你在哪里停下的。这应该是逐字的,以确保任务理解没有偏差。

Here’s an example of how your output should be structured:

以下是你的输出结构示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<example>
<analysis>
[Your thought process, ensuring all points are covered thoroughly and accurately]
</analysis>

<summary>
1. Primary Request and Intent:
   [Detailed description]

2. Key Technical Concepts:
   - [Concept 1]
   - [Concept 2]
   [...]

3. Files and Code Sections:
   - [File Name 1]
     - [Summary of why this file is important]
     - [Summary of the changes made to this file, if any]
     - [Important Code Snippet]
   - [File Name 2]
     - [Important Code Snippet]
   [...]

4. Errors and fixes:
   - [Detailed description of error 1]:
     - [How you fixed the error]
     - [User feedback on the error if any]
   [...]

5. Problem Solving:
   [Description of solved problems and ongoing troubleshooting]

6. All user messages:
   - [Detailed non tool use user message]
   [...]

7. Pending Tasks:
   - [Task 1]
   - [Task 2]
   [...]

8. Current Work:
   [Precise description of current work]

9. Optional Next Step:
   [Optional Next step to take]
</summary>
</example>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<示例>
<analysis>
[你的思考过程,确保所有要点都被彻底且准确地覆盖]
</analysis>

<summary>
1. 主要请求和意图:
   [详细描述]

2. 关键技术概念:
   - [概念 1]
   - [概念 2]
   [...]

3. 文件和代码部分:
   - [文件名 1]
     - [此文件为何重要的摘要]
     - [对此文件所做的更改摘要(如有)]
     - [重要代码片段]
   - [文件名 2]
     - [重要代码片段]
   [...]

4. 错误和修复:
   - [错误 1 的详细描述]:
     - [你如何修复该错误]
     - [用户对该错误的反馈(如有)]
   [...]

5. 问题解决:
   [已解决问题的描述和正在进行的故障排除]

6. 所有用户消息:
   - [详细的非工具使用的用户消息]
   [...]

7. 待办任务:
   - [任务 1]
   - [任务 2]
   [...]

8. 当前工作:
   [当前工作的精确描述]

9. 可选的下一步:
   [可选的下一步行动]
</summary>
</示例>

Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.

请根据迄今为止的对话提供你的摘要,遵循此结构并确保回答的精确性和全面性。

There may be additional summarization instructions provided in the included context. If so, remember to follow these instructions when creating the above summary. Examples of instructions include:

包含的上下文中可能提供了额外的摘要指令。如果是这样,请在创建上述摘要时记住遵循这些指令。指令示例包括:

1
2
3
4
<example>
## Compact Instructions
When summarizing the conversation focus on typescript code changes and also remember the mistakes you made and how you fixed them.
</example>
1
2
3
4
<示例>
## 压缩指令
在总结对话时,重点关注 typescript 代码更改,并记住你犯的错误以及你如何修复它们。
</示例>
1
2
3
4
<example>
# Summary descriptions
When you are using compact - please focus on test output and code changes. Include file reads verbatim.
</example>
1
2
3
4
<示例>
# 摘要描述
当你使用 compact 时 - 请关注测试输出和代码更改。逐字包含文件读取内容。
</示例>