Repository navigation
CLI Reference
Current as of v1.3.2. Longhand exposes 24 commands plus 7 subcommand groups — run longhand --help for the always-true list, or longhand <command> --help for a command's full flags. Most commands that touch the store take --data-dir to point at a non-default location (or set LONGHAND_DATA_DIR, which every entry point except config --set respects — #96). The commands that don't take --data-dir at all: demo, doctor, shared-mcp, hook install/uninstall, prompt-hook install/uninstall, mcp install/uninstall/serve, and schedule install-reconciler/uninstall-reconciler. Of those, doctor, shared-mcp, mcp serve, and the reconciler job use the default/env-resolved store; demo builds its own throwaway store under $TMPDIR; and the hook, prompt-hook, and mcp install/uninstall commands only edit config files and never open a store. config accepts --data-dir but honors it only for its backup.* rows (1.3.0+); the hook/redact rows and --set ignore it (#96).
One-shot orchestrator: ingest + install hooks + register MCP + doctor. Five steps (printed 1/5–5/5): ingest (analysis runs inline unless --skip-analysis), install the SessionEnd + Stop hooks, install the UserPromptSubmit hook, install the MCP server into Claude Desktop (and print the claude mcp add command for Claude Code), then doctor. Flags: --skip-ingest, --skip-prompt-hook, --skip-mcp, --skip-analysis (store and embed events, defer episode/segment extraction to a later analyze --all), --data-dir. Safe to re-run — but re-running re-ingests every session, it does not skip what's already indexed.
Try Longhand on a fake 3-session corpus (a Stripe webhook bug, an auth migration, a downstream 401 fix) without touching your real history. Seeds a sandboxed store under $TMPDIR/longhand-demo-<timestamp>/ (not literally /tmp — /var/folders/.../T/... on macOS), runs recall and recall_project_status against it, then cleans up unless --keep. It is not excluded from the update check, so it can still touch ~/.longhand/update-check.json on exit.
View or edit the hook.* and redact.* keys in ~/.longhand/config.json — and, since 1.3.0, backup.auto, the only backup.* key --set accepts (the rest are written by backup init). --set hook.min_relevance=3.0 writes a key; bare config prints the current hook config table. --set always writes ~/.longhand/config.json, ignoring --data-dir/LONGHAND_DATA_DIR even though the hooks read the resolved data dir's copy — on a relocated store the two can silently diverge (#96). --edit currently does nothing at all — the show/edit choice is never read, so the table prints either way. See Configuration.
Verify installation. Takes no --data-dir — always checks the resolved default/env store. See Architecture → Doctor rows for the full, ordered list of checks (hooks, MCP registration for both Desktop and Code, data directory, ingest freshness, hook errors, transcript-format drift, Codex capture/finalizer, storage size, backup state, aux/unknown events). First thing to run when something isn't working.
Discover and parse Claude Code JSONL files into SQLite + ChromaDB. Defaults to ~/.claude/projects when path is omitted. Incremental by default — a file already indexed at its current size is skipped; --force re-ingests it anyway. --limit N caps how many session files this run processes. --skip-analysis stores and embeds events (so search, timelines, and file history all work) but skips episodes/segments/session+project vectors — run longhand analyze --all later to fill those in.
Reconcile on-disk transcripts against the sessions table. Reports five Claude buckets — fully indexed, partially indexed (ingest crashed mid-pipeline, stage pending), ingested with project_id IS NULL, changed since the last full ingest (1.3.1+: the transcript grew after it and has been quiet for 30 minutes — a turn its session's own hooks never captured), and missing entirely — with a count of transcripts still being written (grown but active, left to their hooks) and of any over the parser's size cap; plus, when a Codex home exists, Codex rollouts on disk: captured-and-current, new-or-changed, quiet threads awaiting the full pipeline, still-being-written, skipped subagent threads, and over-the-size-bound. With --fix, re-ingests the fixable Claude buckets using current project-inference logic and runs both Codex passes (capture + finalize). Idempotent; safe to run any time. See also reattribute, which re-derives project ownership for sessions already in the database, vs. reconcile, which re-ingests transcripts that never made it in or (1.3.1+) grew after their last full ingest.
longhand codex-sync [--semantic] [--finalize-after SECONDS] [--no-finalize] [--watch] [--interval N] [--dry-run] [--include-subagents] [--limit N] [--max-file-kb N] [--max-events N] [--codex-home PATH]
Capture Codex Desktop / CLI threads (the rollouts under ~/.codex/sessions and ~/.codex/archived_sessions, or $CODEX_HOME) into the same archive, in two passes: exact records for every new or changed rollout — no vector model loaded — then the full pipeline for any rollout quiet for --finalize-after seconds (default 1800 = 30 min) so recall and semantic search see it; the model loads only when a quiet thread is waiting. --no-finalize skips the second pass; --semantic runs the full pipeline on everything now. Bounds per run: --limit (default 50), --max-file-kb (default 16384), --max-events (default 20000) — larger rollouts are deferred, never partially imported. --dry-run lists rollouts, sizes, and which are subagent threads without opening the archive; --watch polls every --interval seconds (default 60). reconcile --fix runs both passes too. See Codex.
Re-run analysis (project inference, outcome classification, episode/segment extraction) on already-ingested sessions. One of --all or --session <prefix> is required. Holds the ingest lock for the duration — a SessionEnd or Stop hook that fires meanwhile hands its ingest to a background retry that waits up to 10 minutes for the lock (1.3.1+), and anything still left after that is caught up by reconcile --fix. Sessions whose transcript file has rotated off disk are rebuilt from the events table instead of being skipped. Never re-embeds the events themselves — but every call, including --session, re-embeds that session's project summary, its fixed episodes, its segments, and its session summary (the episode and segment vectors are deleted and rebuilt; the project and session vectors are overwritten in place). --all additionally clears and rebuilds the whole episode vector collection from current SQLite rows (dropping stale embeddings left by prior episode-boundary changes) — with the same CPU-pinned ONNX model the rest of the store uses (since 1.3.2; earlier versions fell back to Chroma's default embedder, #98). Event vectors themselves only get re-embedded by a command that goes through a fresh ingest_session call: setup, ingest --force, reconcile --fix, restore, or codex-sync --semantic/the finalizer. Codex threads specifically: finalization only happens while codex-sync or reconcile --fix is actually running (nothing finalizes with no process invoked), and running analyze on an archived Codex session actively blocks the finalizer from ever indexing it (#97) — prefer codex-sync --semantic for those.
Repair project misattribution by re-deriving each session's project from its events in the database (not the transcript file, which may have rotated away) — fixes the $HOME catch-all, monorepo splits, case-duplicate paths, and junk projects minted from temp dirs. Dry-run by default — prints the moves grouped by destination and touches nothing; --fix applies them and holds the ingest lock while it does. Idempotent.
Scan the local store for secret-shaped strings (the 13 patterns listed in Security → Redaction patterns) across events, episodes, segments, outcomes, and git operations. Covers data ingested before redact.enabled was turned on. Scan mode (default) reports pattern names and counts only — never matched values. --apply masks matches in place (irreversible; prompts for confirmation unless --yes) and re-embeds the changed vector documents.
Reclaim disk space by running SQLite VACUUM (which needs free disk at least the size of the current DB file, and refuses to run — exit 1 — if there isn't enough, or if another ingest is running). --prune-aux deletes every row stored as event_type = 'unknown' before vacuuming — that's broader than just harness orchestration noise: it also removes the deliberately-preserved summary/pr-link/worktree-state/frame-link rows and any genuine upstream-drift records doctor's "Transcript format" row was counting. The source JSONLs remain the recovery path if you ever need that data back.
Opt-in and off by default: nothing leaves the machine until you have read the consent screen and typed yes. The full guide is Backup & Restore.
Turn backups on. Validates the remote (https://, ssh://, file://, user@host:path, or an absolute path; a leading - or any :: transport helper is refused), refuses a public or organization-internal GitHub repository (checked through gh when it is installed; --create makes a private one first; when visibility cannot be determined you type private to attest), measures the archive, and prints exactly what would be uploaded — session count, upload size, that the content is verbatim transcripts including thinking and tool output, that nothing is encrypted, the per-pattern counts of secret-shaped strings that will be masked in the copy, and the current redact.enabled state. Only after you type yes does it clone (or init) the repository and write the backup.* keys to config.json. --yes skips the prompt for scripts; without a terminal and without --yes it refuses. The clone lives at ~/.longhand/backup/ unless --path moves it; an existing backup clone at that path is kept, and re-pointed at --remote if its origin differs (the next backup pushes there), while a directory holding some other repository, or a non-empty directory that isn't a git repository, is refused.
Export every session that changed since the last run as its verbatim transcript (one line per distinct stored line, split into 40 MB parts), mask every longhand redact pattern in the copy only, commit in batches of about 500 MB, and push. A session in the repository never shrinks: when two machines hold different copies, the union is kept. --dry-run prints the plan (sessions to add or update, bytes, mask counts per pattern) and changes nothing; --no-push commits locally; --no-mask exports verbatim and needs a terminal plus the typed word verbatim. Counts only are ever printed, never matched values. Exits 1 when any part of the run fails (a fetch, an export, or the push) and when backups are off or the clone fails its check; a second run while one holds backup.lock stops at once (for now with a Python traceback, exit 1).
Enabled/auto state, remote, clone path, sessions backed up, sessions pending (changed since the last run), unpushed commits, last run and last push, last error, clone size, and the mask counts of the last run.
Let the scheduled reconcile --fix run (schedule install-reconciler, every 30 minutes on macOS) push at most once an hour, only when something changed, masking always on. Failures go to ~/.longhand/logs/backup.log and never affect the reconciler. Same as config --set backup.auto=true.
Turn backups off. The clone and the remote are left as they are.
Rebuild the archive from a backup. Clones the remote when --from is a URL and no clone exists (an existing clone of the same remote is fetched; a clone of a different remote is refused), verifies every transcript's sha256, and re-parses each one with the current parser into the store under the ingest lock — so the restored event count is the current parser's view of the lines, not necessarily the original row count. A session is skipped when this machine's backup-state.json already records its sha256 (an earlier restore or backup here) — the store itself isn't checked, so a store that holds those sessions but has no state file re-ingests them from the masked copy, and an emptied store whose state file survived skips everything (move that file aside first); one broken session is reported and never aborts the rest, config.json is copied back only when the data directory has none, and Codex rollouts come back through the Codex adapter. Then run longhand backup init --remote <url> on the new machine to keep backing up (it sees the clone and skips it).
List ingested sessions with event and edit counts, model, and project path.
Print counts (sessions, events, tool calls, thinking blocks, file edits, vectors indexed, projects, episodes with resolved/unresolved/low-confidence breakdown) and the data directory path. Byte sizes are not here — longhand doctor's "Storage" row has those.
List inferred projects with category, session/edit counts, and last-seen date.
Export an episode or session as standalone markdown. target is an episode ID (ep_*), a session ID (prefix match), or a shortcut: latest (most recent episode) or latest-fix (most recent resolved episode). Prints to stdout, or writes to --out/-o.
longhand search <query> [--limit/-n N] [--type TYPE] [--session PREFIX] [--tool NAME] [--file SUBSTR]
Semantic search across all events. Filters: --type (user_message, assistant_text, assistant_thinking, tool_call, tool_result), --session (prefix match), --tool (Edit, Bash, Read, …), --file (path substring). There is no project filter on the CLI command — that exists only on the MCP search tool (project_id/project_name).
Proactive fuzzy recall. Time parsing + project match + episode search — the command you'll use most. --max/-n caps episodes considered (default 5). --raw also prints raw episode metadata below the narrative. --json prints the full result as JSON, the same shape the MCP recall tool returns.
Three modes, plus --json on all of them. A project and --session can't be combined (exits 2 if both are passed).
-
bare
status— recent-work digest: sessions, outcomes, projects, first asks. Flags:--days/-d N(default 7),--limit/-n N(default 10),--project/-p NAME(filter the digest). -
status <project-name>— where did we leave off on X. Git-aware. Flags:--commits/-c N(default 10),--episodes/-e N(default 5). -
status --session/-s <session-id>— the tail of one session so you can pick up where you left off. Flag:--events N(default 10).
longhand recap, longhand continue <id>, and longhand patterns were removed at v1.0 — they do not run, not even with a pointer message. Use status, status --session <id>, and recall "<topic>" respectively.
Chronological view of a session (prefix match on the ID). --limit/-n caps events shown (default 100); --no-thinking hides assistant_thinking events. No --offset or --tail on the CLI — those pagination options exist only on the MCP get_session_timeline tool.
Reconstruct the state of a file at a point in a session, with syntax highlighting. Omit --at-event for the state at session end. See MCP Tools Reference → replay_file for exactly how "reconstruct" works and where it's a fragment rather than the true original.
Show the before/after content of a single Edit/Write/MultiEdit event.
Extract git operations (commits, pushes, checkouts, merges — including ones that failed, which plain git log never shows) from one session or across all of them. --query/-q searches commit messages; --type/-t filters by operation type. Omit both session-id and --query to see recent operations across all sessions.
Every edit to a file across all sessions, chronologically. Tries an exact path match first, then falls back to a substring match across multiple files.
Wire the SessionEnd (full ingest on close) + Stop (cheap live-tail every turn) hooks into ~/.claude/settings.json. install also auto-upgrades a stale pre-0.5.2 hook that still references the retired $CLAUDE_TRANSCRIPT_PATH environment variable.
Wire the UserPromptSubmit auto-injection hook. Tunable via ~/.longhand/config.json — see Configuration.
install/uninstall register or remove Longhand's MCP server in Claude Desktop's config (~/Library/Application Support/Claude/claude_desktop_config.json — this path is hardcoded for macOS regardless of the host OS, #105). This does not touch Claude Code — Claude Code gets the server from the Longhand plugin's bundled .mcp.json, or from claude mcp add longhand -s user -- longhand mcp-server. mcp serve and the hidden top-level longhand mcp-server both run the MCP server over stdio and are otherwise equivalent — but mcp install writes the hidden mcp-server entry point into Claude Desktop's config (as longhand mcp-server when longhand is on PATH, otherwise python -m longhand.mcp_server), so Desktop never invokes mcp serve. The two also differ in one respect: only mcp-server is excluded from the once-daily update check (#101) — mcp serve, invoked as the mcp subcommand group, is not on that exclusion list, so it can still touch update-check.json when the process exits.
Run the shared-archive MCP server (stdio): four read-only keyword tools over the SQLite archive both Claude and Codex write, with no vector model loaded. Register it as longhand-shared in Claude Code (claude mcp add --scope user longhand-shared -- longhand shared-mcp) and as longhand in Codex. See Codex and MCP Tools Reference → The shared server.
Every Write/Edit to ~/.claude/plans/*.md across all sessions, newest first — pair with replay to reconstruct an earlier version of a plan.
Install (or remove) a macOS-only launchd job, com.longhand.reconcile, that runs longhand reconcile --fix every 30 minutes — belt-and-suspenders for the case where a Claude Code crash was hard enough that neither the Stop nor SessionEnd hook fired. The plist bakes in the resolved LONGHAND_DATA_DIR (launchd doesn't read your shell profile). On Linux, set up the equivalent with cron or a systemd user timer.
Not shown in --help, not part of the 24 above, and not meant to be run directly — documented here only so their names aren't a mystery in a settings file or a process list: context (the query → hook-injection-text formatter that __prompt-hook-run calls; useful standalone to preview roughly what the hook would inject for a given prompt — but not exactly: run standalone it defaults its relevance threshold to 2.0 where the hook passes 2.5, and it has no max_inject_chars cap at all, that's applied by __prompt-hook-run afterward), ingest-session / ingest-live (what the SessionEnd/Stop hooks actually invoke), __prompt-hook-run (the UserPromptSubmit hook's entry point), mcp-server (equivalent to mcp serve, and what mcp install actually points Claude Desktop at), and backfill-episodes (self-heal path recall spawns in the background when the episode vector collection is empty but SQLite has episode rows).