DEV Community

flisk
flisk

Posted on

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

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.

Install

In Claude Code:

/plugin marketplace add flisk-sh/run-my-agents
/plugin install run-my-agents@run-my-agents
Enter fullscreen mode Exit fullscreen mode

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.

The walkthrough

  1. Session 1 edits 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.
  2. Session 2 tries to edit api.ts. The hook sees a claim from the last 10 minutes and stops the edit once, with a note that names the other session, its branch and how long ago it edited.
  3. Session 2 reads the file again and edits. A second try always goes through, and session 2 now holds the claim.

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.

Settings

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.

Worktrees are not enough

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 board

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
Enter fullscreen mode Exit fullscreen mode

Then open http://localhost:4100.

Limits

  • One computer only. Other machines are not seen.
  • Edits through Bash, like sed or echo > file, are not seen.
  • It matches whole files, not lines.
  • It needs 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.

Top comments (0)