Receber por email
← Voltar para o catálogo

continue

Cheaper and faster than /compact. Restores previous session context by reading transcripts directly — no LLM calls, no token cost

27estrelas
Atualizado há 4 meses

Ver no GitHub ↗ Licença: Apache-2.0

Como adicionar

/plugin marketplace add ww-w-ai/claude-code-token-saver

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/continue/svg)](https://www.skillteca.com.br/skills/continue)

Alerta por categoria

Receba novas skills de Design e Frontend toda segunda

1 email curto, só com as skills novas de Design e Frontend. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

Restore context from previous sessions so the user can pick up where they left off — without the cost of /compact.

Help

ONLY show help if the user's argument literally contains the word "help" (e.g. /continue help). If no argument or any other argument is given, SKIP this section entirely and proceed to Step 1.

If the user provides "help" as argument, show usage summary and stop:

/continue — Restore context from previous sessions (zero LLM calls)

Options:
  (nothing)     Show session list, pick which to restore
                  - Current session with context-loss events appears as #0 [default]
                  - Press Enter to restore just #0, or add more numbers
  last          Quick restore:
                  - Current session if it had /compact or auto-compact
                  - Otherwise, most recent other session
  help          Show this help

Examples:
  /continue
  /continue last

Do not run any analysis or restoration. Just display the help text and stop.

Language

Detect the user's language from their message accompanying the /continue invocation. If no message was provided (bare /continue), detect the dominant language from the session list's firstMsg/lastMsg content after Step 1 runs. All UI messages (session list header, selection prompt, progress updates, final reference note) MUST be in the detected language. The examples below are in English — translate naturally, don't transliterate.

Quick Restore: /continue last

If the user invoked /continue last, skip the session list entirely. Run list-sessions with --limit 3. Then pick automatically based on the isCurrent and hasContextLoss fields:

  • If the current session has context-loss (isCurrent: true AND hasContextLoss: true) → auto-pick the CURRENT session. Its pre-context-loss content is what needs restoration.
  • Otherwise → auto-pick the most recent session where isCurrent: false (the previous session).
  • If no valid target (current session has no context-loss AND no previous sessions exist) → print "No previous sessions found in this project." and stop.

Jump directly to Step 3 with the selected session. No user prompt needed.

Step 1: List & Select

If /continue last was used, skip this step (see above).

Run the list-sessions script to get main sessions only (subtask/system-only sessions are filtered out). Requires Node.js.

PROJECT_HASH=$(echo "${PWD}" | sed 's/[^a-zA-Z0-9]/-/g')
TRANSCRIPTS_DIR="${HOME}/.claude/projects/${PROJECT_HASH}"
node ${CLAUDE_PLUGIN_ROOT}/scripts/list-sessions.js "${TRANSCRIPTS_DIR}" --limit 11 --offset 0

The script outputs JSON. If the script returns an empty array, display "No previous sessions found in this project." and stop.

Current session identification: The script sets isCurrent: true on the session whose JSONL is most recently modified (the one being actively written). This is reliable even after auto-compact (unlike firstMsg comparison, which fails because the LLM's first visible message becomes the summary).

Case A/B/C/D list display:

  • Look at the session with isCurrent: true:
  • If hasContextLoss: true → display it as #0 [default] (with 📍 marker plus any @@/+/++ event badges). #1..N are other sessions.
  • If hasContextLoss: false → exclude it entirely from the list (its full content is in live memory, nothing to restore). #1..N are other sessions.
  • If no other sessions exist and current has context-loss → auto-restore current session, skip list display (Case C).
  • If no other sessions exist and current has no context-loss → print "No previous sessions found in this project." and stop (Case D).

Format each session for display (preserve existing Case A/B/C/D logic — current session #0 with context-loss marker, etc.):

📂 Found {N} previous sessions in this project.

Pick the ones you want to restore — Claude will read them and bring the
context into this session so you can continue where you left off.

💡 Tip: Selecting 1-2 sessions is fast (almost always faster than /compact).
   Selecting many sessions takes longer, but still no LLM summarization needed.

| # | Started | Last active | First message | Last message | Size |
|---|---------|-------------|---------------|--------------|------|
| 1 | Mar 31 09:00 | today 14:05 | "improve the skill..." | "ok go ahead..." | 122KB · 3 msgs |
| 2 | Mar 31 08:30 | today 13:59 | "local agent actually..." | "let me test the skill..." | 2.1MB · 82 msgs |
| ... | | | | | |

Enter:
  - numbers only (e.g., "1,3" or "1-4") — fast restore
  - numbers + ":" + topic (e.g., "1,3 : PDCA 구현") — topic-based restore (slower, more accurate)
  - "more" for pagination
  - (empty) for default

💡 Topic search adds an LLM step so it takes longer, but restores specific memories more accurately.

Use --limit N and --offset N for pagination. When the user types "more", re-run list-sessions with --offset increased by 10 (the limit). Numbers continue sequentially across pages.

Wait for user selection before proceeding. This avoids preprocessing sessions the user doesn't need.

Step 2: Parse Input

Split user input on the first ::

  • Left side → numbers part. Parse using existing Case A/B/C/D logic (additive with #0, ranges, comma lists).
  • Right side (optional) → topic string (trim whitespace). May be absent.

Examples:

  • 1,3 → sessions [1, 3], no topic
  • 1-4 : PDCA 구현 → sessions [1, 2, 3, 4], topic = "PDCA 구현"
  • : error handling → only #0 (default), topic = "error handling"
  • `` (empty) → default selection, no topic

Step 3: Ensure Cache & Preprocess

preprocess.js is self-managing: it derives the cache path from the JSONL path, checks format version + mtime, and skips if fresh. Just call it for each selected session.

# For each selected session: ensure compact.txt cache is fresh
node ${CLAUDE_PLUGIN_ROOT}/scripts/preprocess.js "${TRANSCRIPT_PATH}"

The cache file is at:

PROJECT_HASH=$(echo "${PWD}" | sed 's/[^a-zA-Z0-9]/-/g')
CACHE_FILE="${HOME}/.claude/claude-code-token-saver-data/${PROJECT_HASH}/${SESSION_ID}/compact.txt"

Current session with context-loss: The compact.txt contains the FULL session. When reading it, use lastContextLossLine from list-sessions.js to filter: only read entries where L{n} < lastContextLossLine. Content after the last context-loss event is already in live LLM memory.

To extract just the pre-boundary portion without LLM parsing:

awk "/\[Session:.*L${LAST_LOSS_LINE}\]/{exit} 1" "${CACHE_FILE}"

Current session WITHOUT context-loss: Skip — entire session is in live memory.

Past sessions: Read the full compact.txt (none of their content is in live memory).

The preprocessor (v6) outputs a compact text transcript with [Session:{sid} {ISO} L{n}] headers. The L{n} is the JSONL line number of the user message — this enables direct seek into the original transcript for topic-based restoration.

Preprocessing is instant (< 1 second even for 60MB+ transcripts).

Step 4: Load Compact

No size threshold. Always load all selected compact.txt files.

  • No topic → Read all compact.txt files directly using the Read tool. Content is loaded into conversation context as-is. For files exceeding ~10K tokens, read in chunks using offset/limit parameters. Always read the ENTIRE file — never skip sections. Proceed to Step 6.
  • Topic provided → Do NOT Read compact.txt yet. Proceed to Step 5 (topic-based restoration).

Step 5: Topic-Based Original Restoration

Goal: Load compact.txt with the top 20 most topic-relevant truncated turns replaced by their full JSONL originals. The original compact.txt files are never modified — the assembled result is written to a temp file.

Step 5a: Extract user turn list

Extract all user message headers from compact.txt files programmatically (no LLM Read needed):

python3 << 'PYEOF'
import json, os, re

sessions = [
    # (session_id, compact_path) 
Compartilhar X LinkedIn