[BUG] Claude not executing mandatory script on new sessions

Resolved 💬 3 comments Opened Oct 15, 2025 by ghost Closed Oct 19, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Bug Report: Claude Code Fails to Execute Mandatory Startup Commands from CLAUDE.md

Summary

Claude Code consistently fails to execute commands marked as "MANDATORY ACTIONS" and "FIRST ACTION when conversation starts" in the user's global CLAUDE.md configuration file, despite explicit instructions to execute them automatically at session startup.

Impact

This breaks automated prompt history logging systems that rely on session initialization scripts running at the start of every conversation. Users lose tracking of their daily activities and cannot generate management reports based on conversation history.

Environment

  • Claude Code Version: Latest (as of 2025-10-15)
  • Platform: Windows (win32)
  • Configuration File: C:\Users\Andy\.claude\CLAUDE.md (global user configuration)

Expected Behavior

According to the CLAUDE.md configuration (lines 21-31), Claude Code should:

  1. Execute InitializeSession.ps1 as the FIRST ACTION when any conversation starts
  2. Do this automatically without asking
  3. Execute this before any other actions
  4. Store the returned log file path for use throughout the session

Actual Behavior

  • Claude Code starts the conversation without executing the initialization script
  • The script is only executed if manually triggered later or if the user explicitly asks about it
  • No error is shown - the instruction is simply not followed

Reproduction Steps

  1. Create C:\Users\Andy\.claude\CLAUDE.md with the content shown below
  2. Start a new Claude Code conversation in any directory
  3. Send any prompt to start the conversation
  4. Observe that the initialization script is NOT executed automatically
  5. The session log file is not created until manually triggered

Relevant CLAUDE.md Configuration

The global configuration file C:\Users\Andy\.claude\CLAUDE.md contains:

## Prompt History Logging

**CRITICAL: Log every user prompt to daily session file**

**MANDATORY ACTIONS - Execute these automatically without asking:**

For EVERY conversation session, Claude MUST execute these commands:

1. **FIRST ACTION when conversation starts - Initialize the session log:**
   ```bash
   # Execute this command immediately at the start of ANY new conversation:
   powershell -ExecutionPolicy Bypass -File "D:\ClaudePromptHistory\Scripts\InitializeSession.ps1"
   ```
   - Store the returned log file path in memory for the entire session
   - This creates the monthly folder and session log file automatically

(Full file contents available in reproduction details)

Analysis

The instructions are:

  • ✅ Clearly marked as "MANDATORY ACTIONS"
  • ✅ Explicitly state "Execute these automatically without asking"
  • ✅ Specify "FIRST ACTION when conversation starts"
  • ✅ Provide exact command to execute
  • ✅ Pre-authorized in the "Pre-Authorized Operations" section

Despite all of this, Claude Code does not execute the command at startup.

What Works

  • The command executes successfully when manually triggered
  • The script itself works correctly (returns log file path as expected)
  • Claude Code can execute the same command later in the conversation without issues

What Doesn't Work

  • Automatic execution at session start as specified by "FIRST ACTION when conversation starts"
  • Following "MANDATORY ACTIONS" directives in CLAUDE.md

Workaround

None. User must manually remind Claude to run the initialization, which defeats the purpose of automated logging.

Request

Please implement reliable execution of commands marked as "FIRST ACTION when conversation starts" in CLAUDE.md files, ensuring they run before any other actions in the session.

What Should Happen?

Claude should run the mandatory script each and every session since that's the directive provided in my user global claude.md

Error Messages/Logs

Steps to Reproduce

see the content of the claude.md in this bug.
Run a new claude session. Sometimes it'll run the mandatory script, but sometimes it doesn't
Claude needs to be consistent and run the script it is configured to.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

.0.15 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

this claude.md does not always run the requested script:

## Prompt History Logging

**CRITICAL: Log every user prompt to daily session file**

**MANDATORY ACTIONS - Execute these automatically without asking:**

For EVERY conversation session, Claude MUST execute these commands:

1. **FIRST ACTION when conversation starts - Initialize the session log:**
   ```bash
   # Execute this command immediately at the start of ANY new conversation:
   powershell -ExecutionPolicy Bypass -File "D:\ClaudePromptHistory\Scripts\InitializeSession.ps1"
   ```
   - Store the returned log file path in memory for the entire session
   - This creates the monthly folder and session log file automatically

View original on GitHub ↗

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