Skip to content

Commit 3d6c2ba

Browse files
authored
fix(integrations-claude-code): label 'Current time' as UTC in recall context (#1568)
The recall hook injects "Current time - <ts>" into <hindsight_memories> without a timezone label, while the value is computed in UTC. Client LLMs running in non-UTC timezones often misread this as local time — e.g. a 2026-05-10 23:55 UTC stamp prompts a Claude Code session in JST (local 2026-05-11 08:55) to remark "sounds like a good place to wrap up for the day." The opencode integration already labels its equivalent line with " UTC" (hindsight-integrations/opencode/src/hooks.ts:117). Aligning claude-code with that convention removes the foot-gun.
1 parent 8004679 commit 3d6c2ba

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

hindsight-integrations/claude-code/scripts/lib/content.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ def format_memories(results: list) -> str:
221221
def format_current_time() -> str:
222222
"""Format current UTC time for recall context.
223223
224+
The "UTC" suffix is explicit so client LLMs do not misread the
225+
value as local time when reasoning about wall-clock context.
226+
224227
Port of: formatCurrentTimeForRecall() in index.js
225228
"""
226229
now = datetime.now(timezone.utc)
227-
return now.strftime("%Y-%m-%d %H:%M")
230+
return now.strftime("%Y-%m-%d %H:%M UTC")
228231

229232

230233
# ---------------------------------------------------------------------------

hindsight-integrations/claude-code/tests/test_content.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Tests for lib/content.py — pure content-processing functions."""
22

3+
import re
4+
35
import pytest
46

57
from lib.content import (
68
_extract_text_content,
79
_is_channel_message_tool,
810
compose_recall_query,
11+
format_current_time,
912
format_memories,
1013
prepare_retention_transcript,
1114
slice_last_turns_by_user_boundary,
@@ -469,3 +472,18 @@ def test_without_tool_calls_uses_text_format(self):
469472
transcript, _ = prepare_retention_transcript(msgs, retain_full_window=True, include_tool_calls=False)
470473
assert "[role: user]" in transcript
471474
assert "[user:end]" in transcript
475+
476+
477+
# ---------------------------------------------------------------------------
478+
# format_current_time
479+
# ---------------------------------------------------------------------------
480+
481+
482+
class TestFormatCurrentTime:
483+
def test_includes_utc_suffix(self):
484+
# The "UTC" suffix prevents client LLMs from misreading the
485+
# timestamp as local time.
486+
assert format_current_time().endswith(" UTC")
487+
488+
def test_format_shape(self):
489+
assert re.fullmatch(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2} UTC", format_current_time())

0 commit comments

Comments
 (0)