Repository navigation
MCP Tools Reference
Longhand exposes 13 active tools to Claude agents via the MCP protocol. Six more names (search_in_context, get_latest_events, get_project_timeline, get_session_commits, get_episode, match_project) were removed from this listing at v1.0 but keep answering forever, prefixed with a [DEPRECATED] … use … instead migration note — see the table near the bottom. This page is the authoritative reference: what each tool does, when to reach for it, and which tools to avoid using together.
If you're writing prompts or building agents that talk to Longhand, the decision tree below is the most important section. Wrong tool choice is the biggest source of wasted tokens in recall flows.
Current as of v1.3.1. Using Codex too? The four-tool shared server is documented below.
Not every tool caps its output — only 5 of the 13 accept a tunable max_chars; two more truncate at a hard-coded size you can't change; six have no cap at all (#103). Where a cap does apply, the response is truncated and a pagination hint is appended before Claude ever sees it.
| Tool | Cap | Tunable? |
|---|---|---|
search |
12,000 chars (20,000 in context_events mode) |
yes — max_chars
|
get_session_timeline |
16,000 chars | yes — max_chars
|
recall |
16,000 chars | yes — max_chars
|
recall_project_status |
16,000 chars | yes — max_chars
|
find_commits |
12,000 chars | yes — max_chars
|
list_sessions (default mode), list_projects (default mode) |
16,000 chars | no — hard-coded |
list_sessions(project_id=…), list_projects(match=…)
|
none | — (uncapped) |
replay_file, get_file_history, find_episodes (incl. episode_id detail mode), list_plans, get_stats, reconcile
|
none | — (uncapped) |
Absolute ceiling (MAX_OUTPUT_CHARS), where a cap applies |
200,000 chars | caller's max_chars is clamped to this |
A recall or search call is bounded by its cap regardless of history size — a recall over 1,000 sessions costs about the same as one over 10 — but a large replay_file or find_episodes result is not bounded at all, so prefer scoping those with session_id/filters rather than relying on truncation.
- Reading one raw session JSONL directly: 50K–200K tokens per session (Claude Code sessions are typically 1–5MB each).
- Bigger-context-window approaches: every prompt pays the full history, every time.
- Summarizer-based memory tools: cheap per-query but they already threw away the thinking blocks.
Longhand is flat-cost, bounded, and makes zero API calls of its own. The only tokens consumed are the MCP payload Claude reads back.
-
max_chars— accepted by 5 of the 13 tools (search,get_session_timeline,recall,recall_project_status,find_commits). Lower it per-call to shrink payloads further;max_chars <= 0disables truncation entirely on those tools. -
summary_only: true— onget_session_timeline, drops thecontentfield and shrinks payloads ~10×. -
limit/tail/offset— bound the number of events returned rather than the character count.limitis capped at 1,000 on every tool that has one. -
Filters (
session_id,project_name,file_path_contains,event_type,tool_name) — narrowing the search surface reduces noise and keeps results relevant inside the cap. This matters most on the uncapped tools, where there's no truncation safety net at all.
Where a max_chars cap does apply, it's clamped to the absolute ceiling (MAX_OUTPUT_CHARS = 200_000) — but that ceiling only bounds the max_chars argument itself; it does not retroactively cap the six tools that never call the truncation helper.
Start here when deciding which tool to call:
Use recall first. It handles fuzzy time parsing, project matching, and retrieval in a single call, returning a narrative built from conversation segments and session timelines — plus high-precision problem→fix episodes when the work left clean evidence. Do not manually search and paginate — recall was built for this exact use case.
Use search with session_id + context_events. Returns semantic matches WITH surrounding conversation context (N events before and after each match). Do NOT paginate get_session_timeline manually looking for something.
Use get_session_timeline with summary_only: true first to scan the shape of the session, then drill in with search (session_id + context_events) once you know what to look for. Use tail: N for how the session ended or the latest events.
For the session that's running right now: recall and search are both vector-backed, and embeddings only happen at SessionEnd — so neither one sees the in-progress session yet. get_session_timeline works immediately (the Stop hook live-tails every turn), and is the right tool for "what have we done so far this session."
Use get_file_history for the chronological edit list across all sessions. Use replay_file to reconstruct the file's state at any point in any session — exact when the session Write-anchored it, a best-effort fragment reconstruction otherwise (see the tool's row below).
Use find_commits. Pass a query for cross-session commit search (by message, hash prefix, or branch); pass a session_id with no query for every git operation in that session, chronologically.
Use recall_project_status with the project name. Returns recent commits, unresolved issues, last session outcome, and conversation context in one call. Git-aware when git data exists, degrades gracefully without it.
Codex sessions live in the same archive with codex:-prefixed ids. This server lists and pages them (list_sessions, get_session_timeline) and find_commits sees commits made from Codex — but recall and semantic search only see a Codex session once it has been finalized, 30 minutes after the thread goes quiet (1.2.0) — and finalizing only happens while codex-sync or reconcile --fix is actually running (the scheduled reconciler, the launchd template, codex-sync --watch, or a manual run); nothing finalizes a quiet thread with no process invoked. longhand codex-sync --semantic finalizes immediately. Even once finalized, this server only sees it if it started (or last opened its index) after that point — it keeps the index it opened with. For anything active or recent, use the shared server's search.
Avoid these — they waste tokens and return worse results:
-
Never paginate
get_session_timelinein a loop looking for something specific. Usesearchwithsession_id+context_eventsinstead. -
Never use
searchwithoutsession_idwhen you already know which session to look in. Unscoped search returns noise from all sessions. -
Never skip
recallfor "do you remember" questions. Manually stitching togetherlist_sessions+search+get_session_timelinedoes worse than whatrecalldoes natively. -
Don't call the deprecated names (
search_in_context,get_latest_events,get_project_timeline,get_session_commits,get_episode,match_project). They still answer — with a migration preamble — but the surviving tools take the same parameters directly.
-
list_sessions→ identify the session -
search(session_id, query, context_events)→ find the discussion with surrounding context - (Optional)
get_session_timelineat a specific offset if you need even more surrounding context
-
recall(query)→ projects, narrative, and any high-precision episodes - (Optional)
search(session_id, context_events)to read the raw conversation around a result
-
recall_project_status(project)→ recent commits, unresolved issues, last outcome, conversation context - (Optional)
search(session_id, ...)to drill into a specific session from the results
-
get_file_history(file_path)→ every edit chronologically -
replay_file(session_id, file_path)→ reconstructed file state at a point in time (exact from aWriteanchor, a best-effort fragment otherwise)
Grouped by use case.
| Tool | Purpose |
|---|---|
recall |
Start here for "do you remember" queries. Fuzzy time parsing, project matching, and retrieval in one call. Returns a prebuilt markdown narrative from conversation segments and session timelines, plus matched projects and — when the work left clean problem→fix evidence — high-precision episodes with diffs, verbatim thinking blocks, and reconstructed file states. Age-gap note (1.2.2): when the query carries no time phrase and the top episode is both ≥30 days old and ≥30 days older than the newest of the other returned episodes (not necessarily the #2-ranked one — whichever runner-up has the most recent date), the narrative leads with "⚠ Older than the other matches" naming both dates — ranking itself is never reordered, this only surfaces the gap. The same note is on RecallResult.age_gap_note and appears in the UserPromptSubmit hook's injected text as Note: …. |
recall_project_status |
"Where did we leave off on X?" Recent commits, unresolved issues, last outcome, conversation context, and a drift check (stale / stale_reason point at the reconcile tool when on-disk transcripts exceed what's indexed). |
list_projects |
Browse all inferred projects (compact by default; verbose: true adds aliases/keywords/languages). Pass match for fuzzy candidates with scored reasons — "which project did you mean?" |
| Tool | Purpose |
|---|---|
search |
Semantic search across all events, with filters (session_id, event_type, tool_name, file_path_contains, project_id/project_name). Pass context_events with a session_id to get each match wrapped in N surrounding events — the windowed-reading mode (that mode only honors session_id/event_type; other filters are silently ignored — see Key filters below). Auto-scope only triggers when none of session_id/project_id/project_name is set and the query text resembles a known project (the payload says so via auto_scoped_to); pass project_id/project_name explicitly alongside a session_id any time you want to combine a project and a session on purpose — that works fine. What doesn't work: the documented escape hatch. #102 is that auto-scope can't be turned off when you genuinely want an unscoped search whose text happens to resemble a project name — the payload's own hint ("Pass project_name=None to override") is a no-op, because the MCP bridge treats an explicit JSON null the same as omitting the key, so auto-scope re-triggers anyway. |
| Tool | Purpose |
|---|---|
list_sessions |
List recent sessions, optionally filtered by project path substring. When that filter matches a known project whose on-disk transcripts exceed what's indexed, the response wraps a {stale, stale_reason, sessions} envelope instead of a plain array — call reconcile with fix: true. Pass project_id (plus optional since/until) for that project's session timeline enriched with outcomes; that mode is uncapped (see Token budget). |
get_session_timeline |
Chronological view of a session (session ID prefix match). tail: N = the true last N events, even on sessions over 5,000 events (fixed in 1.2.3 — it used to return the middle of long sessions); offset/limit paginate; summary_only: true scans without content. Also accepts include_thinking (default true) and event_type to filter to one type; unknown/aux event rows are filtered out by default either way. |
| Tool | Purpose |
|---|---|
find_episodes |
Structured search for problem→fix pairs (project_ids, since/until, keyword, has_fix, min_confidence). Pass episode_id instead for full detail on one episode: referenced events, diff, and post-fix file state (reconstructed the same way replay_file is — see its caveat below, under File reconstruction). Both modes are uncapped. |
| Tool | Purpose |
|---|---|
replay_file |
Reconstruct a file's state at any point in a past session by replaying its edits from SQLite. Exact when the session wrote the file with Write before the target point; otherwise reconstruction starts from the first Edit's old_string — a fragment, not necessarily the true original file — and applies edits forward from there. If the session only ever Read the file (no edits), returns that Read's snapshot instead (source: "read_snapshot"). Uncapped output. |
get_file_history |
Every edit to a file across all sessions, chronologically. |
| Tool | Purpose |
|---|---|
find_commits |
With a query: search all sessions by commit message, hash prefix, or branch name. With a session_id and no query: that session's full chronological git story (commits, pushes, checkouts, merges — including the failed ones git log never shows). |
| Tool | Purpose |
|---|---|
list_plans |
Every Write/Edit to ~/.claude/plans/*.md across your history, newest first — pair with replay_file to reconstruct an earlier version of a plan. |
get_stats |
Counts only — sessions, events, tool_calls, thinking_blocks, file_edits, projects, episodes, resolved_episodes, low_confidence_episodes, resolved_rate_pct, outcomes, git_operations, git_commits, segments, and the vector count for the events collection specifically (not sessions/projects/segments/episodes). There is no unresolved_episodes field — derive it as episodes - resolved_episodes - low_confidence_episodes if you need it. No byte sizes and no data_dir — use longhand doctor for storage footprint in bytes. Health check; uncapped output. |
reconcile |
Re-ingest on-disk transcripts missing from the index (self-heal after a staleness banner) and, since 1.3.1, transcripts that grew after their last full ingest and have been quiet for 30+ minutes — a turn the session's own hooks never captured (changed_count; ones still being written are only counted, as settling_count). Dry run by default since 1.0 — pass fix: true to apply. With a Codex home present it also reports and, with fix, captures Codex rollouts and finalizes the quiet ones (codex_on_disk, codex_pending, codex_skipped_subagents, codex_oversize, codex_ingested, codex_deferred, and since 1.2.0 codex_unfinalized, codex_settling, codex_finalized). |
A second, deliberately small MCP server over the same SQLite archive — four read-only keyword tools, no Chroma, no embedding model. It is the server Codex talks to (codex mcp add longhand -- longhand shared-mcp), and, registered in Claude Code as longhand-shared, the way Claude searches Codex history by phrase. Setup on the Codex page.
| Tool | Purpose |
|---|---|
list_sessions |
Recent sessions from both clients, newest first. source: "codex" or "claude" narrows to one client; project matches a substring of the project path; limit (default 10, max 50) / offset paginate. |
search |
Find a literal phrase (up to 200 characters) in stored text — keyword matching, not semantic. session_id must be an exact match here, unlike the semantic server's tools (no prefix matching). Results come back newest-first as 2,000-character excerpts, each with a total_chars so you know if there's more; a broad query on a large archive can hit the server's instruction budget — narrow with session_id. limit defaults to 10, max 50. |
get_session_timeline |
Consecutive events of one session (exact session_id, no prefix matching), ordered by timestamp with sequence only as a tiebreak — sequence alone would interleave subagent (sidechain) threads, which restart their own sequence at 0 under the parent session_id. Returns is_sidechain on each row and hides the parser's #-suffixed collision duplicates. offset/limit (default 10, max 50) paginate. |
get_event_text |
An exact 8,000-character slice of one event's text (offset pages through longer records), or its stored raw JSON with raw: true. |
What it does not do: recall, semantic search, file replay, episodes. Those stay on the 13-tool server above, which sees a Codex session once it has been finalized — 30 minutes after the thread goes quiet, but only while codex-sync/reconcile --fix is actually running to do the finalizing (1.2.0) — or immediately with longhand codex-sync --semantic.
These six names left the list_tools() listing at v1.0 — an agent discovering tools fresh won't see them — but the dispatcher still answers all six calls forever, each reply prefixed with a [DEPRECATED] <name> is retired — use <replacement> instead note, so a saved prompt or CLAUDE.md written against the old names never hard-fails.
| Deprecated | Use instead |
|---|---|
search_in_context |
search + context_events (with session_id) |
get_latest_events |
get_session_timeline + tail
|
get_project_timeline |
list_sessions + project_id (+ since/until) |
get_session_commits |
find_commits + session_id (omit query) |
get_episode |
find_episodes + episode_id
|
match_project |
list_projects + match
|
search accepts these filters. Combine aggressively — specificity beats recall for almost every real query.
-
session_id— supports prefix matching (first 8 chars usually enough) on every semantic-server tool: it's an anchoredLIKE '<prefix>%'against the fullsession_id, and an ambiguous prefix silently resolves to the most recent matching session. Codex session IDs are stored ascodex:<thread-id>— a bare thread-ID prefix with nocodex:matches nothing (no session_id starts with it), not "ambiguous, matches many." Include thecodex:prefix; once you do, keep it long enough (codex:plus a handful of characters is usually too short and genuinely is ambiguous across threads). (The shared server's tools require an exactsession_id— no prefix matching there.) -
context_events— withsession_id: wrap each match in its surrounding conversation. In this mode, onlysession_idandevent_typeare honored —tool_name,file_path_contains, and the project filters are silently ignored, andlimitdefaults to 3 (not 10) with a 20,000-char cap (not 12,000). -
event_type—user_message,assistant_text,assistant_thinking,tool_call,tool_result -
tool_name—Bash,Edit,Write,Read,Grep, etc. -
file_path_contains— substring match on file path -
project_id/project_name— filter to one inferred project
Five tools truncate to a tunable max_chars budget (12,000–20,000 by default), two more truncate at a fixed 16,000 you can't change, and six have no truncation at all — see the Token budget table above (#103 tracks closing that gap). Where truncation does apply, the response carries a hint naming the parameters that actually exist on that tool. If you hit a truncation warning, your next call should narrow filters or use offset / limit / tail — not call the same tool again and hope for different results. On an uncapped tool, there's no such warning to catch a runaway response — scope with session_id/filters up front instead.