worktree-per-session

A rule requiring each parallel coding session to use its own Git worktree, which is a separate working directory linked to the same repository.

In plain words
What is it for?
Use it to create and clean up per-session worktrees, coordinate shared-package changes, and check commit contents safely.
Why use it?
It prevents parallel sessions from overwriting each other's files, branches, or Git index state.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/alphabitcore/nexus-gateway/worktree-per-session
Clone the repo
git clone --depth 1 https://github.com/AlphaBitCore/nexus-gateway

Made for: Cursor.

Per session 378 This file is loaded in full into every session.
When invoked 378 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00378 $0.00378
Opus 5 $0.00189 $0.00189
Sonnet 5 $0.00076 $0.00076
Haiku 4.5 $0.00038 $0.00038

Measured 2d ago against content hash 48afde060a17, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

worktree-per-session scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/worktree-per-session.mdc · 26 lines

What it actually says

Worktree per session (binding)

Each parallel Claude Code / Cursor session runs in its own git worktree so working tree, index, and .git/index.lock are private to that session.

Conventions

  1. Spawn: git worktree add ./worktrees/<topic> [-b feature/<new-branch>] [<base>]. ./worktrees/ is gitignored.
  2. Clean up after merge: git worktree remove ./worktrees/<topic>; if the branch is fully merged, also git branch -d feature/<topic>.
  3. One branch per worktree — git enforces this. For a second session on the same logical work, create a sibling branch.
  4. Shared module coordination — worktrees isolate the working tree, not the module graph. Two worktrees editing the same packages/shared/<subpkg>/ file at once will conflict at merge. Coordinate at the subpackage level; pick disjoint shared sub-packages per worktree.
  5. Commit hygiene: git status --short before commit; git log -1 --stat after — confirms you committed what you intended.
  6. .git/index.lock in your worktree = your own prior git invocation crashed mid-flight. Investigate freely.

Inside a worktree, all git operations are private

git stash, git add -A, git restore, removing .git/index.lock — all safe inside your own worktree because the working tree is not shared with any other session.

Memory anchor: [[project_parallel_worktree_sessions]].

Skipping this rule requires explicit user approval in chat.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 26 lines · 378 tokens per session scan A 48afde060a17

Subscribe to this mod's changes

worktree-per-session is a cursor rule published in the GitHub repository AlphaBitCore/nexus-gateway (22 stars, last pushed 7d ago), licensed Apache-2.0. It adds 378 tokens to every session, about $0.0019 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.