Claude Code · PreToolUse hook

The Read Gate

A hook stands in front of Claude's Read tool. Small files pass straight through. Big files get diverted to a cheaper model that answers the question, so your context window never swallows a 2,000-line file.

Read() path, limit? > 200 lines? Context Claude window Composer grok · CLIProxy DeepSeek fallback
Try a file size
Gate decision
Diverted
Read is blocked; Claude is told to ask Composer instead.
Added to context~0.8k tokens
Saved vs reading inline~1.6k tokens
pass through divert to Composer wiring
How it works · the gate

Every Read hits five quick checks

The hook runs before the tool. It reads the call's JSON, applies these checks in order, and either steps aside or denies with a message pointing Claude at ask-deepseek. The order is the logic, so the cheap exits come first.

01

Missing or gone

No path, or the file does not exist. Nothing to gate.

allow
02

Explicit slice

An offset, pages, or limit ≤ 200 means Claude already asked for a portion.

allow
03

Binary type

Images, archives, media, databases. Let the real tool handle them.

allow
04

Line count

head -n 201 checks the size without slurping the whole file.

≤200 allow
05

Over the line

More than 200 lines and no slice. Deny, and hand Claude the ask-deepseek command.

divert
How it works · what Claude sees

A denied read is a redirection, not a dead end

When a file is over the line, the hook answers the tool call with a deny and a reason. Claude reads the reason, runs the suggested ask-deepseek command itself, and keeps going with a short answer instead of the whole file.

How it works · the backend

One command, two backends, automatic fallback

ask-deepseek is a symlink to a composer script. It bundles the file contents with your question, sends them to a fast Composer model through a local gateway, and falls back to DeepSeek's API if that call fails.

Input Question + files The denied path plus whatever you ask, concatenated for analysis.
Primary Composer grok-composer-2.5-fast via CLIProxy on :8317.
If it fails DeepSeek Direct API with reasoning effort turned up. Same answer shape.
Why it pays off

The point is the context window

A long file read inline is pure ballast: it fills the window, pushes earlier work out, and costs premium tokens on every following turn. A focused answer is a few hundred tokens that actually move the task forward.

context limit read 1 reads over one session → read 8
reading inline — window fills, early work gets evicted through the gate — stays open all session
~96%
fewer tokens added for a large-file lookup, on a rough 22k vs 0.8k comparison.
$0
premium model spend on the bulk read; the heavy lifting runs on a cheaper backend.
200
line threshold. Tune it in one place if your codebase wants a different cutoff.
The wiring

Three small files do all of it

ask-deepseek

Shell command (symlinked to composer) that answers questions about one or more files and prints the result to stdout.

deepseek-read-hook.sh

The PreToolUse hook. Parses the Read call with jq, runs the five checks, and returns allow or deny.

~/.claude/settings.json

Registers the hook against the Read matcher. One block connects the gate to every read Claude makes.

Copy the setup in a few minutes

curl -s https://claude-code-composer-guide.pages.dev/claude-code-composer-deepseek-setup.md
Read the full setup guide →