Metadata-Version: 2.4
Name: lastword-cc
Version: 0.1.4
Summary: A permanent, browsable archive of your Claude Code session transcripts, before they're deleted.
Author: kxzongoing
License-Expression: MIT
Project-URL: Homepage, https://github.com/kxzongoing/lastword
Project-URL: Issues, https://github.com/kxzongoing/lastword/issues
Keywords: claude,claude-code,transcripts,archive,backup,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: System :: Archiving :: Backup
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<div align="center">

<img src="https://raw.githubusercontent.com/kxzongoing/lastword/main/docs/banner.svg" alt="lastword" width="100%">

<br>

**Claude Code deletes your session transcripts after 30 days.**<br>
**This archives them permanently — and makes them beautiful to read.**

<br>

[![PyPI](https://img.shields.io/pypi/v/lastword-cc?label=pypi%20%C2%B7%20lastword-cc&logo=pypi&logoColor=white)](https://pypi.org/project/lastword-cc/)
[![Tests](https://github.com/kxzongoing/lastword/actions/workflows/tests.yml/badge.svg)](https://github.com/kxzongoing/lastword/actions/workflows/tests.yml)
![Python](https://img.shields.io/badge/python-3.9%2B-3776AB?logo=python&logoColor=white)
![Dependencies](https://img.shields.io/badge/dependencies-none-2ea44f)
![Offline](https://img.shields.io/badge/network_calls-zero-0f766e)
![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-8b87ff)
![License](https://img.shields.io/badge/license-MIT-blue)

</div>

---

## 😱 The problem

Claude Code writes every conversation to `~/.claude/projects/*.jsonl`, then **silently deletes anything older than `cleanupPeriodDays` — which defaults to 30.**

That research session where you finally cracked the architecture? The debugging marathon with the fix you'd never reconstruct? Gone, with no warning and no undo.

## ✨ The fix

```bash
uv tool install lastword-cc  # or: pipx install lastword-cc
lastword                     # archive everything Claude Code still has
lastword open                # browse it
```

That's the whole setup — Python 3.9+, zero dependencies, zero network calls. The package is `lastword-cc` (cc for Claude Code); the command it installs is `lastword`. Want to try it without installing? `uvx --from lastword-cc lastword`. Upgrade later with `uv tool upgrade lastword-cc`.

Every later run picks up what's new and leaves the rest alone. **Once a conversation is archived, it stays — even after Claude Code deletes the original.**

## 👀 See it before you run it

Don't want to point it at your own chats yet? Build a demo archive from invented transcripts:

```bash
lastword demo --open
```

That builds eight fictional sessions in a temp folder, rendered by the **same code** that renders a real archive. Nothing in it touches `~/.claude`. It's also the right way to grab screenshots or check a UI change without exposing your own work.

---

## 🖥️ What you get

<div align="center">
<img src="https://raw.githubusercontent.com/kxzongoing/lastword/main/docs/screenshot-browser.png" alt="Session browser" width="100%">
<img src="https://raw.githubusercontent.com/kxzongoing/lastword/main/docs/screenshot-search.png" alt="Full-text search" width="100%">
</div>

### 📚 A browser for everything

Run `lastword open` for a two-pane reader: sessions grouped by **Today / Yesterday / Earlier this week**, live filtering, and full keyboard navigation — <kbd>/</kbd> to search, <kbd>↑</kbd><kbd>↓</kbd> or <kbd>j</kbd><kbd>k</kbd> to move, <kbd>Esc</kbd> to clear. Light and dark themes, remembered between visits.

### 💬 Conversations that read like conversations

Messages render as **actual prose** — headings, lists, tables, and syntax-styled code — not walls of preformatted text. Three lanes stay visually distinct so you always know who said what:

| Lane          | Appearance                                                               |
| ------------- | ------------------------------------------------------------------------ |
| 🧑 **You**    | Filled card with an accent border — the thing you scan for               |
| 🤖 **Claude** | Clean prose, unadorned                                                   |
| ⚙️ **Tools**  | Muted monospace folds, collapsed by default, each showing its own output |

Tool results are nested **inside the call that produced them** — so a 500-turn session scans in seconds, and nothing machine-generated is ever mislabelled as something you typed.

### 🔍 Search that actually finds things

`index/search.html` does instant client-side search across every turn, bash command and file edit — filter by type, jump straight to the moment in the conversation. No server, no index to build.

### 📦 Plain files underneath

Everything is JSON and Markdown you can grep, diff, or feed to other tools. Paths are relative to the archive home (`lastword where`):

| Path                                         | Contents                                              |
| -------------------------------------------- | ----------------------------------------------------- |
| `sessions/<project>/<id>/`                   | `source.jsonl`, `conversation.md`, `conversation.html` |
| `index/session_index.{json,md}`              | One row per session — title, project, duration, links |
| `extracts/tool_invocations.{json,md}`        | Every tool call, matched with its result              |
| `extracts/file_modifications.{json,md}`      | Every Edit / Write / MultiEdit / NotebookEdit         |
| `extracts/bash_commands.{json,md}`           | Every Bash call with stdout and stderr                |
| `extracts/architectural_decisions.{json,md}` | Heuristically surfaced decision points                |
| `timeline/timeline.{json,md}`                | All of the above, merged and sorted by date           |

`source.jsonl` is a **byte-for-byte copy** of Claude Code's transcript, the archive of record; everything else is rebuilt from it. Session UUIDs and original timestamps survive everywhere — filenames, table rows, HTML anchors.

> **Note** — `architectural_decisions` is a heuristic (plan proposals, `AskUserQuestion` points, decision language). Read it for signal, not as a curated list.

---

## 🛡️ Stop losing chats in the first place

Before anything else, widen Claude Code's retention window in `~/.claude/settings.json`:

```json
{
  "cleanupPeriodDays": 365
}
```

This tool can only archive what still exists when it runs. A year of retention buys you margin; archiving automatically closes the gap completely.

**Archive every session as it ends:**

```bash
lastword hook install      # adds a SessionEnd hook to ~/.claude/settings.json
```

When a session ends — you exit, `/clear`, or `/resume` another — Claude Code runs `lastword hook run`, which starts an archive run in the background and returns at once, so ending a session never waits on it. Your other settings are left exactly as they were (a backup is saved as `settings.json.lastword-backup`). `lastword hook status` shows the hook and its log (`hook.log` in the archive home); `lastword hook uninstall` removes it. Install lastword as a command first (`uv tool install` / `pipx install`): the hook runs it from whatever project you were in.

**And as a backstop, a daily run.** The hook doesn't fire if a terminal is killed or Claude Code crashes, so schedule one too:

**macOS / Linux** — `crontab -e` (cron has a minimal `PATH`, so give the full path from `which lastword`):

```cron
0 20 * * * $HOME/.local/bin/lastword --quiet
```

**Windows** — Task Scheduler → daily → `lastword --quiet`.

`lastword` exits non-zero if any session failed to archive, so a scheduler that alerts on failure will tell you. Two runs that overlap don't collide: the second waits for the first.

---

## ♻️ Already lost chats? Maybe not.

If you archived sessions before and they've vanished from your index, **they are probably still on disk.** Earlier versions rebuilt the index only from live sources, so pruned sessions dropped out even though `sessions/` still held every byte.

Just run it again:

```bash
lastword
```

The backfill pass replays every session in `manifest.json` from its archived copy:

```
Sessions found: 23 | archived: 2 | unchanged: 21 | restored from archive: 28 | pages rendered: 2 | failed: 0
Total sessions in index: 51
```

As long as `manifest.json` and `sessions/` survive, nothing is lost.

---

## 🚚 Renamed or moved a project?

Claude Code files sessions under the project's folder path, so renaming the folder splits its history in two: old sessions stay under the old name, new ones start under the new one. Join them back up:

```bash
lastword move-project ~/code/old-name ~/code/new-name --dry-run   # preview
lastword move-project ~/code/old-name ~/code/new-name
lastword
```

This moves the old sessions to the new name both in `~/.claude/projects` (so `claude --resume` finds them from the new folder) and in your archive, and from then on shows the old path as the new one in the index, search and timeline. Your transcripts are never rewritten; `source.jsonl` keeps the paths exactly as they were recorded.

Close any Claude Code session still running in the old folder first. `move-project` refuses to run while one is running, and stops without changing anything if a file at the new name would be overwritten. If a session was open during the move anyway, Claude Code writes a few closing records back to the old folder when it exits; run `move-project` again and it recognises that stub and clears it away, since everything in it is already in the moved copy. Pass `--archive-only` to leave `~/.claude/projects` alone.

---

## 🏠 Where your archive lives

By default in **`~/.lastword`**, private to your user (`700`). `lastword where` prints it; to put it elsewhere, pass `--home DIR` or set `LASTWORD_HOME`. Avoid folders that sync to the cloud (Documents or Desktop with iCloud or OneDrive): the archive holds everything you pasted into a session.

**Archived into a git checkout before 0.1?** Nothing breaks: run from inside a folder that already holds an archive, lastword keeps using it. To move it to the standard place:

```bash
lastword migrate --from /path/to/lastword    # copies to ~/.lastword and checks every byte
lastword && lastword verify
```

The old copy is left untouched until you delete it. The first run on an archive from before 0.1 upgrades it in place, keeping the original manifest as `manifest.v0.bak.json`.

---

## ⚙️ Commands

```
lastword [archive]           Archive new and changed sessions (the default)
    --root DIR               Claude Code projects dir (default: ~/.claude/projects)
    --project SUBSTR         Only process project dirs matching a substring
    --force                  Re-render every session's pages
    --quiet / --json         Print nothing but problems / print counts as JSON
    --wait SECONDS           How long to wait for another run to finish (default: 60)
lastword open                Open the session browser
lastword where               Print the archive's location
lastword verify              Check every archived transcript against its checksum
lastword migrate --from DIR  Copy an existing archive to the archive home
lastword move-project OLD NEW  Join a renamed project's sessions (see above)
lastword hook install        Archive each session when it ends (also: uninstall, status)
lastword demo [--open]       Build a demo archive from invented sessions
```

Every command takes `--home DIR`. Exit codes: `0` success, `1` something failed (details on stderr), `2` bad usage.

**Stability:** until 1.0, the commands above and the archive layout (`sessions/`, `manifest.json`) are stable — a newer lastword always upgrades an older archive, and an older lastword refuses a newer archive rather than damage it. The JSON layouts under `extracts/`, `index/` and `timeline/` may still change.

## 🔒 How it stays safe

**Byte-exact** — each transcript is copied verbatim to `source.jsonl`, with its sha256 in `manifest.json`. `lastword verify` re-checks every one.

**Never overwritten** — Claude Code only appends to a transcript, so a new snapshot replaces the old one only if it starts with every byte of it. If a transcript is ever rewritten instead, the earlier copy is kept alongside.

**Append-only** — aggregates rebuild from the union of live sources **and** every session in the manifest, replayed from its archived copy. Claude Code's prune can't remove anything from your index.

**Crash-safe** — every file is written to a temp file and renamed into place, and overlapping runs take turns, so an interrupted run never leaves a half-written archive.

**Local** — reads `~/.claude/projects`, writes to disk. No network, no telemetry, no dependencies. Transcript text is escaped before rendering, and `javascript:` URLs are stripped.

---

## 🚨 Privacy — read this before pushing anywhere

**Your exported conversations are private. Never commit them.**

The archive holds whatever you discussed with Claude: proprietary source, file paths, customer data, credentials pasted into prompts. Keep it out of any repository. If you still archive into a git checkout, its bundled `.gitignore` excludes every path the exporter writes, so a fork stays code-only. Before your first push:

```bash
git status --porcelain     # should list source files only
```

To back up the archive itself, use a **private** repo or ordinary file backup — never a public one.

---

## 🤝 Contributing

Issues and PRs welcome — see [CONTRIBUTING.md](https://github.com/kxzongoing/lastword/blob/main/CONTRIBUTING.md). Run the tests with `python3 -m unittest` — they build invented transcripts and never touch your own. For screenshots or UI checks, `python3 tools/make_demo.py` rebuilds `docs/demo/`. Please never paste real transcript content into a bug report — a redacted snippet or the structure alone is plenty. Found a security problem? Report it privately as described in [SECURITY.md](https://github.com/kxzongoing/lastword/blob/main/SECURITY.md). Release history is in the [changelog](https://github.com/kxzongoing/lastword/blob/main/CHANGELOG.md).

## 📄 License

MIT — see [LICENSE](LICENSE).

<div align="center"><br><sub>Your conversations are work. Keep them.</sub></div>
