{"slug": "what-really-happens-when-two-claude-code-sessions-edit-the-same-file", "title": "What Really Happens When Two Claude Code Sessions Edit the Same File", "summary": "A developer at Flisk released Run My Agents, a Claude Code plugin that uses a PreToolUse hook on Edit, Write, MultiEdit and NotebookEdit to record which session touched a file in ~/.run-my-agents/claims.json, warning when two sessions edit the same file so the agent re-reads and merges instead of overwriting. The tool is a warning rather than a lock, skips lockfiles, generated files, dist/ and node_modules/, and ships with a macOS app and a local board page that lists sessions and flags conflicting edits. The author notes shell writes via sed or echo are not detected and that the approach does not cover agents on shared files across machines.", "body_md": "You open a second Claude Code session on the same repo to fix a bug while the first one works on a feature. Both touch `api.ts`. The later write wins and the earlier work is gone. Run My Agents is a small plugin that catches this.\n\nIn Claude Code:\n\n```\n/plugin marketplace add flisk-sh/run-my-agents\n/plugin install run-my-agents@run-my-agents\n```\n\nThere is also a macOS app, installed with `curl -fsSL https://run-my-agents.flisk.si/install.sh | sh`. The page says it is free, with no server, no account and no keys.\n\n`api.ts`. A `PreToolUse` hook runs before `Edit`, `Write`, `MultiEdit` and `NotebookEdit`, and writes down which session touched the file in `~/.run-my-agents/claims.json`.\nIt is a warning, not a lock. The point is that the agent re-reads the file and merges its change into the new content instead of overwriting it.\n\n| Variable | Default | \n|---|---|\n| `RUN_MY_AGENTS_TTL_MINUTES` | `10` | \n| `RUN_MY_AGENTS_DIR` | `~/.run-my-agents` | \n| `RUN_MY_AGENTS_MODE` | `warn` (`off` disables the warning) | \n| `RUN_MY_AGENTS_IGNORE` | none, for example `*.snap,docs/gen/**` | \n| `RUN_MY_AGENTS_DEBUG` | off, `1` writes`debug.log` | \n\nLockfiles, `*.generated.*`, `dist/` and `node_modules/` are always skipped. When a session ends, its claims are dropped.\n\nGit worktrees keep files apart but not ports. The Flisk agent docs say two worktrees of one repository inherit the same project name and fixed ports, so starting `flisk up` in both can cause container name conflicts and `EADDRINUSE` errors. Give each worktree a unique `project.name` in `.flisk/project.json` and distinct port overrides in `.env`, or run validation tasks one at a time.\n\nThe repo also has a local page that shows every Claude Code session as a card, with the files it touched and a warning when two sessions edited the same file. It reads `~/.claude/projects` and refreshes every 5 seconds:\n\n```\ncd services/app/board && bun install && bun start\n```\n\nThen open [http://localhost:4100](http://localhost:4100).\n\n`sed` or `echo > file`, are not seen.` node` on your PATH.\nIf your agents run on shared files across machines, this will not help. For several sessions on one laptop, it is one small hook.\n\nNext: starting computers for agents with Fleet.", "url": "https://wpnews.pro/news/what-really-happens-when-two-claude-code-sessions-edit-the-same-file", "canonical_source": "https://dev.to/flisk/what-really-happens-when-two-claude-code-sessions-edit-the-same-file-53ce", "published_at": "2026-11-30 18:38:13+00:00", "updated_at": "2026-11-30 18:45:29.676170+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Run My Agents", "Flisk", "Anthropic"], "also_reported_by": [], "takeaway": "A PreToolUse hook that records per-session file claims in a shared JSON file can warn concurrent Claude Code sessions to re-read and merge rather than overwrite, though it misses shell writes like sed or echo and only covers sessions on one machine.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/what-really-happens-when-two-claude-code-sessions-edit-the-same-file", "markdown": "https://wpnews.pro/news/what-really-happens-when-two-claude-code-sessions-edit-the-same-file.md", "text": "https://wpnews.pro/news/what-really-happens-when-two-claude-code-sessions-edit-the-same-file.txt", "jsonld": "https://wpnews.pro/news/what-really-happens-when-two-claude-code-sessions-edit-the-same-file.jsonld"}}