---
name: save-context
description: Auto-saves a distilled summary of the session before /clear wipes context, and reloads it after. Hooks into SessionEnd (matcher clear) and SessionStart (source clear). Use to set up the hooks, troubleshoot, or explain how the workflow works.
---

# save-context — persist context across /clear

This skill installs two hooks that make `/clear` safe to run after every task. Before context is wiped, the just-ended session is distilled into a per-project log file. When the next session starts via `/clear`, that log is loaded back in — so you keep continuity without keeping noise.

## What it does

1. **SessionEnd hook (matcher: `clear`)** — fires when the user runs `/clear`. Reads the session transcript, runs `claude -p` to extract decisions / files touched / open threads, appends a dated entry to `~/.claude/session-log/<project>.md`, and rotates entries older than the 200-line cap into a sibling `archive/` file.
2. **SessionStart hook (matcher: `clear`)** — fires when the new session starts after `/clear`. Reads the log file for the current project and emits it as additional context, so the new session picks up where the old one left off.

The `startup` and `resume` SessionStart sources are **not** matched — fresh terminals don't auto-load anything.

## File layout

```
~/.claude/skills/save-context/
├── SKILL.md            # this file
├── scripts/
│   ├── save.sh         # SessionEnd hook
│   └── load.sh         # SessionStart hook
└── INSTALL.md          # paste-in settings.json snippet for teammates

~/.claude/session-log/
├── <project>.md        # rolling log, capped at ~200 lines
└── archive/
    └── <project>.md    # older entries roll here
```

`<project>` is the basename of the cwd at the time the hook fires (e.g. `projects.md`, `genos-proxy.md`). Simple and predictable; works in non-git directories.

## Installation (for the user or a teammate)

1. Copy `~/.claude/skills/save-context/` into your own `~/.claude/skills/`.
2. Add the hooks block from `INSTALL.md` to your `~/.claude/settings.json` (merge with any existing `hooks` key).
3. Run `/clear` once to verify — you should see a `~/.claude/session-log/<cwd-basename>.md` file appear.

No other config needed. The scripts are self-contained bash + `claude -p`.

## When this skill is invoked directly

If the user says "set up save-context", "install the clear hook", "why isn't my session log saving", or asks how the workflow works — read this file and the two scripts, then help them install or debug. The hook scripts are the source of truth; SKILL.md just describes the contract.

## Troubleshooting

- **Nothing in `session-log/` after `/clear`** — check `~/.claude/session-log/.save-errors.log`. The save script logs failures there instead of failing silently.
- **`claude -p` not found** — the scripts assume `claude` is on PATH. If a teammate uses a non-standard install, edit `scripts/save.sh` to point at the right binary.
- **Log file growing too large** — the rotation cap is `MAX_LINES=200` near the top of `save.sh`. Adjust there.
- **Want to disable temporarily** — remove the `SessionEnd`/`SessionStart` `"clear"` matchers from `settings.json`. The skill files stay put.
