/ constants / common.ts
common.ts
 1  import memoize from 'lodash-es/memoize.js'
 2  
 3  // This ensures you get the LOCAL date in ISO format
 4  export function getLocalISODate(): string {
 5    // Check for ant-only date override
 6    if (process.env.CLAUDE_CODE_OVERRIDE_DATE) {
 7      return process.env.CLAUDE_CODE_OVERRIDE_DATE
 8    }
 9  
10    const now = new Date()
11    const year = now.getFullYear()
12    const month = String(now.getMonth() + 1).padStart(2, '0')
13    const day = String(now.getDate()).padStart(2, '0')
14    return `${year}-${month}-${day}`
15  }
16  
17  // Memoized for prompt-cache stability — captures the date once at session start.
18  // The main interactive path gets this behavior via memoize(getUserContext) in
19  // context.ts; simple mode (--bare) calls getSystemPrompt per-request and needs
20  // an explicit memoized date to avoid busting the cached prefix at midnight.
21  // When midnight rolls over, getDateChangeAttachments appends the new date at
22  // the tail (though simple mode disables attachments, so the trade-off there is:
23  // stale date after midnight vs. ~entire-conversation cache bust — stale wins).
24  export const getSessionStartDate = memoize(getLocalISODate)
25  
26  // Returns "Month YYYY" (e.g. "February 2026") in the user's local timezone.
27  // Changes monthly, not daily — used in tool prompts to minimize cache busting.
28  export function getLocalMonthYear(): string {
29    const date = process.env.CLAUDE_CODE_OVERRIDE_DATE
30      ? new Date(process.env.CLAUDE_CODE_OVERRIDE_DATE)
31      : new Date()
32    return date.toLocaleString('en-US', { month: 'long', year: 'numeric' })
33  }