Compact chat history

From dtyq/magic · View interactive version

Compact chat history is an AI agent skill from the GitHub repository dtyq/magic. Summarize and compress the current conversation history into a structured context snapshot, then call compact_chat_history to save it. Read this skill only when the user explicitly asks to compact/summarize — system-triggered compaction injects the instructions directly without requiring a skill rea

How to use this skill

Skill file

Compact Chat History

Compress the current conversation into a structured summary, then call compact_chat_history immediately with the result.


Instructions

The conversation history is too long and must be compressed. You must call the compact_chat_history tool immediately to complete the summary.

Your task is to create a thorough summary of the conversation so far, with special attention to the user's explicit requests and your prior actions. The summary must capture all important details, work results, and file locations to ensure continuity, since we follow an "everything-is-a-file" architecture.

Remember: subsequent work will restore context by reading files, so you must provide accurate file paths. For content already saved to files, note the location — do not repeat large blocks of text in the summary itself.

Treat the summary as a recovery index, not a transcript. Inline only information that cannot be reliably recovered by reading files or reloading skills: exact URLs, external IDs, user-provided constraints, active runtime references, and critical failure evidence.

If a User Input Reference Index is provided, do not reproduce full user messages yourself. Select the indexes of user messages that must be preserved exactly, mention those indexes in Section 6 with short reasons, and pass the same indexes to compact_chat_history as preserved_user_input_indexes. The system restores the exact text from the original chat history.

Use indexes only from the latest User Input Reference Index visible in context. If no current index is available, pass an empty list instead of guessing.

Your summary must include the following sections:

1. Task Goals and Approach

2. Key Files and Context Resources (most important part — be thorough and precise)

2.5 External Links and Irrecoverable References

3. Skills Needed to Resume This Task

4. Resolved Issues and Current State

5. Incomplete Tasks, Next Steps, and Continuity Confirmation

6. High-Value User Input

Preserve exact carriers of future work when they are still relevant:

Do not preserve full file contents when the file can be read again and the summary keeps the correct path. Preserve what to read and why instead.

Do not preserve stale search-result links, old intermediate URLs, or details that were superseded by a later decision.

If any of the above sections overlap, merge them — no need to repeat.


Output Format Example

1. Task Goals and Approach:
   [Describe each specific request in detail]
   - [Method 1]
   - [Strategy 2]
   - [...]

2. Key Files and Context Resources (most critical):
   - [project outline path] - overall plan and structure - read when confirming global goals and scope
   - [currently active file path] - current progress and key context - read first when resuming
   - [user-specified reference path] - content user explicitly requested - read when working on that section
   - [similar completed content path] - style/structure reference - read a suitable amount when consistency is needed
   - [project config path] - project settings - read when config details are needed
   - [history/backup path] - read when tracing back changes
   - [info name] - not saved to file - how to re-acquire: [specific method]
   Reading principles:
   - Start with the most important items closest to the current task, then read others as needed
   - For high-consistency tasks, read a suitable number of completed items as reference
   - Avoid reading all files at once to prevent filling up context again

2.5 External Links and Irrecoverable References:
   - URL: https://example.com/watch?v=abc123&t=10 - source video for the active analysis task; status: still needed; needed by: continue video analysis
   - Run ID: run_123456 - external job created before compaction; status: pending; needed by: poll result
   - Local URL: http://localhost:5173 - active dev server; status: running; needed by: browser verification
   (Only include references still needed for incomplete or future tasks.)

3. Skills Needed to Resume This Task:
   - [Skill name] - [one-line purpose]
   - [Skill name] - [one-line purpose]
   (Do NOT include skill content. Pass these choices as skill_suggestions; reading remains optional.)

4. Resolved Issues and Current State:
   [Description of resolved issues and ongoing troubleshooting]
   [Accurate description of current work state]

5. Incomplete Tasks, Next Steps, and Continuity Confirmation:
   Status: incomplete
   - Task 1
   - Task 2
   Next action: continue from the failed file read using the exact full path above
   Relevant quote: "Please continue analyzing this video. The link is https://example.com/watch?v=abc123."

6. High-Value User Input:
   Selected user input indexes:
   - 2: user gave a non-negotiable output-language constraint
   - 5: user provided the source URL needed for the unfinished analysis
   The system restores the exact text from the original chat history. Do not copy full user messages here.

Pass the summary and selected choices together as tool arguments:

{
  "summary": "[The complete structured summary above]",
  "preserved_user_input_indexes": [2, 5],
  "skill_suggestions": [
    {"name": "[Available skill name]", "reason": "[Why it may help with the remaining work]"}
  ]
}

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.