Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created June 26, 2026 13:20
Show Gist options
  • Select an option

  • Save tommcfarlin/52fcd558e4121e04e394942019f96179 to your computer and use it in GitHub Desktop.

Select an option

Save tommcfarlin/52fcd558e4121e04e394942019f96179 to your computer and use it in GitHub Desktop.
Claude Code UserPromptSubmit hook: inject current date/time into context on every message

Claude Code: Always-Current Date & Time Hook

A UserPromptSubmit hook for Claude Code that injects the current local date, time, and timezone into context on every message you send.

Why

Claude Code doesn't track the passage of time within a session. Leave a session open overnight, type a message the next morning, and it has no idea hours have passed — to it, idle-for-a-minute and idle-for-twelve-hours look identical.

A SessionStart hook doesn't fix this: it only fires on launch/resume/clear/ compact, so its timestamp freezes at session start. UserPromptSubmit fires on every prompt, so the clock refreshes each turn no matter how long the session sat idle.

Install

Merge the block below into ~/.claude/settings.json (global, all projects). If you already have a hooks key, add UserPromptSubmit alongside the existing entries rather than replacing them.

Takes effect on your next prompt — no restart needed. If it doesn't kick in, open /hooks once to force a settings reload.

Requires date and jq (both standard on macOS/Linux).

Verify

jq '.hooks.UserPromptSubmit' ~/.claude/settings.json
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "jq -n --arg ctx \"$(date '+%A, %B %-d, %Y at %-I:%M %p %Z (UTC%z)')\" '{hookSpecificOutput:{hookEventName:\"UserPromptSubmit\",additionalContext:(\"Current local date and time: \" + $ctx + \". This is refreshed on every message; use it as your reference for \\\"now\\\" and \\\"today\\\".\")}}'"
}
]
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment