[Bug] CLAUDE.md startup/exit session protocols ignored - no automatic execution of time-sensitive instructions

Resolved 💬 3 comments Opened Dec 9, 2025 by greogory Closed Dec 12, 2025

Bug Description

Claude Code does not automatically execute startup or exit protocols defined in ~/.claude/CLAUDE.md or project-level CLAUDE.md files. Instructions that should run automatically at session start/end are ignored unless the user explicitly prompts for them.

Steps to Reproduce

1. Create a minimal CLAUDE.md with startup instructions

Create ~/.claude/CLAUDE.md with the following content:

# Session Protocol

## MANDATORY STARTUP ACTIONS
On every Claude Code startup, you MUST automatically:
1. Run `date` to get current system time
2. Report the current time to the user
3. Say "Startup protocol executed"

Do NOT wait to be asked. Execute immediately when session begins.

2. Start a new Claude Code session

claude
# or
claude --model opus

3. Observe the first response

Expected: Claude automatically runs date, reports the time, and says "Startup protocol executed" without being prompted.

Actual: Claude greets you normally and does NOT execute the startup instructions. The CLAUDE.md instructions are treated as reference material, not executable directives.

4. Verify Claude received the instructions

Ask: "What does my CLAUDE.md say about startup?"

Claude will correctly describe the startup protocol, proving it read the file but did not execute the instructions.

Real-World Example

User's CLAUDE.md contained:

- **On Claude Code startup**: Read and report `/raid0/ClaudeCodeProjects/exit.<date>` to show when the last session ended.
- Trust the system date from the `<env>` block or `date` command - it is ALWAYS correct.

What happened:

  1. Claude read an exit timestamp file showing 16:43:01
  2. Claude reported this as the last session time
  3. Claude did NOT run date to verify current time
  4. Actual system time was 19:48 (3+ hours later)
  5. When user said "I exited 2 minutes ago", Claude incorrectly agreed instead of checking the system time
  6. The explicit instruction to "trust the system date" and verify via date command was ignored

Root Cause Analysis

The model appears to:

  1. Read CLAUDE.md instructions as context/reference material rather than executable directives
  2. Not distinguish between "instructions to follow when asked" vs "instructions to execute automatically on specific triggers"
  3. Not have a mechanism to execute startup/exit hooks defined in markdown config files
  4. Not recognize trigger phrases like "On Claude Code startup" or "MANDATORY" as requiring automatic execution

Workaround

Recommended: Custom Slash Command

Create ~/.claude/commands/startup.md:

Execute the startup protocol from CLAUDE.md:
1. Run `date` to get and report current system time
2. Check for exit.* files and report when last session ended
3. Calculate elapsed time since last session

Then type /startup as your first command each session.

Pros:

  • Native to Claude Code ecosystem
  • Executes within session context where CLAUDE.md is loaded
  • Single command, easy to remember
  • Portable across terminals
  • Can be version-controlled with your dotfiles

Cons:

  • Still requires manual invocation (defeats purpose of "automatic" startup)
  • Must remember to run it every session

Alternative: Shell Alias

Add to ~/.bashrc or ~/.zshrc:

alias claude='echo "Remember: type /startup" && command claude'

Pros:

  • Provides a reminder before Claude launches

Cons:

  • External to Claude Code (shell-specific)
  • Just a reminder, doesn't solve the problem
  • Requires shell configuration
  • Not portable across different shell environments

Proposed Solutions

  1. SessionStart hook support: Add a hook type that executes CLAUDE.md sections automatically

``json
{
"hooks": {
"SessionStart": [{"command": "execute-claude-md-section", "section": "STARTUP"}]
}
}
``

  1. Auto-execute markdown syntax: Special markers for automatic execution

``markdown
<!-- AUTO-EXECUTE: startup -->
Run
date and report the time.
<!-- /AUTO-EXECUTE -->
``

  1. Improved instruction parsing: Recognize phrases like "On startup", "MANDATORY", "MUST automatically" as triggers requiring immediate execution without user prompting
  1. First-message injection: Allow CLAUDE.md to specify a "first prompt" that Claude treats as if the user sent it

Environment Info

  • Platform: linux (CachyOS/Arch)
  • Terminal: CLI (Kitty)
  • Claude Code alias: claude-lite (claude --model opus)
  • Model: Claude Opus 4.5

Related Issues

  • #13417 - Claude Code not following user instructions consistently (similar but less specific)
  • #13351 - Incorrect year interpretation (tangentially related to time handling)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗