Skip to content
Back to skills

Pre Compact Backup

ASecurity

Back up conversation transcript before context compaction. Use when: PreCompact hook fires, user asks to save session state, or before long tasks where context loss would be costly. Creates timestamped backup in logs/transcript_backups/. Inspired by: disler/claude-code-hooks-mastery pre_compact pattern.

  • 10 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 9, 2026
ai-agentsbash

Works with

  • claude code

Security analysis

A100/100

Scanned September 9, 2026

npx -y skills add yanacuti1121/Yana-AI --skill pre-compact-backup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pre Compact Backup?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pre Compact Backup
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/yanacuti1121-pre-compact-backup/badge)](https://www.skillsdirectory.com/skills/yanacuti1121-pre-compact-backup)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "pre-compact-backup"
description: "Back up conversation transcript before context compaction. Use when: PreCompact hook fires, user asks to save session state, or before long tasks where context loss would be costly. Creates timestamped backup in logs/transcript_backups/. Inspired by: disler/claude-code-hooks-mastery pre_compact pattern."
---

# Pre-Compact Backup Skill

## When to trigger

- PreCompact hook fires (automatic)
- "save session before compact", "lưu transcript"
- "backup context", "sao lưu phiên làm việc"
- Before starting a very long multi-step task

## What to do

### Step 1 — Identify transcript location

Check for `.claude/state/` or default Claude Code transcript paths.

### Step 2 — Create backup

```bash
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="logs/transcript_backups"
mkdir -p "$BACKUP_DIR"
# Copy current transcript if accessible
cp .claude/transcript.jsonl "$BACKUP_DIR/transcript_${TIMESTAMP}.jsonl" 2>/dev/null || true
```

### Step 3 — Tag the backup

Write a short metadata file alongside:
```json
{
  "timestamp": "YYYY-MM-DDThh:mm:ssZ",
  "trigger": "manual | pre-compact-hook",
  "branch": "[current-branch]",
  "last_commit": "[sha]"
}
```

### Step 4 — Report

```
Backup saved: logs/transcript_backups/transcript_[timestamp].jsonl
Trigger: [manual | pre-compact-hook]
Branch: [branch]
```

## Graceful degradation

- If transcript not accessible: log the attempt, do not error
- If logs/ does not exist: create it
- Never block compaction — backup is best-effort
- Silent failure is acceptable; noisy failure is not

## Notes

This skill is informational — the actual backup is best done via a PreCompact hook wired in `settings.json`. This skill documents the pattern and can be invoked manually when needed.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.