He Stopped Telling Claude Code to Stop Making Up Timestamps—and Made It Impossible with a PreToolUse Hook
Grimmoner · reddit · 2026-10-18
A Claude Code user found the model kept writing fabricated timestamps in logs—rounded guesses, placeholders like 16:4x, even a time 16 minutes in the future—despite being told not to.
His fix: stop telling, start enforcing. A PreToolUse hook runs a small Python script before every Bash command, file write, edit, or message, blocking calls that would introduce a guessed time pattern and instructing the model to read the clock inline with T=$(date '+%H:%M') instead.
Key engineering details:
- Exit-code trap: Python exits 2 when it can't open the script, but 2 is hook-speak for "block"—a missing hook file would block every tool call. He uses custom exit code 3 with a one-line sh wrapper that maps only 3 to 2; anything else is just a warning.
- Safe config edits: since settings.json also holds permissions, he uses a script to add the key with backup and read-back verification.
The hook caught Claude within two hours of deployment. Known limits: round guesses like 06:00 slip through, and plain chat replies aren't visible. His lesson: if you've told an agent the same thing three times, make the wrong thing impossible.
More from coding & agent
- Claude-written test harness let 31KB fake archives land on a real backup server — Grimmoner · 2026-10-18
- Matt Pocock's pre-commit hook caps agent-written files at 5,000 tokens — mattpocockuk · 2026-10-18
- Backups silently failed for 10 days: three monitoring blind spots lined up — Grimmoner · 2026-10-18
- Author Laurence Moroney: write your ugly first draft yourself, then let an LLM edit it — lmoroney · 2026-10-18
- Open-weight TYGER speech decision model makes 80ms turn-taking calls for full-duplex voice agents — solyarisoftware · 2026-10-18
- Devs: Opus 5.5 on medium beats Opus on max — eyishazyer · 2026-10-18