Back to catalogue
ContextUserPromptSubmitUserPromptSubmitOn prompt submit · can enrich input⚡ blocking
Current date and time injection
Adds the current date and time to the context of every prompt, preventing the agent from reasoning with an incorrect cutoff date.
Use cases
- Correct temporal reasoning
- Timestamped logs
- Changelogs
Providers & tags
Claude Code
#context#datetime#prompt
settings.json fragment
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"command": "echo \"Date/heure actuelle: $(date '+%Y-%m-%d %H:%M:%S %Z')\"",
"type": "command"
}
]
}
]
}
}Script · .claude/hooks/inject-datetime.mjs
#!/usr/bin/env node
// Injecte la date et l'heure courantes dans chaque prompt (UserPromptSubmit)
import { fileURLToPath } from 'url';
export function run({ now = new Date() } = {}) {
const formatted = now.toLocaleString('fr-FR', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
});
return `Date et heure courantes : ${formatted}\n`;
}
/* v8 ignore next 3 */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
process.stdout.write(run());
}