Give Claude a clock — and a canary
Two small Claude Code tricks that took me one evening to set up, plus a refinement of Matthew’s canary idea that came out of it.
The problem
Claude has no clock. Mid-session it genuinely does not know if it’s been ten minutes or six hours, whether it’s afternoon or nearly midnight — and in long sessions it slowly gets sloppy about early instructions without anyone noticing. Two cheap fixes and one tripwire:
Trick 1 — inject the time (and turn count) every prompt
Claude Code has hooks — scripts that fire on events. A UserPromptSubmit hook runs every time you send a message, and whatever it prints gets injected into Claude’s context. So: a tiny script that prints the turn number and wall-clock time.
~/.claude/hooks/turn-time.sh:
#!/bin/bash
# Injects "[turn N · HH:MM TZ]" into Claude's context on every prompt.
STATE_DIR="${HOME}/.claude/state"; mkdir -p "$STATE_DIR"
SESSION_ID=$(python3 -c "import json,sys; print(json.load(sys.stdin).get('session_id',''))" 2>/dev/null)
[ -z "$SESSION_ID" ] && exit 0
F="$STATE_DIR/turns-$SESSION_ID"
COUNT=$(( $(cat "$F" 2>/dev/null || echo 0) + 1 )); echo "$COUNT" > "$F"
echo "[turn $COUNT · $(date '+%H:%M %Z')]"
Wire it up in ~/.claude/settings.json (and chmod +x the script):
{
"hooks": {
"UserPromptSubmit": [
{ "hooks": [ { "type": "command", "command": "~/.claude/hooks/turn-time.sh" } ] }
]
}
}
Cost: roughly 10 tokens per turn — noise. Benefit: Claude knows what time it is, how long the session has run, and can pace itself (“it’s 11pm and turn 80 — want to wrap?”). Session notes get real timestamps too.
Trick 2 — timestamps in the UI
One setting, no script:
{ "showMessageTimestamps": true }
Every Claude response gets stamped with its arrival time in the terminal — like a shell prompt for your conversation. (Display-only; it doesn’t enter the transcript content. That distinction matters for trick 3.)
Trick 3 — the canary, with an answer key
Matthew’s original idea: put an instruction early in your setup like “always begin every response with the word X.” When Claude stops doing it, your context is getting muddy — the canary died, get out of the mine.
The diagnosis is right, but a fixed magic word has a weakness: it’s the easiest instruction in the world to keep. Claude can emit the ritual token flawlessly while its actual judgment quietly degrades — a false green light. And there’s nothing to check the canary against.
The refinement: make the canary echo the hook injection. Instruction (in your CLAUDE.md or memory):
Open every response by echoing the latest [turn N · HH:MM] stamp injected into the conversation. If you notice you missed or mis-echoed one, say so — it’s a context-health signal, and we should consider wrapping the session.
Now the canary carries information with ground truth behind it: a wrong turn number, a stale time, or a missing echo is objectively checkable against what the hook injected — you’re not relying on remembering whether the magic word appeared. Bonus: the echo lives in the transcript itself, so your session logs get timestamps permanently, and if the echo ever disagrees with the UI stamp from trick 2, that divergence is itself a signal.
Honest fine print
The canary is a tripwire, not a gauge — it fires late. By the time even a rote echo fails, subtler degradation started earlier. The real defense is still session hygiene: scope sessions to one thread of work, reopen fresh at natural boundaries instead of running marathons, and treat the canary as the smoke alarm, not the sprinkler system.
Credit where due: the canary concept is Matthew’s; the answer-key twist and the hook plumbing are what fell out of trying it in practice.
2
3 comments
Collin Thomas
1
Give Claude a clock — and a canary
powered by
Claude Code Pirates
skool.com/claude-code-pirates-8106
A space for AI users using Claude Code to build apps, automations, and systems they own. No hype.
Build your own community
Bring people together around your passion and get paid.
Powered by