Skip to content

Instantly share code, notes, and snippets.

@corylanou
Last active September 10, 2025 20:48
Show Gist options
  • Select an option

  • Save corylanou/a2a3a23280e3b29d1dc4ce26e5ce96a1 to your computer and use it in GitHub Desktop.

Select an option

Save corylanou/a2a3a23280e3b29d1dc4ce26e5ce96a1 to your computer and use it in GitHub Desktop.
Auto-Update Date in Claude Code Global CLAUDE.md - Workaround for broken global hooks

Auto-Update Date in Claude Code Global CLAUDE.md

This guide shows how to automatically update the date in your global ~/.claude/CLAUDE.md file every time you start Claude Code, bypassing the broken global hooks system.

The Problem

Claude Code v1.0.110+ has a bug where global hooks in ~/.claude/settings.json don't execute during session startup. This prevents automatic date updates in your global CLAUDE.md file.

The Solution

Create a shell function wrapper that intercepts all claude commands and runs the date update script before starting Claude.

Setup Steps

1. Create the Date Update Script

Create ~/.claude/update-date.sh:

#!/bin/bash

# Script to update the current date in global CLAUDE.md file
# Only updates if the date is different from today

CLAUDE_MD="$HOME/.claude/CLAUDE.md"
TODAY=$(date +%Y-%m-%d)

# Check if CLAUDE.md exists
if [[ ! -f "$CLAUDE_MD" ]]; then
    echo "CLAUDE.md not found at $CLAUDE_MD"
    exit 1
fi

# Get current date from file
CURRENT_DATE=$(grep -o '\*\*Current date\*\*: [0-9-]*' "$CLAUDE_MD" | sed 's/\*\*Current date\*\*: //')

# Only update if date is different
if [[ "$CURRENT_DATE" != "$TODAY" ]]; then
    # Use sed to update the date line
    if [[ "$OSTYPE" == "darwin"* ]]; then
        # macOS sed syntax
        sed -i '' "s/\*\*Current date\*\*: [0-9-]*/\*\*Current date\*\*: $TODAY/" "$CLAUDE_MD"
    else
        # Linux sed syntax
        sed -i "s/\*\*Current date\*\*: [0-9-]*/\*\*Current date\*\*: $TODAY/" "$CLAUDE_MD"
    fi
    echo "Updated CLAUDE.md date from $CURRENT_DATE to $TODAY"
else
    echo "Date already current: $TODAY"
fi

Make it executable:

chmod +x ~/.claude/update-date.sh

2. Create the Claude Wrapper Function

Add this function to your ~/.zshrc (or ~/.bashrc if using bash):

# Claude wrapper function that auto-updates date
claude() {
    # Update date in global CLAUDE.md before starting Claude
    ~/.claude/update-date.sh
    # Call the actual claude command with all arguments
    command claude "$@"
}

3. Reload Your Shell Configuration

source ~/.zshrc

How It Works

  1. Intercepts all claude commands: The function runs before the actual Claude Code CLI
  2. Updates date automatically: Runs the update script every time
  3. Passes through all arguments: Uses command claude "$@" to call the real Claude with all original arguments
  4. Works globally: Functions in any directory, unlike project-specific hooks

Yolo Mode Support

The wrapper function preserves all arguments, so your yolo mode setup continues to work:

claude --skip-dangerously  # Still works exactly the same

You can also create an alias for convenience:

# Add this to your ~/.zshrc for easy yolo mode access
alias clauded="claude --skip-dangerously"

Testing

Test the setup:

  1. Manually change the date in ~/.claude/CLAUDE.md to an old date
  2. Run any claude command
  3. Check that the date was updated automatically

Benefits

  • Always works: No dependency on broken global hooks
  • Transparent: Use claude command normally
  • Efficient: Only updates when date actually changes
  • Cross-platform: Works on macOS and Linux
  • Argument preservation: All Claude flags and options work unchanged

Troubleshooting

Script not running?

  • Check that ~/.claude/update-date.sh is executable: ls -la ~/.claude/update-date.sh
  • Verify the function is loaded: type claude should show it's a function

Date not updating?

  • Manually test the script: ~/.claude/update-date.sh
  • Check your CLAUDE.md has the expected format: **Current date**: YYYY-MM-DD

Function not working?

  • Reload your shell: source ~/.zshrc
  • Check for syntax errors: zsh -n ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment