Skip to main content

File Read Gate

What It Is

The File Read Gate is a PreToolUse hook that intercepts Claude’s Read tool calls. When Claude tries to read a file that has prior observations in the database, the gate blocks the read and instead shows a compact timeline of past work on that file. Claude then decides the cheapest path to get the context it needs. This is a concrete implementation of progressive disclosure — show what exists first, let the agent decide what to fetch.

How It Works

When the gate fires, Claude sees a message like this:

The Decision Tree

Claude has four options after seeing the timeline, ordered from cheapest to most expensive: In practice, most file reads resolve at the semantic priming or get_observations level, saving thousands of tokens per interaction.

Current Date/Time for Temporal Reasoning

The timeline includes the current date and time as its first line:
This lets Claude reason about how recent the observations are relative to now. For example:
  • Observations from today — likely still accurate, semantic priming is safe
  • Observations from last week — probably accurate, get_observations for details
  • Observations from months ago — file may have changed, consider smart_outline or full read
The timestamp format matches the session start context header (YYYY-MM-DD time timezone), so Claude sees consistent temporal markers throughout its session.

Token Economics

A typical source file costs 5,000-50,000 tokens to read in full. The File Read Gate replaces that with: If Claude needs more detail, it fetches individual observations at ~300 tokens each. Even fetching 3 observations totals ~1,270 tokens — still a 75-97% savings over reading the full file.

Real-World Example

Without the gate (reading worker-service.ts):
With the gate:

Specificity Ranking

Not all observations about a file are equally relevant. The gate scores each observation by how specifically it relates to the target file: Higher-scoring observations appear first in the timeline. An observation where the file was the primary modification target ranks above one where the file was incidentally read alongside 20 others.

Configuration

Small File Bypass

Files smaller than 1,500 bytes always pass through the gate without interception. At that size, the timeline (~370 tokens) would cost more than reading the file directly. This threshold is hardcoded in src/cli/handlers/file-context.ts.

Project Exclusions

Projects matching patterns in CLAUDE_MEM_EXCLUDED_PROJECTS skip the gate entirely. Configure this in ~/.claude-mem/settings.json:

How to Disable the Gate

The File Read Gate is implemented as a PreToolUse hook on the Read tool matcher. To disable it, remove the Read matcher entry from the hooks configuration:
  1. Open your Claude Code settings:
  2. Find the claude-mem hooks section under hooks.PreToolUse and remove the entry with the Read matcher.
Alternatively, if you want to keep the gate installed but bypass it for a specific read, Claude can ask you to allow the read — the gate’s deny decision is presented to the user, who can override it.
Disabling the gate means Claude will read full files every time, which increases token usage but ensures it always sees the latest code. This is a reasonable choice for small projects or when observations are sparse.

How It Fits Together

The File Read Gate is one piece of claude-mem’s layered context strategy:
  1. Session Start: Inject timeline of recent observations (layer 1 — metadata)
  2. File Read Gate: Intercept reads with observation history (layer 1 — metadata)
  3. get_observations: Fetch specific observation details on demand (layer 2 — details)
  4. smart_outline / smart_unfold: Read current code structure efficiently (layer 3 — source)
  5. Full file read: Last resort when everything else is insufficient
Each layer is progressively more expensive. The gate ensures Claude starts at the cheapest layer and escalates only when needed.