agentleFS
rpeckrpeck/claude-explorer/AGENTS.md

claude-explorer

AGENTS.md26 starsChanged 20 days agoApache-2.0View on GitHub

Two rules from the user (2026-11-14). They apply to every source (Desktop, Claude Code, Cowork local and remote) and to the list, the viewer, search, and the MCP tools. 1. Show every session that has a turn. The user may want to see and search any session that had an effect on their work. - A turn is a user message or an assistant message. A session with only an assistant turn still has a turn. - Hide only a…

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

28 rules. About 0 are common, 9 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never hide a session because a field is missing, such as the first user message or a title.

    line 16
  2. Distinctive:

    Never delete or mark an archived session because its source is gone.

    line 23
  3. Distinctive:

    All UX flows and rules are documented in UX.md.

    line 56
  4. Distinctive:

    All testing guidance starts at TESTING.md: how to run the suites and trust the result, how to write tests, what CI proves, and how to …

    line 60
  5. Distinctive:

    Read §0 and the file for your task before you write, review, or report on tests.

    line 63
  6. Very specific:

    After installing (uv sync), use the claude-explorer command:

    line 141
  7. Distinctive:

    Start the web server to browse and export conversations.

    line 231
  8. Very specific:

    Every launcher starts the server if port 8765 does not answer, opens the browser, and stops only a server that it started.

    line 293
  9. Very specific:

    Never probe a PID with os.kill(pid, 0) on Windows: it calls TerminateProcess.

    line 316
  10. Distinctive:

    Keep applet state in globals, not properties.

    line 336
  11. Very specific:

    Do not switch ports automatically.

    line 366
  12. Very specific:

    Desktop conversations: every fetch route runs the drift pass before it reports success (_reindex_search_after_fetch in …

    line 407
  13. Very specific:

    Never keep a per-thread connection open past its thread.

    line 420
  14. Very specific:

    Never write DELETE FROM messages WHERE conv_uuid = ?

    line 437
  15. Very specific:

    If you change the schema, bump backend/search_index.SCHEMA_VERSION and the next process startup will drop+rebuild on its own.

    line 468
  16. Very specific:

    Behavior: if ~/.claude-explorer/credentials.json is missing OR the fetch returns 401/403/cf-mitigated, the backend invokes …

    line 476
  17. Very specific:

    One credentials loader and one conversion: Every caller that builds a ClaudeFetcher reads the file with …

    line 515
  18. Very specific:

    Read the primary org from primary_org_id.

    line 519
  19. Very specific:

    Use uv to manage the Python virtual environment:

    line 525
  20. Distinctive:

    Start the frontend (in another terminal):

    line 575
  21. Very specific:

    When ~/.claude-explorer/config.json fails to parse (editor crash mid-save, truncated JSON, non-dict root, permission flip, non-UTF-8 …

    line 593
  22. Very specific:

    Every writer route checks the flag via _refuse_if_config_corrupt(settings) (defined in backend/deps.py) and returns HTTP 503 with a …

    line 596
  23. Very specific:

    Every caller copies the local sources into the archive through backend/write_gate.py:run_archive_syncs(store, reason, lock_timeout_s) …

    line 609
  24. Very specific:

    MCP: no wait, inline, at most once per debounce interval.

    line 619
  25. Very specific:

    Never store or show an fs_path result.

    line 623
  26. Very specific:

    Cloud-sync gate (plan D13): No Explorer writer puts data into a folder that a cloud client syncs until the user opts in.

    line 626
  27. Very specific:

    No CORS: Do not add CORSMiddleware back.

    line 654
  28. Distinctive:

    If a hook fires during normal editing, READ the warning — don't paper over it with a config override.

    line 724

≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Claude Explorer

Guiding Principles

Two rules from the user (2026-11-14). They apply to every source (Desktop, Claude Code, Cowork local and remote) and to the list, the viewer, search, and the MCP tools.

  1. Show every session that has a turn. The user may want to see and search any session that had an effect on their work.
    • A turn is a user message or an assistant message. A session with only an assistant turn still has a turn.
    • Hide only a session with no turns: a 0-byte file, or a file with only metadata or setup events (for example a remote task that was opened but never got a prompt).
    • Never hide a session because a field is missing, such as the first user message or a title. Use a fallback value.
    • A user control may hide sessions (for example "Show empty sessions"), but the default code path must not.
  2. Keep all history, even when Claude removes it. Claude Code deletes old session files, and the claude.ai API stops listing deleted tasks and conversations. The archive must keep its copy.
    • Never delete or mark an archived session because its source is gone.
    • A sync adds and updates. It does not remove. The Desktop fetch and the remote-task sync follow this rule.
    • Claude Code and local Cowork sessions (#92, 2026-11-27): the copy pass mirrors ~/.claude/projects into <data_dir>/machines/<machine_id>/claude-code/projects/ and the local Cowork root into .../machines/<machine_id>/cowork/ (backend/archive_sync.py:sync_machine_tree). Copy metadata and revisions go to the sync/ folder beside the mirror, so the readers read the mirror unchanged.
      • The machine id is a random UUID in ~/.claude-explorer/machine.json, never in data_dir and never the host name.
      • The readers read every machines/*/ folder, live first by uuid. When Claude Code deletes a session file, the drift pass deletes the rows of the live path and indexes the archive copy.
      • MCP does not copy (a first copy can be gigabytes); Refresh and the CLI stop after 20 s, and the watcher copies the rest.
    • Other machines (#92, 2026-11-27): backend/machines.py moves a machine's allowed sessions to another archive, on the same machines/<id>/ layout: bundles (archive export, archive import) and the shared sync folder (shared_archive_dir, a pass of run_archive_syncs).
      • Nothing leaves by default: export-rules.json starts in mode "off".
      • An import and a pull only add and append. Each machine writes only its own folder in the shared folder, which never holds the search index and needs its own D13 consent (allow_writes_in_shared_archive).
      • Another machine's Codex goes to machines/<id>/codex/<home_key>/; this machine's stays in codex/<home_key>/.
      • Tests never see this Mac's machine id: the root conftest.py gives a test that keeps the real home a temporary identity file.

UX Rules

All UX flows and rules are documented in UX.md. Code changes that affect UI behavior MUST keep that document accurate; failing-test-first applies (see the "Code Style" section below).

Testing Rules

All testing guidance starts at TESTING.md: how to run the suites and trust the result, how to write tests, what CI proves, and how to verify each platform by hand. TESTING.md is a short index. Its table maps each section number to a file in testing/. Read §0 and the file for your task before you write, review, or report on tests.

The test-execution integrity rule is a hard invariant. It now lives in TESTING.md §0. Never report a suite as passing without it.

Before you commit or report work as done, run uv run python scripts/check.py until it passes. It runs the same checks as CI. The pre-commit hook refuses a commit of content that no green run covers; never bypass it with --no-verify. If the checks fail, say so plainly.

Performance Work

Three project-specific invariants the 2026-05-22 → 2026-05-23 search-perf hunt earned. Full walk: PLANS/POSTMORTEM-search-typing-lag-2026-05-22.md. Testing protocol: §5.14. Council-driven perf workflow: ~/.claude/agents/llm-council-coding.md Rules P0–P11.

  1. No useContext() of a churning provider in any list-rendered component (N ≥ 100 rows). Known churning providers in this codebase: SettingsContext, SearchPanelContext, BookmarksContext — their value identity changes on every keystroke, toggle, or navigation. useContext bypasses React.memo (Fiber resolves context deps in beginWork before the bailout check), so subscribing from a row component re-renders every row on every context flip. The list-owning parent (ConversationPage) calls useContext once and threads relevant fields as props. Carve-outs: dispatch-only contexts with stable function identity, and useMemo([])-stabilized config contexts.
  2. Memoize every <Provider value={{...}}> with useMemo + explicit deps list. Inline object literals rebuild value identity every render and fire the entire subscriber graph. Pattern lives in SearchPanelContext.tsx and SettingsContext.tsx.
  3. For any user-reported "feels slow", the first commit on the branch is a measurement commit. Output: one number from PerformanceObserver Long Task total OR cProfile wall time on the real corpus (not a 3-row synthetic). Every subsequent commit must move that number, or revert. A user re-reporting the same symptom after a fix shipped is a falsification event for the diagnosis — re-instrument, don't stack a second fix in the same suspected layer. Instrumentation snippet in §5.14.

Project Structure

├── backend/          # FastAPI backend (Python)
├── frontend/         # React frontend (TypeScript)
├── fetcher/          # mitmproxy addon for fetching conversations (Python)
├── mcp_server/       # stdio MCP server (5 tools, FastMCP)
├── scripts/          # build-mcpb.py, closure analyzer, format checks
├── assets/           # mcpb-icon.png, mcpb-README.md (Extensions panel)
├── PLANS/            # Implementation plans
└── pyproject.toml    # Python dependencies (version is dynamic, read from
                     #   mcp_server/__init__.py:__version__ — single source
                     #   of truth for pip + MCP serverInfo + MCPB manifest)

MCPB bundle (Claude Desktop extension)

scripts/build-mcpb.py produces dist/claude-explorer-${VERSION}.mcpb — the drag-drop Claude Desktop extension that wraps mcp_server.server's 5 tools. Pipeline:

  1. scripts/mcpb_import_closure.py walks the eager-import graph of mcp_server.server (skips function bodies — that's the supported escape hatch for lazy-importing heavy deps like weasyprint inside create_pdf).
  2. Build script copies only the closed-over .py files into the bundle, manually appends a small DYNAMIC_IMPORT_MODULES list for modules backend.store / backend.search lazy-import at call time (backend.cowork_reader, backend.summary_cache, backend.search_index). The Codex source (backend.sources.codex, backend.codex.*, backend.archive_sync) needs no entry: the registry imports it eagerly, so the analyzer finds it.
  3. Writes a stripped pyproject.toml with ONLY the deps the MCP path uses: the 5 that the analyzer finds (fastmcp, pydantic, orjson, platformdirs, portalocker; the last one is the archive lock), plus zstandard>=0.23; python_version < '3.14' by hand. backend/codex/zstd.py imports it inside a function (Python 3.14+ uses compression.zstd), so the analyzer cannot see it, and EXPECTED_EXTERNAL_DEPS does not list it.
  4. Writes manifest.json with manifest_version: "0.4" + server.type: "uv" — Claude Desktop ships Node but not Python, so UV resolves + installs on the user's machine on first launch.
  5. Runs mcpb pack (npm install -g @anthropic-ai/mcpb if missing).

Closure-canary invariant. mcp_server/tests/test_mcpb_closure.py fails the suite if a future PR pulls FastAPI / weasyprint / mitmproxy / watchdog into the MCP code path. If the canary fires, DO NOT loosen the test — find the import and either move it inside a function body (lazy) or remove it from the MCP code path. The bundle is supposed to stay around ~500 KB; pulling in even one of those would balloon it past 30 MB.

CI release wiring (.github/workflows/release.yml build-mcpb job) runs the same script on every v* tag push and attaches the artifact to the GitHub Release alongside the wheel.

CLI Usage

After installing (uv sync), use the claude-explorer command:

# Step 1: Capture credentials (a browser window opens; log in to Claude)
claude-explorer capture

# Step 2: Fetch all conversations
claude-explorer fetch

# Step 3: Start the web server to browse
claude-explorer serve
# Then open http://localhost:8765

Command Reference

claude-explorer capture

Capture the Claude session credentials into ~/.claude-explorer/credentials.json.

Options:
  -o, --output PATH      Where to save credentials
  -t, --timeout INTEGER  Max seconds to wait for login (default: 300)
  --proxy                Use mitmproxy and Claude Desktop instead of a browser
  --port INTEGER         Proxy port when using --proxy (default: 8080)

Default (browser): fetcher/playwright_capture.py opens a Chromium window. After you log in, it reads the sessionKey cookie and the orgs.

--proxy (mitmproxy):

  1. Starts mitmproxy with the addon fetcher/mitmproxy_addon.py. cli/main.py finds the addon through its module, not through a path next to cli/. From v1.0.0 to v1.1.9 the path named cli/mitmproxy_addon.py, which does not exist. mitmproxy stopped at once with "No such script", and --proxy failed every time.
  2. You launch Claude Desktop through the proxy.
  3. The addon extracts sessionKey and the org ids from API requests.

Platform-specific launch commands for --proxy:

# macOS
open -a "Claude" --args --proxy-server="127.0.0.1:8080" --ignore-certificate-errors

# Windows
"C:\...\Claude.exe" --proxy-server="127.0.0.1:8080" --ignore-certificate-errors

# Linux
claude --proxy-server="127.0.0.1:8080" --ignore-certificate-errors

claude-explorer fetch

Download all conversations from Claude using captured credentials.

Options:
  --output-dir PATH               Where to save JSON files
                                  (default: the data directory that the app reads,
                                  ~/.claude-explorer/conversations unless
                                  CLAUDE_EXPLORER_DATA_DIR or config.json moves it)
  --credentials PATH              Path to credentials file
                                  (default: ~/.claude-explorer/credentials.json)
  --session-key TEXT              Session key (overrides credentials file)
  --org-id TEXT                   Org ID (overrides credentials file)
  --incremental / --full-refresh  Skip already-saved conversations (default: incremental)
  --delay FLOAT                   Seconds between requests (default: 0.3)
  --limit INTEGER                 Max conversations to fetch
  --verbose                       Show detailed output

Examples:

# Fetch all new conversations
claude-explorer fetch

# Re-fetch everything
claude-explorer fetch --full-refresh

# Fetch only 10 conversations with verbose output
claude-explorer fetch --limit 10 --verbose

# Use custom credentials
claude-explorer fetch --session-key "sk-ant-..." --org-id "uuid-..."

claude-explorer serve

Start the web server to browse and export conversations.

Options:
  --host TEXT       Host to bind to (default: 127.0.0.1)
  --port INTEGER    Port to bind to (default: 8765)
  --reload          Enable auto-reload for development

Examples:

# Start server
claude-explorer serve

# Start on different port
claude-explorer serve --port 9000

# Development mode with auto-reload
claude-explorer serve --reload

claude-explorer install-watcher (cross-platform — strongly recommended)

Install a supervised job that runs the CC image-cache watcher continuously, independent of claude-explorer serve. Without this, the watcher only runs while the dev server is up — Claude Code can rotate images off disk during downtime, causing permanent data loss.

The CLI dispatches by sys.platform:

  • macOS → launchd user agent (~/Library/LaunchAgents/com.claude-explorer.cc-watcher.plist)
  • Linux → systemd user unit (~/.config/systemd/user/claude-explorer-cc-watcher.service); also run sudo loginctl enable-linger $USER to survive logout
  • Windows → Task Scheduler task ClaudeExplorerCCWatcher (logon-triggered, runs the launcher at %USERPROFILE%\.claude-explorer\cc-watcher.py via pythonw.exe)

The watcher uses watchdog for event-driven capture (FSEvents on macOS, inotify on Linux, ReadDirectoryChangesW on Windows) — sub- second latency, near-zero idle CPU. A periodic backstop poll (default 600s = 10 min, overridable via --interval or env var CLAUDE_EXPLORER_CC_WATCHER_INTERVAL_SEC) catches the rare event the OS dropped or coalesced.

uv run claude-explorer install-watcher

# Verify (per platform):
launchctl list | grep claude-explorer                                 # macOS
systemctl --user status claude-explorer-cc-watcher.service            # Linux
schtasks /Query /TN ClaudeExplorerCCWatcher                           # Windows

# Logs (macOS):
tail -f ~/Library/Logs/claude-explorer-cc-watcher.{out,err}

# Tune the backstop poll interval (default 600s):
uv run claude-explorer install-watcher --interval 60

# Uninstall:
uv run claude-explorer install-watcher --uninstall

claude-explorer install-app (every platform)

Adds a launcher, so a user can start Claude Explorer without a terminal. Every launcher starts the server if port 8765 does not answer, opens the browser, and stops only a server that it started. Install code: cli/app_launcher.py.

PlatformLauncherStop
macOS~/Applications/Claude Explorer.appQuit the app
WindowsStart menu shortcut, runs pythonw.exe -m cli.desktop_launcher trayTray icon, Quit
Linux~/.local/share/applications/claude-explorer.desktop, runs ... openRight-click action, runs ... stop

On every platform the sidebar's power button (UX.md → "Quit (power button)") also stops the server: POST /api/shutdown raises SIGINT in the server's own process, exactly like Ctrl+C (backend/shutdown.py), so claude-explorer serve exits with code 0. The route requires the header X-Claude-Explorer-Action: shutdown and a same-origin or loopback Origin, so another website cannot stop the server. The macOS applet's idle handler quits the app when the server it started is gone, and the Windows tray removes its icon. Linux needs nothing: open does not stay running.

Windows and Linux share cli/desktop_launcher.py. It records the PID and port of each server that it starts in ~/.claude-explorer/launcher-server.pid. Linux has no tray icon: GNOME shows none without an extension, and pystray's Linux backends need GTK bindings that a uv tool install lacks. Never probe a PID with os.kill(pid, 0) on Windows: it calls TerminateProcess. The launcher watches the port there instead.

macOS details:

  • What it is: an AppleScript stay-open applet, compiled on the user's Mac with osacompile. A locally made file has no quarantine flag, so it needs no notarization.
  • Open: starts claude-explorer serve if port 8765 does not answer, then opens the browser. Server output goes to ~/Library/Logs/claude-explorer-serve.log.
  • Quit: stops the server, but only a server that the app started.
  • Refuses a uvx interpreter, like install-watcher.

Three traps, each hit while building it:

  1. The start command must redirect stdin, stdout, and stderr, and background only the server. cd /tmp && nohup cmd & echo $! kept the output pipe of do shell script open, and the app could not receive Quit.
  2. Keep applet state in globals, not properties. An applet writes changed properties back into its bundle, which breaks the signature.
  3. Changing the icon or Info.plist breaks the ad-hoc signature, so build_app re-signs the bundle with codesign --force -s -.
claude-explorer install-app              # install or rebuild
claude-explorer install-app --port 8766  # use another port (default 8765)
claude-explorer install-app --uninstall  # remove

The launcher keeps the port that install-app gave it, and install-app saves it in ~/.claude-explorer/launcher-port. A later install-app without --port (the upgrade steps run one) reuses it; --uninstall deletes it. Windows and Linux pass --port to cli.desktop_launcher (tray and open); stop reads the port from the PID file. On 2026-10-13 an Emacs process held 8765 on a user's laptop, so the app could not start until it used another port.

Port conflict message. Many users are not developers. When another program holds the port, every launcher and serve say so in plain words, and give the exact fix command with a port that is free now:

  • port_in_use (cli/desktop_launcher.py) is a bind test with the same socket options as asyncio, so it agrees with uvicorn.
  • Windows and Linux: report_port_conflict shows the message. Windows also puts the command on the clipboard.
  • macOS: the applet runs the hidden claude-explorer port-check before it starts serve. Line 1 of the output is the command for its Copy Command button; the rest is the dialog text.
  • Do not switch ports automatically. The web page keeps settings in localStorage, which is per address, so a changing port loses them.

claude-explorer reindex-search (manual override only)

Force a rebuild of the SQLite FTS5 search index at ~/.claude-explorer/search-index.sqlite. You should not need this in normal operation: the index is built automatically at backend startup (non-blocking lifespan task) and kept in sync by the same watcher loop that handles CC images (event-driven via watchdog, with a 600s backstop poll). Use only when:

  • the index file got corrupted (delete it, then run this);
  • you want a known-fresh full rebuild;
  • a future schema bump requires manual rebuild without restarting serve.
# Default: full DROP + rebuild from scratch.
uv run claude-explorer reindex-search

# Drift-only pass (re-index only files whose mtime changed since last index).
uv run claude-explorer reindex-search --drift

How search works in the running server:

  • backend/search_index.py owns the SQLite FTS5 schema, lifecycle, and queries. Singleton via get_search_index(); returns None on sqlite3 builds without FTS5.
  • backend/search.py:search_conversations is a dispatcher: prefer the FTS5 fast path when idx.is_ready(), fall back to the linear-scan code on any failure (initial build still running, FTS5 unavailable, sqlite3 error). Search never goes "down".
  • Architecture is Scatter-Gather: FTS5 returns (conv_uuid, message_uuid) pairs; the existing Python create_snippet/sort code runs on the matched conversations only (warm via FileCache). Result: byte-for-byte identical SearchResult shape to the linear path for whole-word queries.
  • Three triggers keep the index current. Failures in each are isolated.
    • Claude Code and Cowork sessions: watchdog events on ~/.claude/projects and the Cowork root start a debounced drift pass.
    • Desktop conversations: every fetch route runs the drift pass before it reports success (_reindex_search_after_fetch in backend/routers/fetch.py). The watcher does not observe the Desktop conversations directory.
    • Backstop: backend/cc_watcher.py:scan_once runs the drift pass once per backstop scan (600s default). It catches anything the other two missed.

Read connections close when their thread ends. SearchIndex and SummaryCache open one SQLite read connection per thread through backend/sqlite_read_conns.py. Each event-driven drift pass runs on a new threading.Timer thread, and anyio workers end after 10 s idle.

  • Never keep a per-thread connection open past its thread. Before 2026-11-08 a registry kept them until close(). The supervised watcher then held 1262 connections after 46 days, and every drift pass failed with Too many open files, so the index lagged by days (issue #33).
  • backend/tests/test_read_conn_thread_leak.py pins this: it counts the open file descriptors on the index file (on Windows, all the handles of the process).

At most one drift pass runs at a time, and a delete never scans messages. On 2026-11-11 the restarted watcher still went from 4 to 146 descriptors on the index in 11 minutes, by two causes together:

  • A delete by conv_uuid read every row. conv_uuid is an UNINDEXED FTS5 column, which FTS5 cannot index, so each upsert scanned all 393,517 rows (8.9 s cold) while it held the write lock.
    • Writes now find a conversation's rows in the message_rowids map and delete them by rowid.
    • Never write DELETE FROM messages WHERE conv_uuid = ?; use SearchIndex._delete_messages_of.
    • The map is additive, with no SCHEMA_VERSION bump. Code from before it ignores the map, and _sync_message_rowids rebuilds the map when such code changed messages. A version bump would make old processes drop and rebuild the whole index.
  • Drift passes overlapped. Each event during a slow pass started one more pass on a new Timer thread, and each waited for the write lock with an open read connection.
    • _run_drift_single_flight (backend/cc_watcher.py) lets one pass run. An event or a backstop scan during it makes it run once more.
    • The fetch routes still run their own pass, because complete must wait for it. The 409 guard allows only one fetch at a time.

A file that loads as nothing leaves the drift backlog. On 2026-11-13 six files stayed in the backlog for good, and every pass read them again: four 0-byte Claude Code sessions and two remote Cowork tasks that hold only setup events (the task was opened, but no prompt was sent).

  • _note_unloadable (backend/search_index.py) records such a file with its mtime and size. The drift scan skips it until one of them changes, and the watcher log gets one line for it.
  • The record is in memory, one per process. A new version of a reader thus reads each such file once again, and the index file gets no rows that an older watcher process does not know.
  • A file that cannot be opened is not recorded. The readers turn an OSError into "no entries", so "Too many open files" looks like an empty file. The next pass tries again.
  • The list and the viewer still hide both kinds: a 0-byte file has no entries, and a Cowork session with no turns has nothing to show (D6).

If you change the schema, bump backend/search_index.SCHEMA_VERSION and the next process startup will drop+rebuild on its own.

Web UI Refresh button (Build-9)

The sidebar Refresh button owns the full pipeline — capture + fetch — so the user never has to drop to the CLI to re-capture credentials.

  • Endpoint: GET /api/fetch/refresh?incremental=true (SSE).
  • Behavior: if ~/.claude-explorer/credentials.json is missing OR the fetch returns 401/403/cf-mitigated, the backend invokes fetcher.playwright_capture.capture_credentials in-process. On success it persists creds (atomic write, 0o600) and continues with an incremental fetch automatically.
  • Capture is run at most once per request. A post-capture fetch that still 401s emits a final error event — no retry loop.
  • Concurrency: one module-level flag, _refresh_in_progress, guards /fetch/refresh, /fetch/start, and POST /fetch/conversation/<uuid> (single-conversation re-fetch). A second fetch of any kind returns 409 Conflict. Frontend disables the button while running, so 409 is defense-in-depth.
    • The route sets the flag. _FetchStreamResponse clears it when the response ends, also when the client leaves before the first chunk. A finally in the stream alone left the flag set in that case, and every later fetch got 409.
  • SSE event types: capture_start, capture_waiting_login (heartbeat every 25s during the 5-min login wait), capture_done, capture_error, plus the existing start, progress, complete, error.
  • Manual override: the Details modal's "Full Refresh" and "Fetch New" buttons still hit /fetch/start directly with no auto-capture.
  • Search is current at complete. The backend re-indexes search before it emits complete. The frontend then calls invalidateAfterFetch (frontend/src/lib/queryClient.ts), which marks both the conversations and the search caches stale. A new fetch site must do both, or the Search Pane shows pre-fetch results.

Remote Cowork tasks are a second fetch source. Cowork tasks that run in Anthropic's cloud are not chat conversations: chat_conversations never lists them, and nothing lands in Claude Desktop's local local-agent-mode-sessions/. An account that only runs tasks used to "fetch" 0 conversations. Every fetch path (Refresh, /fetch/start, claude-explorer fetch) now also syncs them through fetcher/remote_sessions.py:

  • API: GET https://claude.ai/v1/code/sessions?tags=cowork-remote and /v1/code/sessions/<id>/events (newest first, cursor=<seq> pages back). Both need the anthropic-beta: ccr-byoc-2025-07-29, anthropic-version, and x-organization-uuid headers. Recorded from the claude.ai web app with Playwright; re-record the same way if the API moves.
  • Storage: <data_dir>/cowork-remote/<org>/remote_<id>/audit.jsonl plus a sibling sidecar, in the local Cowork shape, so backend/cowork_reader.py, the store, and the search index read them unchanged (iter_cowork_session_dirs / find_cowork_session_dirs).
  • Workspace: a remote task gets organization_id from the sidecar organizationId (the <org> directory is the fallback), so the workspace filter shows it. A local Cowork session keeps organization_id = None.
  • Incremental: a session is skipped when its sidecar records the API's updated_at; otherwise only events newer than the highest _sequence_num in audit.jsonl are fetched and appended.
  • Additive: an org without sessions-API access (401/403/404) is skipped; any other failure is a progress message, never a stream error.
  • Tests: the autouse _no_remote_cowork_network fixture (both conftests) stubs RemoteCoworkFetcher._get_json; fetcher/tests/ccr_fake.py is a fake of the API with its real paging.

If you change capture or fetch logic, edit backend/routers/fetch.py (the _capture_phase_stream, _fetch_phase_stream, and refresh_pipeline_stream async generators) and the two web-page consumers of the stream together — the SSE event schema is shared. The consumers are frontend/src/contexts/FetchPipelineContext.tsx (Refresh) and frontend/src/components/fetch/FetchDialog.tsx (Fetch New, Full Refresh); frontend/src/components/fetch/FetchToast.tsx holds their shared text helpers.

One credentials loader and one conversion. Every caller that builds a ClaudeFetcher reads the file with fetcher.credentials.load_credentials and gets its credential arguments from fetcher.credentials.fetcher_credentials: the three fetch routes, claude-explorer fetch, and claude-explorer rehydrate. Do not write another copy of either.

  • Five private copies of the conversion drifted apart. One passed a removed org_id= keyword and crashed every claude-explorer fetch (issue #1). The routes refused a v2 file without the legacy org_id mirror.
  • A plain json.load copy of the loader in fetcher/bulk_fetch.py passed a list or a string on as credentials. fetch and the routes then failed with AttributeError instead of "run capture".
  • Read the primary org from primary_org_id. org_id is only a legacy mirror that CredentialsV2 plans to drop. Only the v1 paths in fetcher/credentials.py read it.

Development Setup

Python (Backend & Fetcher)

Use uv to manage the Python virtual environment:

  • .python-version pins Python 3.13 for development. Without the pin, uv can choose the newest Python on the machine. On 2026-11-08 that was 3.15, and pydantic-core and rpds-py from the lockfile had no wheels for it, so uv sync failed.
  • A job that tests another Python sets UV_PYTHON. uv sync --python X alone is not enough: the next plain uv run replaces the venv with the .python-version Python.
    • The pytest job in install-matrix.yml sets UV_PYTHON, and its step "The venv uses the matrix Python" checks the result. backend/tests/test_workflow_python.py pins the rule for every workflow.
    • Proof (2026-11-09): a CI run without UV_PYTHON ran the 3.14 and 3.15 rows on 3.13, and the check step failed them.
    • The install job does not set it, on purpose: it runs the README's commands as a user types them, and all its rows are 3.13.
  • To use another Python locally (for example offline, with only 3.12 installed), set UV_PYTHON=3.12 in the shell for every uv command.
# Create/sync the virtual environment
uv sync

# Run backend server
uv run uvicorn backend.main:app --reload --port 8765

# Run with dev dependencies
uv sync --extra dev
uv run pytest

The .venv directory is local to the project and managed by uv.

Frontend

cd frontend
npm install
npm run dev    # Development server on http://localhost:5173
npm run build  # Production build

Running the Full Stack

  1. Start the backend:
    # On macOS with Homebrew, set library path for WeasyPrint PDF support:
    DYLD_LIBRARY_PATH=/opt/homebrew/lib uv run uvicorn backend.main:app --reload --port 8765
  2. Start the frontend (in another terminal):
    cd frontend && npm run dev

The frontend proxies /api requests to the backend.

Data Directory

Conversations are stored in ~/.claude-explorer/conversations/ as JSON files.

Set CLAUDE_EXPLORER_DATA_DIR to override, or create ~/.claude-explorer/config.json:

{"data_dir": "/path/to/conversations"}

Corrupt-config safe mode

When ~/.claude-explorer/config.json fails to parse (editor crash mid-save, truncated JSON, non-dict root, permission flip, non-UTF-8 contents), the app does NOT crash and does NOT silently fall back to defaults. Instead it boots in read-only safe mode:

  1. backend/config.py:Settings catches (JSONDecodeError, OSError, TypeError, ValueError) and populates config_corrupt_reason: str | None with a one-line <path>: <ExceptionType>: <message> summary. The reader continues to the next candidate (canonical → legacy) instead of breaking — a valid legacy config next to a corrupt canonical still wins.
  2. Every writer route checks the flag via _refuse_if_config_corrupt(settings) (defined in backend/deps.py) and returns HTTP 503 with a recovery message instead of writing. Currently gated: POST/PATCH/DELETE /api/bookmarks/*, PUT/PATCH /api/preferences, GET /api/fetch/{start,refresh,conversation/{uuid}}, and the claude-explorer fetch CLI.
  3. GET /api/config exposes config_corrupt_reason to the frontend. The lru_cache on get_settings() is cleared on every /api/config call so the user fixing the file mid-session is detected without a server restart.
  4. The frontend renders a persistent (non-dismissible) ConfigCorruptionBanner at the top of the app shell. Dismissing it would re-enable the data-orphaning failure mode it exists to prevent, so the only way to remove the banner is to fix the underlying file.
  5. Reads remain unconditional — /api/conversations, /api/search, /api/conversations/{uuid} all stay at 200 even when corrupt. The user can still browse what's already on disk while they recover.

When adding a new writer route, wire it through _refuse_if_config_corrupt(settings) (or Depends(refuse_if_config_corrupt) if you prefer the FastAPI-dep form). Otherwise a corrupt-config user can silently write to the wrong data_dir and orphan their archive.

install-watcher is intentionally EXEMPT from the writer gate. The launcher template lives under ~/Library/LaunchAgents/ (or systemd/Task Scheduler equivalents), NOT under data_dir, AND the supervised watcher IS the recovery path the user needs to reach when config is corrupt. Gating it would lock the user out of recovery. The CLI test test_install_watcher_runs_when_config_corrupt pins this exemption as a HARD invariant — do not remove.

cc_watcher.scan_once is also NOT gated. Blocking the background CC image-cache watcher during corrupt-config would cause the data loss it exists to prevent (Claude Code rotates images off disk while the watcher is blocked). Only its archive copy of the local sources skips (plan D9): backend/write_gate.py:run_archive_syncs logs one WARNING line per pass, and image capture and the drift pass still run.

Archive copy and the cloud-sync gate

Every caller copies the local sources into the archive through backend/write_gate.py:run_archive_syncs(store, reason, lock_timeout_s) (PLANS/2026.11.18-codex-source.md §4.3). It checks two gates in order, corrupt config and then cloud sync, and then calls each adapter's archive_sync in registry order.

  • Callers and their lock wait:
    • Watcher (_event_drift_pass, the backstop _backstop_drift_pass): no wait, inside the drift single-flight. A busy lock calls _schedule_drift, so the copy runs again after the debounce.
    • Refresh, /fetch/start: up to 60 s in a worker thread, before the capture. A busy lock sends a progress frame with phase: "codex", and the fetch continues.
    • claude-explorer fetch: up to 60 s, before the credentials load.
    • MCP: no wait, inline, at most once per debounce interval; a busy lock gives sync_pending: true.
  • write_gate.py stays MCP-safe: it imports neither backend.cc_watcher, backend.deps, nor a router.
  • Watch roots: the watcher starts one observer per WatchRoot of each adapter and matches its patterns. A root with create=False (another tool's home) is never created; a missing one gets its watch after a later backstop scan. The Cowork root also matches the session sidecar local_*.json.
  • Long paths on Windows: a new file operation under the archive (or anywhere under the data folder) gives its path through backend/long_paths.py:fs_path (open, os.stat, os.replace, mkdir, listdir, shutil). It lists a folder with long_paths.iterdir, glob, or walk, and checks containment with real_path or is_inside.
    • Never store or show an fs_path result. The UI, the API, MCP, the search index, and cache keys keep the normal form.
    • Without the \\?\ prefix, Windows with LongPathsEnabled = 0 refuses a path over 259 characters, and the copy of a long session is lost.

Cloud-sync gate (plan D13). No Explorer writer puts data into a folder that a cloud client syncs until the user opts in. write_gate.cloud_sync_block(settings) returns (provider, folder) while the gate is closed.

  • Detection: backend/cloud_sync.py, on data_dir, search-index.sqlite, and cc-images/. It fails closed.
  • Opt-in: allow_writes_in_cloud_sync in config.json must equal the resolved data_dir. POST /api/write-consent/cloud-sync (backend/routers/write_consent.py) writes it, with the shutdown route's header and Origin rules and the corrupt-config gate.
  • While closed:
    • The fetch routes return 409 before any network call; the CLI fetch refuses. The preferences PUT and PATCH also return 409 (write_consent.refuse_if_cloud_sync_gate, after the corrupt-config dependency).
    • The MCP outline cache (cache.db) is built in memory.
    • The archive copy skips.
    • get_search_index() and get_summary_cache() return None.
    • The lifespan creates no data folder and skips the layout migration.
    • New Claude Code images go to cc_image_cache.pending_dir(). scan_once moves them into cc-images/ after the opt-in.
  • A new writer into data_dir or its siblings must check cloud_sync_block too.

Host-header guard (DNS rebinding)

The server listens on localhost, but any web page can make its own domain resolve to 127.0.0.1 (DNS rebinding). Its requests are then same-origin, so the browser sends no CORS preflight, and the page can read every response and call every route. A probe in the PR #6 review (2026-10-19) read /api/conversations and /api/account, and stopped the server.

  • The guard: backend/host_guard.py refuses (400) every request whose Host is not localhost, 127.0.0.1, or ::1. It is the outermost middleware; a test pins that.
  • Extra names: CLAUDE_EXPLORER_ALLOWED_HOSTS (comma-separated). The root conftest.py adds the test-client names testserver and test.
  • serve --host <network address> sets that variable to * and prints a warning, because the user chose to expose the server.
  • No CORS. Do not add CORSMiddleware back. The web page calls /api on its own origin, and the Vite dev server proxies /api. CORS for localhost:5173 let any project's dev server read the archive.
  • A new state-changing route follows POST /api/shutdown: POST only, a custom header (which needs a preflight that the server never answers), and an Origin check against the guard's allowlist, never against Host.

PDF Export Dependencies

WeasyPrint requires system libraries for PDF generation:

# macOS
brew install pango cairo libffi

# Ubuntu/Debian
apt-get install libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0

# Windows (via MSYS2 — https://www.msys2.org)
# In the MSYS2 shell:
pacman -S mingw-w64-x86_64-pango
# Or skip the system-library install entirely by using the standalone
# WeasyPrint .exe from the WeasyPrint GitHub releases page.

See: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation

macOS DYLD bootstrap (tests + dev server)

macOS Sonoma+ strips DYLD_* env vars from subprocess invocations (SIP), so prefixing uv run pytest with DYLD_FALLBACK_LIBRARY_PATH=... silently no-ops. The tests bootstrap this from backend/tests/conftest.py at import time (sets DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib before WeasyPrint imports), so uv run pytest backend/tests Just Works with no --ignore flags or env-var prefixes.

For the live dev server (claude-explorer serve or uvicorn backend.main:app), set DYLD_LIBRARY_PATH directly on the command line as shown above — the server doesn't go through conftest.

Code Style

  • Python: Follow PEP 8, use type hints
  • TypeScript: Strict mode, prefer functional components
  • Commits: Conventional commit messages, no AI attribution lines

Static-analysis tooling

Three layers run alongside the manual pre-push checklist. Neither replaces it — they cover different failure modes (greps find leaked credentials; LLM/AST tools find logic bugs).

React Doctor (millionco/react-doctor)

Oxlint-based AST scanner for React (~250 rules across architecture, state-and-effects, performance, a11y, correctness). Catches things eslint-plugin-react-hooks doesn't, e.g. inline <Provider value={{...}}> literals via jsx-no-constructed-context-values — directly relevant to the [[Performance Work]] invariant #2.

Two npm scripts:

cd frontend
npm run lint:react        # full-codebase informational scan; never fails CI
npm run lint:react:diff   # pre-push gate: scan files changed vs main, fail on errors

Baseline as of 2026-05-27: 71/100, 346 issues (4 architecture errors + 2 state-and-effects errors + 340 warnings across a11y/perf/correctness). Do not block a push on pre-existing baseline. Pre-push gate is lint:react:diff — fails only if YOUR change introduces a new error.

Known gap: React Doctor does NOT catch [[Performance Work]] invariant #1 (useContext of churning provider in list-rendered components). No public linter does — that one stays a human-review / postmortem rule.

security-guidance plugin (Anthropic, user-scope; Claude Code only, optional)

Real-time PreToolUse hook that intercepts Write/Edit/MultiEdit and warns about eval, pickle, dangerouslySetInnerHTML, child_process.exec, GHA injection, command injection patterns. Free; runs at the harness level (~0 token cost). Installed via claude plugin install security-guidance@claude-plugins-official. Verify with claude plugin list.

If a hook fires during normal editing, READ the warning — don't paper over it with a config override. The hook fires on a curated list of known-bad patterns, not on style preferences.

/security-review slash command (Claude Code only, optional)

Diff-based LLM security review of pending changes on the current branch. If you use another agent, any LLM security review of the diff serves the same purpose; the pre-push gate cares that one ran, not which. Same engine as the anthropics/claude-code-security-review GitHub Action. Covers SQLi, XSS, authn/authz, IDOR, SSRF, weak crypto, RCE/deserialization, hardcoded secrets, supply-chain. Manual invocation only — see the pre-push checklist.

Pre-push checklist (runs before every push that affects the public repo)

Public-flip is a one-way door: once a commit is on origin/main and the repo is public, secrets, personal paths, and AI attribution become permanently public-cached (search-indexed, mirrored by archivers, scraped by training-data crawlers). Run this scan before pushing to a public repo. Every step MUST return clean (or only known-OK matches the maintainer has eyeballed) before push.

# 1. Secrets in unpushed commit diffs
git log -p origin/main..HEAD | grep -nE 'sk-ant-[A-Za-z0-9_-]{10,}|Bearer [A-Za-z0-9_.-]{20,}|"password"\s*:\s*"[^"]+"'

# 2. Personal /Users/<name>/ paths in committed files (excluding docs/PLANS)
git grep -nE '/Users/[a-zA-Z]+/|/home/[a-zA-Z]+/' -- ':!PLANS/' ':!*.md'

# 3. Real session keys / cookies in test fixtures (only "fake-test-key" literals should match)
git grep -nE 'sessionKey.{0,5}[A-Za-z0-9+/_-]{30,}' -- 'backend/tests/' 'fetcher/tests/'

# 4. AI attribution across ALL unpushed commits (NOT just the most recent — check the whole batch)
git log origin/main..HEAD --format='%H %B' | grep -inE 'co-authored-by:.*claude|🤖 generated'

# 5. Accidentally-tracked credential / cache / local files
git ls-files | grep -E '(^|/)\.env$|\.env\.[^.]+$|credentials\.json$|\.sqlite$|\.local$|\.local\.json$'

# 6. Real email addresses outside known-OK list
git grep -nE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' -- ':!*.md' ':!PROCESS/' | \
  grep -v -E 'raymondpeckiii@gmail\.com|noreply@|@example\.(com|org)|user@host'

# 7. ~/.claude or /Users/rpeck/ in files shipped to PyPI sdist
uv build --sdist 2>&1 | tail -3
mkdir -p /tmp/sdist-check && tar xzf dist/*.tar.gz -C /tmp/sdist-check
grep -rnE '/Users/rpeck|~/\.claude(?!-explorer)' /tmp/sdist-check | grep -v PKG-INFO  # PKG-INFO ~/.claude refs are legitimate README content
rm -rf /tmp/sdist-check

# 8. IP addresses outside known-OK list (127.0.0.1, RFC1918, link-local)
git grep -nE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' -- ':!*.md' ':!PROCESS/' | \
  grep -v -E '127\.0\.0\.1|0\.0\.0\.0|169\.254\.|192\.168\.|10\.[0-9]+\.|255\.255'

# 9. Private-infra URLs (internal., grafana, slack channels, linear, etc.)
git grep -nE '(internal\.|\.local/|linear\.app/|slack\.com/archives|grafana\.|datadog\.)' -- ':!PROCESS/'

# 10. TODO/FIXME/XXX in user-facing code (samples below should be intentional documented tech debt only)
git grep -nE 'TODO|FIXME|XXX' -- 'frontend/src/' 'backend/' ':!**/tests/**'

# 11. React Doctor diff-gate — fails on NEW errors in files changed vs main
(cd frontend && npm run lint:react:diff)

# 12. LLM security review of the diff (e.g. /security-review in Claude Code, or your agent's equivalent)
#     /security-review

# 13. Article image/link formats must render on GitHub (co-equal surface with Medium)
#     Fails on Obsidian ![[...]] / [[...]] (literal text on GitHub), spaces or %20 in
#     local image/link paths (GitHub's blob renderer mangles %20), and referenced
#     images that aren't git-committed (404). Earned 2026-06-01 when a public push
#     shipped broken images on every Part 2 screenshot.
python3 scripts/check-article-formats.py

Known-OK matches (won't fail the scan but worth re-eyeballing):

  • fake-test-key and sk-ant-sid01-fake-test-key in backend/tests/, fetcher/tests/ — deliberate fake fixtures.
  • /Users/rpeck/ in test fixtures under frontend/e2e/ — deliberate test data shape mirroring real CC session paths.
  • ~/.claude in PKG-INFO (README copy) and source code — describing the actual home-directory paths the app reads from.
  • claude-exporter (the legacy pre-V1 name) in .gitignore (backwards-compat) and PROCESS/a70251a5/outline.jsonl (frozen historical conversation snapshots).
  • http://claude-explorer.local/ in backend/export.py — base URL for relative-resource resolution in PDF export; not a real infrastructure reference.

Things this checklist does NOT cover (and that you should still think about before flipping visibility):

  • The PROCESS/ directory exposes development-session conversation snapshots. Some maintainers want this; some don't. Decide before flip.
  • The .github/workflows/*.yml reference org-scoped secrets (PYPI_API_TOKEN, OIDC trusted publishing config). On the public repo, these need to be configured under repo Settings → Secrets and variables → Actions BEFORE the first release workflow run.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.