# Several AI coding sessions, one working tree: mixed commits and half-edited builds

> I run several Claude Code sessions on this site, all in the live site's folder. In two days: commits carrying other sessions' files, a build failing with no new commit, and clashing to-do numbers.

- Date: 2026-11-27
- Topics: DevOps
- Chinese original: https://kbs0830.com/blog/multiple-ai-sessions-one-folder

Most changes to this site are made together with Claude Code. To go faster, I often open three or four sessions at once: one for layout, one for the radar, one for tidying the to-do list. The catch is that they **all work in the same folder**, and that folder is the live site itself (the `scripts/server.js` the desktop's scheduler runs, and the CI deploy, both live here).

Normally each edits its own files and nothing seems wrong. On 11/26 and 11/27, the following things happened one after another.

## 1. A commit carried someone else's files

The staging area (index) that `git add` fills is **one copy shared by the whole folder**, no matter which session put things there. Session A runs `git add` for its files and has not committed yet; session B then runs `git add its-files && git commit`, and the commit takes **everything** in the staging area with it.

What actually happened:

| commit | message said | actual content also included |
|---|---|---|
| `8fc6a04` | remove duplicate "contact me" from the home footer | `watchdog.ps1`, radar health check, `HeroSky.tsx`, fake admin data... 10 files in all |
| `3915209` | widen admin by screen width | 4 files, all project pages and `PortfolioSection.tsx` |

Nothing was broken in the code itself, but the commit message does not match the content, so later when I ask "why was this line changed" I look in the wrong place. Worse, it can push someone else's **unfinished** work live.

What I can do right away: before every commit, look at `git diff --cached --stat`, and use `git commit <files...>` so that only my own paths are committed. That way, even if the staging area holds someone else's work, it is not taken along.

## 2. No new commit, yet the deploy build failed

The deploy script `deploy.ps1` goes: `git pull` in the live folder, then `next build` into whichever of the two slots is not in use, then a health check, then swap. The hole is that **`next build` reads the files in the folder, not the version in git**.

`logs/deploy.log` shows two clear cases:

```text
[2026-11-26T23:03:33] git pull origin main
[2026-11-26T23:03:33]   Already up to date.
[2026-11-26T23:04:19]   Error: Route "/projects/[slug]": Next.js encountered uncached or runtime data …
[2026-11-26T23:04:20] [FAILED] Build failed (exit 1), live site untouched, still .next-a

[2026-11-27T09:57:56]   Already up to date.
[2026-11-27T09:58:16]   ./src/app/api/chat/route.ts:33:96  Error: Unterminated string constant
[2026-11-27T09:58:16] [FAILED] Build failed (exit 1), live site untouched, still .next-a
```

Both say "Already up to date": nothing new was pulled, and yet the build failed. The reason is that another session was in the middle of editing. The first time, a component on the radar project page was half edited (in the same minute `tsc` also reported a type error in `RadarSnapshot.tsx`), making a project page that should have been fully static read live data. The second was more direct: a string in `route.ts` was half typed when the build picked it up.

Nothing went wrong this time thanks to the [two-slot deploy](/en/blog/vscode-locks-next): the new slot failed to build, and the live slot kept serving, so the cost was one wasted run and one failure email. The reverse case is scarier: something half edited by someone else that **happens to build** goes straight live, and git has no such version, so when something breaks I do not even know what to roll back to.

The right approach is to build in a **clean copy** at deploy time: `git worktree add` a copy of `origin/main`, point its `node_modules` back to the existing one with a junction (creating a junction on Windows needs no administrator rights), and move the build output into the slot afterwards. That is still on my to-do list, not done yet.

## 3. Two writers on the database: clashing numbers

The to-do list lives in `data/admin.db` (SQLite) and is added to with a command-line script. While tidying the list, I was about to add an item as Q13, but in the meantime another session had already added Q13 to Q17.

The database itself was fine: it had long been in WAL mode with a `busy_timeout` set (the story is in [SQLite WAL and backup](/en/blog/sqlite-wal-vacuum-into-backup)), so simultaneous writes do not corrupt the data. What broke was the flow of "**look up the highest number, remember it, write later**": someone cut in between the lookup and the write. I changed it to compute the next free number right before writing (mine ended up as Q18), and it went in fine.

## 4. Also hit: Git Bash rewrites your arguments

This is not the multi-session's fault, but I hit it the same day, and it is sneaky. Claude Code's shell on Windows is Git Bash (MSYS2), which automatically converts **arguments that look like Unix paths** into Windows paths before passing them to Windows programs like `node`. I was adding a to-do whose title started with `/now`:

```bash
$ node -e 'console.log(process.argv[1])' "/now, /uses"
C:/Program Files/Git/now, /uses
```

The title stored in the database became `C:/Program Files/Git/now, ...`. To turn the conversion off, add `MSYS_NO_PATHCONV=1`:

```bash
$ MSYS_NO_PATHCONV=1 node -e 'console.log(process.argv[1])' "/now, /uses"
/now, /uses
```

But with it off, **real paths are not converted either**. In the same command I used a temp file path from `cygpath -u`, which is `/tmp/...`, and Node took it as the root of the current drive:

```text
ENOENT C:\tmp\msys-test.md
```

All seven additions failed. Convert paths to Windows form yourself first: `cygpath -w` gives `C:\Users\...\Temp\...`, which reads fine whether or not `MSYS_NO_PATHCONV` is on.

The rule in one sentence: **if an argument has text starting with `/`, add `MSYS_NO_PATHCONV=1`, and use `cygpath -w` for any file path on the same line.**

## The real fix: one worktree per session

Problems 1 to 3 share one cause: several writers sharing one working area. Git already has the answer: `git worktree` gives one repo several folders, each with its own branch and its own staging area, sharing the same `.git` history:

```bash
git worktree add ../kbs-hero -b hero-tweak   # this session edits only here
# edit, commit, merge back into main
git worktree remove ../kbs-hero
```

The Claude Code desktop app lets you tick "use a worktree" when starting a session. The live folder is then left only for deploys, with nobody editing files in it.

Both of these (deploys building in a clean copy, one worktree per session) are still on my to-do list, waiting for me to decide. Until then, the manual guardrails are:

- Commit with `git commit <my files>`, and look at `git diff --cached --stat` first
- When adding anything numbered, look up the free number right before writing
- In Git Bash, add `MSYS_NO_PATHCONV=1` for arguments starting with `/`, and use `cygpath -w` for paths

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/multiple-ai-sessions-one-folder
