Optional timestamps after user prompts and tool batches, switched by the model or the person.

Claude Code gets a date, but not a time. This mod fixes that, a little cheekily.
When timestamps are on:
<system-reminder> saying The time is HH:MM:SS.So the model has the time whenever it is about to answer or call a tool. The first stamp after switching on, or after a compaction, is full, 2026-10-19 14:05:09 -05:00; after that the date appears only when the local date changes (past midnight) and the offset only when it changes (DST, or a new system time zone). They are off by default, so a session that doesn't need the time pays nothing for it.
timestamps tool with enabled: true or false. A static section added to the system prompt tells it the tool exists and what the stamps mean./timestamps flips it, /timestamps on and /timestamps off set it.Turning timestamps off leaves a one-time note saying the earlier times are stale, so the model does not keep treating the last one as the current time.
$.session.append), so the TUI doesn't show it as something you typed, and tool results are never modified.session.append on the prompt door appends the row once the prompt is stored.turn.step hook collects the tool call ids of each model response as it streams, and session.append on the tool-result door appends the row once the last of them has its result. Only after the last: a request's tool_result blocks must come before any text, and consecutive user rows are merged, so a reminder between two results would be refused.prompt.compose adds one static, session-scoped section, so the prompt cache is unaffected.The engine's own Today's date is … reminder is left alone: engine rows can't be refused.
At the prompt of a terminal session:
/plugin install date-time --marketplace ioctlLR/claude-needs-times-too
From a shell:
claude plugin install date-time --marketplace ioctlLR/claude-needs-times-too
In the desktop app, where /plugin does not run: click + next to the prompt box, then Plugins, Add marketplace with ioctlLR/claude-needs-times-too, then Add plugin.
session.append, turn.step and prompt.compose do not run in an installed plugin where an organization manages Claude Code; only a plugin the organization lists runs them.claude plugin test .hooks/register.ts 129 lines1import type { EngineInterface, Register } from 'claude-code'
2import { NOTE, OFF_TEXT, TOOL, formatStamp, hasText, parseSwitch, reminder, timeReminder } from './stamp'
3
4const REF = { plugin: 'date-time', key: 'timestamps' } as const
5
6async function read($: EngineInterface) {
7 return (await $.state.get(REF)).value ?? { isOn: false, isOffPending: false }
8}
9
10/** The current time for a stamp in one conversation, recording the date and offset it shows. */
11async function stamp($: EngineInterface, agentId: string | undefined) {
12 const s = await read($)
13 const key = agentId ?? ''
14 const { text, shown } = formatStamp(await $.clock.now(), s.shown?.[key])
15 await $.state.set(REF, { ...s, shown: { ...s.shown, [key]: shown } })
16 return text
17}
18
19/** Appends the time, or the one-time off notice, as a hidden row the model reads. */
20async function remind($: EngineInterface, agentId: string | undefined) {
21 const s = await read($)
22 let text: string | null = null
23 if (s.isOn) text = timeReminder(await stamp($, agentId))
24 else if (s.isOffPending) {
25 text = reminder(OFF_TEXT)
26 await $.state.set(REF, { isOn: false, isOffPending: false })
27 }
28 if (text !== null) await $.session.append({ message: { type: 'user', content: [{ type: 'text', text }] }, agentId })
29}
30
31// The tool calls of each conversation's latest model response, by agentId ('' for main).
32// The reminder goes after the batch's last result, never between two: the API wants a
33// request's tool_result blocks before any text, and consecutive user rows are merged.
34type Batch = { ids: Set<string>; done: Set<string>; isStreamed: boolean; isReminded: boolean }
35const batches = new Map<string, Batch>()
36
37async function settle($: EngineInterface, agentId: string | undefined, b: Batch) {
38 if (!b.isStreamed || b.isReminded || b.ids.size === 0) return
39 for (const id of b.ids) if (!b.done.has(id)) return
40 b.isReminded = true
41 await remind($, agentId)
42}
43
44export const register: Register = on => {
45 on('session.start', async ($, e, next) => {
46 await $.tool.register({
47 name: TOOL,
48 description:
49 'Turn harness timestamps on or off. When on, the current local time follows each user prompt and each batch of tool results. Off by default; turn on when the time matters, off when it does not.',
50 inputSchema: {
51 type: 'object',
52 properties: { enabled: { type: 'boolean', description: 'true to add timestamps, false to stop' } },
53 required: ['enabled'],
54 },
55 isDeferred: false,
56 })
57 await $.command.register({ name: TOOL, description: 'Turn timestamps on or off (on, off, or no argument to flip)' })
58 return next(e)
59 })
60
61 on('tool.call', { tool: 'mcp__date-time__timestamps' }, async ($, e) => {
62 const isOn = (e as unknown as { enabled?: unknown }).enabled === true
63 await $.state.set(REF, { isOn, isOffPending: false })
64 return { result: isOn ? 'Timestamps are on.' : OFF_TEXT }
65 })
66
67 on('command.run', { command: 'timestamps' }, async ($, e) => {
68 const cur = await read($)
69 const isOn = parseSwitch(e.args, cur.isOn)
70 if (isOn === null) return { text: 'Usage: /timestamps [on|off]' }
71 await $.state.set(REF, { isOn, isOffPending: !isOn && cur.isOn })
72 return { text: `Timestamps ${isOn ? 'on' : 'off'}.` }
73 })
74
75 // Collects the response's tool call ids as they stream. Results can be stored before
76 // the stream ends, so whichever of the two comes last appends the reminder.
77 on('turn.step', async function* ($, e, next) {
78 const b: Batch = { ids: new Set(), done: new Set(), isStreamed: false, isReminded: false }
79 batches.set(e.agentId ?? '', b)
80 for await (const c of next(e)) {
81 if (c.kind === 'tool') b.ids.add(c.id)
82 yield c
83 }
84 b.isStreamed = true
85 try {
86 await settle($, e.agentId, b)
87 } catch {}
88 })
89
90 // No .catch here or on the prompt door: retrying next(e) would store the row twice.
91 on('session.append', { door: 'tool-result' }, async ($, e, next) => {
92 const stored = await next(e)
93 try {
94 const b = batches.get(e.agentId ?? '')
95 if (b) {
96 for (const c of e.message.content) if (c.type === 'tool_result' && typeof c.tool_use_id === 'string') b.done.add(c.tool_use_id)
97 await settle($, e.agentId, b)
98 }
99 } catch {}
100 return stored
101 })
102
103 on('session.append', { door: 'prompt' }, async ($, e, next) => {
104 const stored = await next(e)
105 try {
106 if (hasText(e.message.content)) await remind($, e.agentId)
107 } catch {}
108 return stored
109 })
110
111 // A summary may drop the last full stamp, so the next stamp after a compaction is full.
112 // No .catch: retrying next(e) would compact twice.
113 on('session.compact', async ($, e, next) => {
114 const r = await next(e)
115 if (r.skip !== undefined || e.trigger === 'precompute') return r
116 try {
117 const s = await read($)
118 const { [e.agentId ?? '']: _, ...shown } = s.shown ?? {}
119 await $.state.set(REF, { ...s, shown })
120 } catch {}
121 return r
122 })
123
124 on('prompt.compose', async ($, e, next) => {
125 const r = await next(e)
126 return { sections: [...r.sections, { id: `${$.plugin.name}:time`, text: NOTE, scope: 'session' }] }
127 }).catch(($, e, next) => next(e))
128}
129hooks/stamp.ts 45 lines1import type { Shown } from '../types'
2
3/** Formats a local time, with the date and UTC offset only where they differ from `last`. */
4export function formatStamp(ms: number, last?: Shown): { text: string; shown: Shown } {
5 const d = new Date(ms)
6 const p = (n: number) => String(n).padStart(2, '0')
7 const off = -d.getTimezoneOffset()
8 const sign = off < 0 ? '-' : '+'
9 const abs = Math.abs(off)
10 const date = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
11 const offset = `${sign}${p(Math.floor(abs / 60))}:${p(abs % 60)}`
12 const time = `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
13 const parts = [date !== last?.date ? date : null, time, offset !== last?.offset ? offset : null]
14 return { text: parts.filter(x => x !== null).join(' '), shown: { date, offset } }
15}
16
17export const TOOL = 'timestamps'
18
19export const OFF_TEXT = 'Timestamps are now disabled. Times shown earlier in this conversation are stale; do not treat them as the current time.'
20
21export const NOTE =
22 'The harness can add timestamps to the conversation. They are OFF by default. ' +
23 `Call the ${TOOL} tool with enabled=true when the current time matters (logs, deadlines, durations) and enabled=false when it no longer does; the person can switch them too. ` +
24 'While on, each user prompt and each batch of tool results is followed by a <system-reminder> saying "The time is HH:MM:SS.", from the local clock. ' +
25 'The first stamp after timestamps are switched on or the conversation is compacted, and any stamp where the local date changes, puts the date (YYYY-MM-DD) before the time; the first stamp, and any stamp where the UTC offset changes, puts the offset (±HH:MM) after it. Otherwise the last date and offset shown still hold, and the stamp date overrides any earlier "Today\'s date" line. ' +
26 'They are added by the harness, not by tools or the user; use them as the current time and do not repeat them back unless asked. ' +
27 'When timestamps are switched off a notice says so, and the times shown before it are stale.'
28
29type Block = { type: string; [field: string]: unknown }
30
31export const reminder = (text: string) => `<system-reminder>\n${text}\n</system-reminder>`
32export const timeReminder = (time: string) => reminder(`The time is ${time}.`)
33
34/** True when a user row holds typed text, so it earns a reminder. */
35export const hasText = (content: readonly Block[]): boolean => content.some(b => b.type === 'text')
36
37/** Parses `/timestamps` arguments: on, off, or empty to flip. */
38export function parseSwitch(args: string, current: boolean): boolean | null {
39 const a = args.trim().toLowerCase()
40 if (a === '') return !current
41 if (['on', 'true', 'enable', 'enabled', '1'].includes(a)) return true
42 if (['off', 'false', 'disable', 'disabled', '0'].includes(a)) return false
43 return null
44}
45types/index.d.ts 15 lines1/** The date and UTC offset a stamp showed, as `formatStamp` in hooks/stamp.ts makes them. */
2export type Shown = { date: string; offset: string }
3
4/**
5 * `shown` is the date and offset last stamped in each conversation, by agentId ('' for main).
6 * Switching clears all of it and compacting clears that conversation's, so the next stamp is full.
7 */
8export type Timestamps = { isOn: boolean; isOffPending: boolean; shown?: Record<string, Shown> }
9
10declare module 'claude-code' {
11 interface PluginState {
12 'date-time': { timestamps: Timestamps }
13 }
14}
15