claude-code - ✅(Solved) Fix [Bug] Agent invents timestamp when writing to files — currentDate injected but no currentTime [2 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#60492Fetched 2026-05-20 03:57:07
View on GitHub
Comments
3
Participants
2
Timeline
10
Reactions
0
Timeline (top)
commented ×3labeled ×2mentioned ×2subscribed ×2

When Claude Code writes a timestamp into a filename, document header, version history row, or journal entry, it silently fabricates the time component. The system prompt injects currentDate (e.g. Today's date is 2026-05-19) but no currentTime. The agent has the date but no authoritative time source, so it guesses.

Error Message

The agent fabricates a plausible-looking but incorrect time (e.g. writes 202605191456 when the real time was 202605191200). The failure is silent — the agent does not warn that it is guessing.

Root Cause

currentDate is injected into the system prompt at session start. currentTime is not. Node.js has new Date() which gives the full current date and time — this is already available in the Claude Code runtime.

Fix Action

Workaround

Add to CLAUDE.md: instruct the agent to always run date via Bash before writing any timestamp and use the returned value.

PR fix notes

PR #257: examples: timestamp-fresh-rewrite.sh — PreToolUse hook for #60492

Description (problem / solution / changelog)

Adds a new PreToolUse hook (examples/timestamp-fresh-rewrite.sh) implementing the operator-side defense for anthropics/claude-code#60492 — Agent invents timestamp when writing to files. The reporter @satel-kalletuulos documented the YYYYMMDDHHMM fabrication pattern: the system prompt provides currentDate but not currentTime, and the model invents the time component when writing timestamped filenames, document headers, version history rows, or journal entries. In comment 1 the reporter refined the design ask: "The timestamp should be freshly retrieved always when timestamp is needed and inserted." This hook is the harness-level form of that requirement, shipped as an operator-side reference implementation. PreToolUse on Write/Edit/MultiEdit:

  1. Scans tool_input.file_path and tool_input.content (or new_string) for YYYYMMDDHHMM-shaped substrings.
  2. Computes drift between the substring's encoded time and the actual system clock (date +%s).
  3. If drift > CC_TIMESTAMP_REWRITE_DRIFT minutes (default 10):
    • Substitute mode (default): rewrites the drifted value to the fresh clock value via a decision: "modify" JSON response, then emits a stderr note documenting the substitution.
    • Advisory mode (CC_TIMESTAMP_REWRITE_ADVISORY=1): emits a <system-reminder> on stderr without modifying the tool input, for older harness versions that do not honor the substitution path.
  4. If drift is within tolerance: silent exit (no false positive on legitimate past/future timestamps). Substitute, do not block. The fabrication is silent on the read side. Blocking and asking the model to re-issue doubles the turn cost without addressing the underlying gap (system prompt injection covers date but not time). Substitution is deterministic, runs outside the model's metacognition, and produces the correct value the first time.
  • ✅ Drifted timestamp in file_path → substituted
  • ✅ Drifted timestamp in content → substituted
  • ✅ In-band timestamp → silent (no false positive)
  • ✅ No timestamp → silent
  • ✅ Advisory mode → stderr only, no decision: "modify"
  • ✅ Disable flag → fully silenced
  • ✅ Empty stdin → silent (no crash)
  • ✅ Malformed JSON input → silent (no crash)
  • Edit tool → handles new_string
  • ✅ Custom CC_TIMESTAMP_REWRITE_DRIFT → respected
  • ✅ Missing tool_name → still processes
  • file_path-only input → substitutes path only
  • ✅ Substitution reason JSON field cites #60492
  • ✅ Empty path with clean content → silent
  • ✅ Stderr note accompanies substitution This is the third operator-side defense hook shipped this week against the recognition-without-arrest cluster (#60226):
  1. same-correction-arrest.sh (PR #250) — same-correction repetition detector for #60506
  2. closure-word-verify-gate.sh (PR #250) — completion claim gate for #60506 recommendation 4
  3. evidence-claim-gate.sh (PR pending) — epistemic claim gate for #60506 recommendation 5
  4. This PR — value-substitution PreToolUse hook for #60492 The four hooks operate at four different boundaries (Stop, Stop, Stop, PreToolUse) and target four different claim shapes (same-correction repetition, completion language, epistemic language, fabricated value substitution). Together they cover four of the seven supplier-side recommendations from #60506 with deterministic verdict paths that run outside the model. The hook count in examples/ advances by one (739 → 740 if PR #256 merges first; 738 → 739 if this lands first). The 30,000-install cc-safe-setup audience gains a new install option for the YYYYMMDDHHMM fabrication pattern that affects journals, changelogs, archives, and any timestamp-bearing file written by Claude Code agents. 🤖 Generated with Claude Code

Changed files

  • examples/timestamp-fresh-rewrite.sh (added, +203/-0)
  • tests/test-timestamp-fresh-rewrite.sh (added, +254/-0)

Code Example

const now = new Date();
// e.g. "Current time is 2026-05-19T12:08:00+03:00"
RAW_BUFFERClick to expand / collapse

Description

When Claude Code writes a timestamp into a filename, document header, version history row, or journal entry, it silently fabricates the time component. The system prompt injects currentDate (e.g. Today's date is 2026-05-19) but no currentTime. The agent has the date but no authoritative time source, so it guesses.

Steps to reproduce

  1. Instruct Claude Code to create a timestamped archive file (e.g. archive-YYYYMMDDHHMM.md)
  2. Observe the filename — the time component (HHMM) is invented, not the actual current time

Expected behavior

The timestamp matches the actual wall-clock time at the moment of writing.

Actual behavior

The agent fabricates a plausible-looking but incorrect time (e.g. writes 202605191456 when the real time was 202605191200). The failure is silent — the agent does not warn that it is guessing.

Root cause

currentDate is injected into the system prompt at session start. currentTime is not. Node.js has new Date() which gives the full current date and time — this is already available in the Claude Code runtime.

Suggested fix

Inject currentTime into the system prompt alongside currentDate:

const now = new Date();
// e.g. "Current time is 2026-05-19T12:08:00+03:00"

Workaround

Add to CLAUDE.md: instruct the agent to always run date via Bash before writing any timestamp and use the returned value.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The timestamp matches the actual wall-clock time at the moment of writing.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - ✅(Solved) Fix [Bug] Agent invents timestamp when writing to files — currentDate injected but no currentTime [2 pull requests, 3 comments, 2 participants]