# midden midden archives the transcript of every agent session a person runs: their own Claude Code sessions on any machine, and the sessions of [simmer](https://tangled.org/guid.foo/simmer). Later it archives sessions from other harnesses. It keeps everything: prompts, responses, tool calls, tool results, and subagent turns. midden is useful without simmer. A person's sessions can search their own history. simmer uses midden to explain what its sessions did and to find what a person keeps coming back to, and simmer's sessions add to midden. midden captures through one OTLP endpoint, and serves the archive back as MCP tools: a list of sessions, a session's conversation, and a search of their text. ## The canonical record The canonical record of a session is the harness's own transcript, stored verbatim. For Claude Code, that is the JSONL file under `~/.claude/projects/`. Each line is one entry: a full API message with every content block, or another event of the session. Each entry has a `uuid`, a `parentUuid`, a `sessionId`, and a `timestamp`. midden does not convert entries to its own schema when it writes them. The JSONL format is internal to Claude Code and changes between versions, so midden stores each entry as it arrives, and the read path handles the differences between formats and between harnesses. ## One channel: OTLP Everything reaches midden as OTLP logs over HTTP, at `/v1/logs`, in protobuf and in JSON. Two kinds of log record arrive: - **Transcript entries.** One log record for each JSONL entry. The record's timestamp is the entry's, `event.name` is `transcript.entry`, the attributes are the session ID and the entry's `uuid`, and the body is the entry, unchanged. - **Native events.** Claude Code's own OpenTelemetry events, such as `claude_code.api_request`. They add a live view and the cost and latency of each request. Nothing depends on them. ## The shipper The shipper is a small program that reads a session's JSONL file and sends each entry that midden does not have yet. - A Stop hook runs `midden ship` after each turn, in every session on every machine. - Backfill runs the same program over every transcript that a machine still has, such as the retained transcripts on a laptop. - When midden cannot be reached, the shipper keeps its place, and the next run sends what is left. A machine that is offline loses nothing. The shipper reads its endpoint, user, and app password from the environment, or from `~/.config/midden/env`, a file of `NAME=value` lines. midden stores each entry of each transcript file once. A retry, a second backfill, or an overlap between runs stores nothing twice, so delivery is at least once, with no duplicates. ## Native events Claude Code exports its own events when these are set: ``` CLAUDE_CODE_ENABLE_TELEMETRY=1 OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://midden.example.com/v1/logs OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic%20 OTEL_LOG_USER_PROMPTS=1 OTEL_LOG_ASSISTANT_RESPONSES=1 OTEL_LOG_TOOL_DETAILS=1 OTEL_LOG_TOOL_CONTENT=1 ``` `OTEL_LOG_TOOL_CONTENT` needs tracing, and `OTEL_LOG_ASSISTANT_RESPONSES` needs Claude Code 2.1.193 or later. The OTel specification percent-encodes header values. It is not yet checked that Claude Code's exporter decodes `%20`. ## Hosting midden runs in a Kubernetes cluster, behind an ingress for each path (`midden.example.com` here): - `/v1/logs` is the capture path, behind Authentik. - Pods of the same cluster reach a second address for `/v1/logs` through the Service, with no ingress. See "Auth". - `/mcp` is the read path. Each of its two addresses has its own `mcp-sidecar` and its own OAuth. Nothing else on midden is routed from outside the cluster. The image is `atcr.io/guid.foo/midden`, built with ko. Its entrypoint is `/ko-app/midden` and it has no default arguments, so a container runs the server with `args: ["serve"]` and leaves `command` unset. ## Auth midden's capture path is behind Authentik's forward auth, as a proxy provider, so it is reachable from anywhere. When midden's host is outside the cookie domain of the Authentik that protects it, the proxy provider is `forward_single`. midden has no auth code of its own for that path. - A client sends an Authentik app password as HTTP Basic. Authentik answers a wrong one with a 302 to its login page, so the shipper follows no redirect, and it counts a request as sent only when midden's own OTLP response comes back. - Authentik passes the user to midden in `X-authentik-username`, and midden records it on each row. - Each machine has its own app password, so one machine can be revoked alone. The shipper and the native exporter use the same endpoint and the same app password. A pod of midden's own cluster needs no password. `MIDDEN_PODS_LISTEN` is a second address for `POST /v1/logs`, which only pods reach: - The pod sends its projected ServiceAccount token for the audience `midden` as a bearer token, and `midden ship` reads it from `MIDDEN_TOKEN_FILE`. - midden sends the token to the API server's TokenReview, so its own ServiceAccount is bound to `system:auth-delegator`. A token for another audience, or one that is bound to no pod, is refused. - `MIDDEN_POD_USERS` maps a namespace to the user that its pods' records are stored under, and a pod of any other namespace is refused. A pod holds a token for midden only when its spec mounts one, so whoever writes the pod specs of a listed namespace decides which pods ship. - This address never reads `X-authentik-username`, and the address behind Authentik never reads a token. A NetworkPolicy must keep pods from the address behind Authentik, where a pod could name any user. ## Storage midden appends to one table in its own Postgres. Each OTLP log record is one row: - columns for the fields that queries use: the kind of record, the session ID, the transcript file, the entry's key, the `prompt.id` of a native event, the event name, the timestamp, the Authentik user, and the harness and host from the resource attributes - the transcript entry, parsed, in a `jsonb` column - the full log record, as OTLP JSON, in another `jsonb` column An entry's key is its `uuid`, or its byte offset in the file when it has no `uuid`. A unique index on the session, the file, and the key gives each entry of each file one row. A resumed session's file repeats earlier entries with the same `uuid` and different metadata, such as the Claude Code version, so each file's copy is its own row. midden never updates or deletes a row. ## Other harnesses A harness joins midden with a reader for its transcript format in the shipper. Codex also writes its sessions as JSONL files. Its format is not checked yet. ## The read path `midden serve` serves three MCP tools at `/mcp`, over the streamable HTTP transport, with the official Go SDK. The tools only read, and each returns one page with a `Next` cursor. - **`list_sessions`** lists sessions, newest first by their last entry, filtered by time, host, user, and harness. Each has its first and last time, its user, host, and harness, its working directory and git branch, its first prompt, and its number of entries. - **`read_session`** returns one session's entries in order. Each entry has parts: the user's prompts, the assistant's text, each tool call with its input, and each tool result in a short form of at most 10 lines and 2000 bytes. Subagent entries are in the order too, marked as sidechains. - **`search`** finds entries by the text of their prompts, responses, tool calls, and tool results, with the filters of `list_sessions`. It returns each match with its session, time, and a snippet, and a `From` cursor that starts `read_session` at the match. A resumed session's files repeat its earlier entries. The read path shows each `uuid` once in a session, and each entry keyed by its offset once in each file, so the list's count and the read agree. A trigger keeps each entry's place in its session's order in `entry_places`, in the entry's own transaction, so a page of `read_session` starts at its cursor in an index and reads only its own entries. The sessions stored before the table are in `unplaced_sessions`: `midden serve` places them one at a time after it starts, and a read places its own session first when it is still there. Postgres ends any query of the read path that runs longer than a minute, because it does not see an MCP client that gives up. Search is Postgres full-text search, with the `english` configuration, over the same parts that `read_session` shows. A query takes words, "quoted phrases", `or`, and `-word`, and stemming finds "deploying" for "deploy". Paths and dotted names, such as `archive/search.go`, match only in full. The GIN index `records_search` is not in the schema: `midden serve` builds it with `CREATE INDEX CONCURRENTLY` after it starts, so the intake keeps writing. Search works before the index exists, but reads the whole table. The MCP addresses do no auth. The deployment binds each to `127.0.0.1` behind its own `mcp-sidecar`, and Authentik decides who reaches each sidecar. The intake's address answers 404 at `/mcp`. ## Privacy A session is private when any entry of any of its files works in a private repository or calls a private tool. The rule is on the whole session, so a session that calls Gmail an hour after its first prompt is private from its first entry. - `MIDDEN_PRIVATE_REPOSITORIES` holds one regular expression for each private repository, matched against each entry's `cwd`. The default is none: no repository is private until it is named here. - `MIDDEN_PRIVATE_TOOLS` holds prefixes of tool names. The default is Gmail, Google Calendar, and Google Drive, as claude.ai connectors, such as `mcp__claude_ai_Gmail__`, and by their local names, such as `mcp__gmail__`. Each list is split by spaces, and an empty one keeps its default. A trigger stores each session's working directories and tool names in `session_traits`, in the entry's own transaction. The reads apply the rule to those traits, so a change to the config applies at the next start with nothing to reclassify. The read path has two views, and the address a request reaches decides its view: - `MIDDEN_MCP_FULL_LISTEN` serves the full view, with every session, for the person's own machines. - `MIDDEN_MCP_SHARED_LISTEN` serves the shared view, for simmer's service accounts. Private sessions do not exist there: the list skips them, a read finds no entries, and search finds nothing in them. No private text reaches a Job's context. An unset address does not listen, because any default would serve the archive with no auth. ## Metrics `midden serve` serves Prometheus's `/metrics`, and a `/healthz` that answers while the process runs, on `MIDDEN_METRICS_LISTEN`. No Ingress routes to it. Each process has its own registry, and the series count nothing per session, user, or host: a Job's host is its pod's name, so the intake counts by `listener`, the address a request reached. `authentik` is `MIDDEN_LISTEN` and `pods` is `MIDDEN_PODS_LISTEN`. - `midden_build_info{version}` is always 1. The version is the image's tag, or `dev` for a build that set none. - `midden_intake_requests_total{listener, outcome}` counts each request to `POST /v1/logs`. The outcome is `stored`, `unauthenticated`, `forbidden` (a pod of a namespace with no user), `review_failed` (the TokenReview could not be asked), `undecodable`, or `store_failed`. - `midden_records_received_total{listener, kind}` counts the records of each request that decoded, and `midden_records_stored_total{listener, kind}` the ones the archive did not have. The kind is `transcript` or `event`. Received minus stored is the copies that a retry or a backfill sent again. - `midden_append_duration_seconds{outcome}` times each request's write to Postgres, and the outcome is `ok` or `error`. - `midden_record_lag_seconds{listener, kind}` observes, for each new record with a time, how long before midden stored it the harness wrote it. The shipper runs after each turn, so the lag holds the length of the turn, and a backfill's lag is the age of its transcripts. An entry that never ships has no lag, so a machine that stops shipping shows only as fewer records. - `midden_tool_calls_total{tool, view, outcome}` counts each MCP tool call. The tool is `list_sessions`, `read_session`, or `search`, the view is `full` or `shared`, and the outcome is `ok`, `refused` (input that the caller must fix), `timeout` (Postgres ended the read at its bound), `canceled` (the client went away), or `error`. - `midden_tool_call_duration_seconds{tool, view}` times each call. The tool series exist only in a process that serves a view. Go's and the process's own series come with every registry. ## Not designed yet - retention