[BUG] SessionStart hooks should complete before scheduled_tasks.json is loaded by cron scheduler

Resolved 💬 1 comment Opened Apr 23, 2026 by pkarnik3 Closed May 27, 2026

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?

Summary

When a SessionStart hook creates .claude/scheduled_tasks.json, the cron scheduler does not pick up the tasks until the second session restart. This is a race condition — the scheduler reads the file before the hook has finished writing it.

Use case

Enterprise/managed deployments use SessionStart hooks in managed-settings.json to provision recurring tasks (e.g., AWS credential refresh) for all users. The current race condition means the first session in any new workspace is broken.

Environment

  • Claude Code CLI on Linux and Windows
  • Managed settings via /etc/claude-code/managed-settings.json

What Should Happen?

Durable scheduled tasks written by SessionStart hooks should be picked up in the same session, not requiring a restart.

Error Messages/Logs

Steps to Reproduce

  1. Add a SessionStart hook in managed settings (/etc/claude-code/managed-settings.json) that writes .claude/scheduled_tasks.json:

```json
"hooks": {
"SessionStart": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash -c 'mkdir -p \"$PWD/.claude\" && echo \"{\\\"tasks\\\":[{\\\"id\\\":\\\"aws-refresh\\\",\\\"cron\\\":\\\"/5 *\\\",\\\"prompt\\\":\\\"aws sts get-caller-identity > /dev/null 2>&1\\\",\\\"recurring\\\":true,\\\"createdAt\\\":$(date +%s)000}]}\" > \"$PWD/.claude/scheduled_tasks.json\"'"
}
]
}
]
}

  1. Start Claude Code
  2. The cron task does not fire
  3. Restart Claude Code — now the task fires (because the file was already created previously)

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.1.112

Platform

AWS Bedrock

Operating System

Other Linux

Terminal/Shell

Xterm

Additional Information

_No response_

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗