Claude Code /resume loses sessions — rebuild the index to get them back
Claude Code 2.1.27 introduced a regression: /resume only shows a handful of sessions even though the .jsonl history files are still on disk. You exit a long conversation, try to resume it, and it’s gone from the list. Your progress across multiple projects — infrastructure work, portfolio work, everything with valuable context — looks wiped out.
The cause
Claude Code maintains a sessions-index.json file that maps session IDs to metadata (summary, last prompt, timestamps). The /resume command reads this index, not the actual session files. When the index goes stale — which the 2.1.27 regression causes frequently — sessions that exist on disk become invisible to /resume.
The .jsonl files are fine. The index is just wrong.
The fix
Scan the actual session files and rebuild the index from truth:
#!/usr/bin/env python3
"""rebuild_claude_index.py — restore missing Claude Code sessions to /resume"""
import json
from pathlib import Path
claude_dir = Path.home() / ".claude" / "projects"
for project_dir in claude_dir.iterdir():
if not project_dir.is_dir():
continue
index_path = project_dir / "sessions-index.json"
sessions = {}
for jsonl_file in project_dir.glob("*.jsonl"):
session_id = jsonl_file.stem
lines = jsonl_file.read_text().strip().split("\n")
if not lines:
continue
# Extract first user message as summary
summary = ""
last_prompt = ""
for line in lines:
try:
msg = json.loads(line)
if msg.get("role") == "user":
content = msg.get("content", "")
if isinstance(content, list):
content = " ".join(
b.get("text", "") for b in content
if b.get("type") == "text"
)
if not summary:
summary = content[:200]
last_prompt = content[:200]
except json.JSONDecodeError:
continue
# Get timestamps from file
stat = jsonl_file.stat()
sessions[session_id] = {
"summary": summary,
"lastPrompt": last_prompt,
"lastActiveAt": int(stat.st_mtime * 1000),
"createdAt": int(stat.st_ctime * 1000),
}
if sessions:
index_path.write_text(json.dumps(sessions, indent=2))
print(f"Rebuilt {len(sessions)} sessions in {project_dir.name}")
Run it, restart Claude Code, and /resume shows every session again.
Why this matters
Claude Code sessions accumulate significant context — file reads, architectural decisions, debugging trails. Losing access to a session mid-project is disruptive, especially when you’re juggling multiple workstreams across different repos.
The underlying issue is tracked in multiple Anthropic GitHub issues (22030, 22107, 22114). Until a platform fix ships, the rebuild script is the workaround.