# What Really Happens When Two Claude Code Sessions Edit the Same File

> Source: <https://dev.to/flisk/what-really-happens-when-two-claude-code-sessions-edit-the-same-file-53ce>
> Published: 2026-11-30 18:38:13+00:00

**Key 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.

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.

In Claude Code:

```
/plugin marketplace add flisk-sh/run-my-agents
/plugin install run-my-agents@run-my-agents
```

There 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.

`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`.
It 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.

| Variable | Default | 
|---|---|
| `RUN_MY_AGENTS_TTL_MINUTES` | `10` | 
| `RUN_MY_AGENTS_DIR` | `~/.run-my-agents` | 
| `RUN_MY_AGENTS_MODE` | `warn` (`off` disables the warning) | 
| `RUN_MY_AGENTS_IGNORE` | none, for example `*.snap,docs/gen/**` | 
| `RUN_MY_AGENTS_DEBUG` | off, `1` writes`debug.log` | 

Lockfiles, `*.generated.*`, `dist/` and `node_modules/` are always skipped. When a session ends, its claims are dropped.

Git 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.

The 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:

```
cd services/app/board && bun install && bun start
```

Then open [http://localhost:4100](http://localhost:4100).

`sed` or `echo > file`, are not seen.` node` on your PATH.
If your agents run on shared files across machines, this will not help. For several sessions on one laptop, it is one small hook.

Next: starting computers for agents with Fleet.
