claude-code - 💡(How to fix) Fix [BUG] Durable cron tasks written to ephemeral git worktree instead of main repo [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52839Fetched 2026-04-25 06:19:31
View on GitHub
Comments
2
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×4commented ×2subscribed ×1

Error Message

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

Persisted scheduled tasks created when Claude is running in a non-main worktree are lost when working in other worktrees, or if the worktree is deleted.

What Should Happen?

Persisted scheduled tasks should be available in all worktrees for a given repo.

Error Messages/Logs

Steps to Reproduce

  • CronCreate with durable: true writes scheduled_tasks.json to .claude/ in the current working directory
  • When CWD is a git worktree, the file is lost when the worktree is cleaned up
  • Should write to the main worktree's .claude/ (discoverable via git rev-parse --git-common-dir) or ~/.claude/
  • Reproducible: create worktree, start Claude, create durable cron, remove worktree, task is gone

Claude Model

None

Is this a regression?

Untested.

Last Working Version

None.

Claude Code Version

2.1.119 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

No response

extent analysis

TL;DR

The issue can be fixed by modifying the CronCreate function to write scheduled_tasks.json to the main worktree's .claude/ directory instead of the current working directory.

Guidance

  • Identify the main worktree's directory using git rev-parse --git-common-dir and use this path to store scheduled_tasks.json.
  • Consider using a centralized location like ~/.claude/ as an alternative storage location for scheduled tasks.
  • Update the CronCreate function to handle the case where the current working directory is a git worktree.
  • Verify that the scheduled tasks are persisted across different worktrees and after worktree cleanup.

Example

const gitCommonDir = execSync('git rev-parse --git-common-dir').toString().trim();
const scheduledTasksPath = path.join(gitCommonDir, '.claude', 'scheduled_tasks.json');
// Write to scheduledTasksPath instead of the current working directory

Notes

The solution assumes that the git rev-parse --git-common-dir command returns the correct path to the main worktree's directory. Additionally, the implementation details of the CronCreate function and the execSync function are not provided, so the example code snippet is a suggestion rather than a definitive solution.

Recommendation

Apply workaround: Modify the CronCreate function to write to the main worktree's .claude/ directory or a centralized location like ~/.claude/, as this will ensure that scheduled tasks are persisted across different worktrees and after worktree cleanup.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Durable cron tasks written to ephemeral git worktree instead of main repo [2 comments, 3 participants]