Skip to content

Race condition when multiple Claude Code windows write to tasks.json #1567

@bjcoombs

Description

@bjcoombs

Problem

When multiple Claude Code windows (separate processes) access Task Master simultaneously, the JSON file can get corrupted or work that Task Master claims to have saved is lost.

Root Cause

The readJSON() and writeJSON() functions in scripts/modules/utils.js had no file locking mechanism:

  • Multiple processes could read the same file simultaneously
  • Each process would make changes to its copy
  • When writing, later writes would overwrite earlier ones, losing updates

Additionally, the _rawTaggedData snapshot pattern caused stale data issues - a snapshot taken at read time could become outdated by the time the write occurred.

Impact

  • Data loss when multiple Claude Code sessions work on the same project
  • Corrupted tasks.json file
  • Lost task updates, status changes, and subtask modifications

Solution

Implemented in PR #1566:

  • Cross-process file locking using proper-lockfile (async) and custom lock files with exclusive wx flag (sync)
  • Atomic writes using temp file + rename pattern
  • Re-read file inside lock to get current state
  • Stale lock detection and automatic cleanup (10-second timeout)

Reproduction Steps

  1. Open multiple Claude Code windows on the same project
  2. Have both windows make Task Master operations simultaneously (e.g., set-status, update-subtask)
  3. Observe that some changes are lost or file becomes corrupted

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:task-managementCore task management featuresbugSomething isn't workinghigh-priorityUrgent issue requiring immediate attentionprovider:claude-codeClaude Code integrated models

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions