Cool little hack using Claude Code watching files with tail -f
Claude Code will watch a file using tail -f and notice any change to the file waking up. Cool little hack using Claude Code watching files with tail -f
By Dillip Chowdary • Aug 31, 2026 • Source: HN Claude/Codex/Fable
What happened
The article is saved at [claude-code-tail-hack.md](file:///home/ubuntu/.gemini/antigravity-cli/brain/db25bfc6-4342-47b9-8a85-d59c4afa47df/claude-code-tail-hack.md).
A technique shared on Hacker News shows that Claude Code can be kept persistently awake and cache-warm by pointing it at a markdown file and having it watch that file using the Unix tail -f command. The trick surfaces a real cost asymmetry in Anthropic's pricing model: cached tokens are billed at one-tenth the rate of normal tokens, meaning sessions that stay alive and reuse their context are dramatically cheaper than sessions that restart and rebuild from scratch.
This piece explains exactly how the hack works, who should care about it, and what engineers running multi-agent Claude Code workflows should verify before adopting the pattern. It is aimed at developers already using Claude Code or Codex CLI who want to reduce inference costs without sacrificing orchestration capability.
How it works
A Hacker News thread surfaced a lightweight orchestration pattern for Claude Code that exploits the tail -f command to hold agent sessions open indefinitely. The author observed that read-cache tokens cost 10 percent of what normal tokens cost, but that every time a sub-agent is launched in a fresh chat it loses the accumulated cache, resetting to full-price token consumption. The proposed fix is to start a small number of long-lived chat sessions upfront, each assigned a level of model and effort, and keep them running rather than spinning new ones up per task.
The mechanic is simple: each persistent chat session is told to watch its own dedicated markdown file using tail -f, and it sits idle until that file changes. When the orchestrator needs to delegate work, it writes instructions into the appropriate file. The watching agent notices the change, reads the new content, and begins working. The cache built up over the session lifetime is preserved because the process never exited.

The primary audience affected is anyone running Claude Code in a multi-agent or orchestrated configuration where sub-agents are spawned repeatedly for discrete tasks. Each fresh sub-agent launch pays full token rates for its initial context because there is no warm cache to inherit. At scale, this compounds quickly: a workflow that creates dozens of sub-agents per hour is paying full price for context that is largely identical across those agents.
Advertisement
Tech Pulse Daily
Get tomorrow's pulse first
Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.
Why it matters
Builders using Codex CLI or similar Anthropic-backed tooling with session-level caching face the same tradeoff. Single-session or interactive users who never restart their chat are already naturally retaining cache and may be getting this benefit without realizing it. The cost gap between a session-restart-heavy pattern and a persistent-session pattern is the gap between full token price and 10 percent of that price.
The minimum change a builder should make is to stop treating sub-agents as disposable. Instead of spawning a new agent per task, create a small pool of persistent agents at session start, each with a designated markdown file in a folder that is explicitly excluded from git tracking. Git-tracked files risk polluting version history with every instruction message the orchestrator writes, and the whole mechanism depends on low-friction writes to those files.
Who is affected
Once the folder and per-agent files are in place, each agent should be initialized with an explicit instruction to watch its own file using tail -f and to treat any new content appended to that file as its next task. The orchestrator then writes to the correct file when it wants to route work. Verify that your orchestrator knows which agent file maps to which capability or effort tier so it dispatches to the right session.
The underlying mechanism depends on two behaviors. First, tail -f in Unix keeps a file descriptor open and emits new bytes as they are appended, which means a process blocked on that output stays alive without polling or sleeping in a loop. Claude Code, observing that output stream, can treat a file change as an external wake signal. Second, Anthropic's caching layer prices previously seen tokens at 10 percent of the standard input token rate. A session that has processed a large system prompt, a codebase snapshot, or extended prior conversation history has already paid for those tokens once; subsequent turns reuse the cached representation at the reduced rate.
When you kill that session and open a new one, the cache is cold. The new session pays full price to re-encode the same context. For agents given a large shared context, such as a full repository index or a long tool manifest, the cost difference between one long session and ten short ones that each reprocess that context is close to a 9x penalty on every restart.
What to watch next
The thread does not specify what happens when a watched file receives multiple rapid writes before the agent finishes processing the first one. It is unclear whether the tail -f approach causes the agent to queue instructions, process only the latest append, or behave inconsistently depending on timing. That ambiguity matters for orchestrators that could write to a file while the watching agent is still mid-task.
It is also not documented how Anthropic's cache interacts with effort or model tier settings. The hack assumes that cache tokens are preserved across turns within a session regardless of the model or effort level assigned at session start, but this has not been confirmed for every configuration. Builders should run cost comparisons against their own workloads before treating the 10 percent figure as a guaranteed saving across all session types.
Developer Action Items
- ☐ Inventory whether Anthropic / Claude / Gemini runs in prod, CI, staging, or on laptops before you debate severity.
- ☐ Confirm the vendor's fixed build for Anthropic / Claude / Gemini from HN Claude/Codex/Fable, then schedule the patch window.
- ☐ If you cannot patch today, isolate the service, rotate tokens that sat on the affected surface, and raise the logging floor.
- ☐ Record the decision and residual risk so the next on-call does not re-litigate whether you are exposed.
Advertisement