From 22527e96d01ce87aecaeeb75beab55b89ec965d6 Mon Sep 17 00:00:00 2001 From: YAMAGUCHI Seiji Date: Mon, 11 May 2026 09:15:36 +0900 Subject: [PATCH] fix(integrations-claude-code): label 'Current time' as UTC in recall context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recall hook injects "Current time - " into 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. --- .../claude-code/scripts/lib/content.py | 5 ++++- .../claude-code/tests/test_content.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hindsight-integrations/claude-code/scripts/lib/content.py b/hindsight-integrations/claude-code/scripts/lib/content.py index 008c1e7020..435bdcea9b 100644 --- a/hindsight-integrations/claude-code/scripts/lib/content.py +++ b/hindsight-integrations/claude-code/scripts/lib/content.py @@ -221,10 +221,13 @@ def format_memories(results: list) -> str: def format_current_time() -> str: """Format current UTC time for recall context. + The "UTC" suffix is explicit so client LLMs do not misread the + value as local time when reasoning about wall-clock context. + Port of: formatCurrentTimeForRecall() in index.js """ now = datetime.now(timezone.utc) - return now.strftime("%Y-%m-%d %H:%M") + return now.strftime("%Y-%m-%d %H:%M UTC") # --------------------------------------------------------------------------- diff --git a/hindsight-integrations/claude-code/tests/test_content.py b/hindsight-integrations/claude-code/tests/test_content.py index 51fb3ea693..8aaaeae29a 100644 --- a/hindsight-integrations/claude-code/tests/test_content.py +++ b/hindsight-integrations/claude-code/tests/test_content.py @@ -1,11 +1,14 @@ """Tests for lib/content.py — pure content-processing functions.""" +import re + import pytest from lib.content import ( _extract_text_content, _is_channel_message_tool, compose_recall_query, + format_current_time, format_memories, prepare_retention_transcript, slice_last_turns_by_user_boundary, @@ -469,3 +472,18 @@ def test_without_tool_calls_uses_text_format(self): transcript, _ = prepare_retention_transcript(msgs, retain_full_window=True, include_tool_calls=False) assert "[role: user]" in transcript assert "[user:end]" in transcript + + +# --------------------------------------------------------------------------- +# format_current_time +# --------------------------------------------------------------------------- + + +class TestFormatCurrentTime: + def test_includes_utc_suffix(self): + # The "UTC" suffix prevents client LLMs from misreading the + # timestamp as local time. + assert format_current_time().endswith(" UTC") + + def test_format_shape(self): + assert re.fullmatch(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2} UTC", format_current_time())