Skip to content

hookWorkflow

Inject Current Date

A Claude Code hook that tells the agent today's date, weekday and time zone on each prompt, so date math and changelog entries come out right.

npx workspacetemplates add inject-current-date --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file15 lines · 650 BFile
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{let j={};try{j=JSON.parse(d)}catch(e){}const n=new Date();const z=x=>String(x).padStart(2,'0');const day=n.toLocaleDateString('en-US',{weekday:'long'});console.log('Current date: '+day+', '+n.getFullYear()+'-'+z(n.getMonth()+1)+'-'+z(n.getDate())+' (time zone '+Intl.DateTimeFormat().resolvedOptions().timeZone+'). Use it for anything that depends on today.');process.exit(0)})\"",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

What it does

Models often guess the date from their training data. This UserPromptSubmit hook reads the system clock and adds one line to every prompt: the weekday, the date in year-month-day form and your time zone.

That is enough for correct release notes, migration file names, license years and phrases like 'last Friday'. The hook never reads your prompt text and sends nothing anywhere.

Example

you › Add a changelog entry for this release.

agent › Claude receives 'Current date: Sunday, 2026-11-15 (time zone Europe/Berlin)' and writes the heading with that date.

Questions

Which clock does it use?
The local clock of the machine running Claude Code, in that machine's time zone.
Can I add the time of day?
Yes. Append n.toLocaleTimeString() to the printed text inside the command.
  • Log Bash Commands

    HookWorkflow

    Free
  • Log Session End

    HookWorkflow

    Free
  • Notification Bell

    HookWorkflow

    Free