Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
v1.91.207.0 fix(global-discover): count removed Claude worktree sessions with their repository (port of #3334) (#3387)
Garry Tan3b6502f79c57
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c73e8784a..5a5072300 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,15 @@# Changelog+## [1.91.207.0] - 2026-10-25++**Per-repository session counts include sessions from removed Claude Code worktrees (ported from #3334 by @Shweta-Mishra-ai).** Claude Code creates worktrees at `<repo>/.claude/worktrees/<name>` and removes them once their branch merges, but their session history stays. `gstack-global-discover` resolved each session's recorded directory with git, so a removed worktree resolved to nothing: its sessions counted in the tool total and in no repository. Reproduced on main: 2 sessions in a repo plus 3 in a removed worktree gave `total_sessions 5` but 2 for the repo.++### Fixed+- **`bin/gstack-global-discover.ts`**: when a session's directory no longer exists and sits inside `<repo>/.claude/worktrees/<name>` (or a subdirectory of it), the session counts with `<repo>`. Any other missing directory, and a worktree whose repository is gone too, still count in no repository. A live worktree keeps its own path, as before.++### Tests+- `test/global-discover.test.ts` gains six end-to-end cases built with real `git worktree add` and `remove` (removed worktree, a subdirectory of one, a repo with no remote, plus the live-worktree, gone-repo and plain-missing-directory controls) and table tests for the path matcher. The three positive cases and the matcher tests fail on main.+## [1.91.206.0] - 2026-10-25**A repo that keeps `.gstack/` out of git can give pregate a policy, and name the CI lanes a local run satisfies (#3286).** On a shared repo where gstack is one contributor's tool, pregate fell back to defaults, so every platform lane the machine could not run (an `ubuntu-latest` suite on a Mac, say) became a `requires-remote` obligation that never cleared, even when that suite runs the same here. Ported from #3286 by arlophoenix, whose 13 commits carry the feature (merged with their history kept); our commits on top close two findings from a security-focused review of the port.diff --git a/VERSION b/VERSIONindex 32e1b690a..c5d5571bc 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-1.91.206.0+1.91.207.0diff --git a/agents-digest/gstack-AGENTS.md b/agents-digest/gstack-AGENTS.mdindex 216383b07..2ce846c8e 100644--- a/agents-digest/gstack-AGENTS.md+++ b/agents-digest/gstack-AGENTS.md@@ -1,4 +1,4 @@-# gstack digest v1.91.206.0 — regenerate/re-copy after upgrading gstack+# gstack digest v1.91.207.0 — regenerate/re-copy after upgrading gstackBehavioral rules from gstack (https://github.com/garrytan/gstack), compressedfor agent hosts without a full skill install. The full skills add workflows,diff --git a/bin/gstack-global-discover.ts b/bin/gstack-global-discover.tsindex d8d8d0e9f..88cfbfdbe 100644--- a/bin/gstack-global-discover.ts+++ b/bin/gstack-global-discover.ts@@ -186,11 +186,26 @@ function gitProject(cwd: string): GitProject | null {const up = prefix.split("/").filter(Boolean).map(() => "..");project = { root: resolve(cwd, ...up), main: basename(common) === ".git" ? dirname(common) : common };}+ } else {+ // A merged branch's worktree is removed but its session history stays:+ // count those sessions with the repository the worktree was created from.+ const parent = parentRepoOfClaudeWorktree(cwd);+ if (parent) project = gitProject(parent);}PROJECT_MEMO.set(cwd, project);return project;}+/**+ * Claude Code creates worktrees at `<repo>/.claude/worktrees/<name>`. Given a+ * cwd inside one (the worktree root or any subdirectory), the repository root+ * it was created from; null for any other path.+ */+export function parentRepoOfClaudeWorktree(cwd: string): string | null {+ const m = cwd.match(/^(.+?)[\\/]\.claude[\\/]worktrees[\\/][^\\/]+(?:[\\/].*)?$/);+ return m ? m[1] : null;+}+function getGitRemote(root: string): string | null {const r = spawnSync("git", ["-C", root, "remote", "get-url", "origin"], {encoding: "utf-8",diff --git a/package.json b/package.jsonindex afd5b5d31..53b6f1d2f 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "gstack",- "version": "1.91.206",+ "version": "1.91.207","description": "Garry's Stack — Claude Code skills + fast headless browser. One repo, one install, entire AI engineering workflow.","license": "MIT","type": "module",diff --git a/test/global-discover.test.ts b/test/global-discover.test.tsindex fd0c80631..8e56a6b42 100644--- a/test/global-discover.test.ts+++ b/test/global-discover.test.ts@@ -644,5 +644,104 @@ describe("gstack-global-discover", () => {expect(json.repos).toHaveLength(1);expect(json.repos[0].sessions.claude_code).toBe(1);});++ // Claude Code worktrees live at <repo>/.claude/worktrees/<name> and are removed once+ // their branch merges; the session history under ~/.claude/projects stays behind.+ function removedWorktree(main: string, name = "feat-x"): string {+ const wt = join(main, ".claude", "worktrees", name);+ git(main, "worktree", "add", "-q", wt);+ return wt;+ }++ test("sessions of a removed Claude worktree count with the repository it was created from", () => {+ const main = repo("work/ai-blogger-lab", "https://github.com/acme/ai-blogger-lab.git");+ const wt = removedWorktree(main);+ session(main, "main-1");+ session(main, "main-2");+ session(wt, "wt-1");+ session(wt, "wt-2");+ session(wt, "wt-3");+ git(main, "worktree", "remove", "--force", wt);+ expect(existsSync(wt)).toBe(false);+ const json = discover();+ expect(json.tools.claude_code.total_sessions).toBe(5);+ expect(json.repos).toHaveLength(1);+ expect(json.repos[0].sessions.claude_code).toBe(5);+ expect(json.repos[0].paths).toEqual([main]);+ });++ test("a session started in a subdirectory of a removed Claude worktree counts too", () => {+ const main = repo("work/app", "[email protected]:acme/app.git");+ const wt = removedWorktree(main);+ mkdirSync(join(wt, "packages", "web"), { recursive: true });+ session(join(wt, "packages", "web"), "sub-1");+ git(main, "worktree", "remove", "--force", wt);+ const r = discover().repos.find((x) => x.remote === "https://github.com/acme/app")!;+ expect(r.sessions.claude_code).toBe(1);+ expect(r.paths).toEqual([main]);+ });++ test("a removed Claude worktree of a repository with no remote counts with its repository", () => {+ const main = repo("work/local-only");+ const wt = removedWorktree(main);+ session(main, "l-1");+ session(wt, "l-2");+ git(main, "worktree", "remove", "--force", wt);+ const local = discover().repos.filter((x) => x.remote.startsWith("local:"));+ expect(local).toHaveLength(1);+ expect(local[0].sessions.claude_code).toBe(2);+ });++ test("a live Claude worktree keeps its own path next to its repository's", () => {+ const main = repo("work/live", "https://github.com/acme/live.git");+ const wt = removedWorktree(main);+ session(main, "m-1");+ session(wt, "w-1");+ const r = discover().repos.find((x) => x.remote === "https://github.com/acme/live")!;+ expect(r.sessions.claude_code).toBe(2);+ expect(r.paths.sort()).toEqual([main, wt].sort());+ });++ test("a removed Claude worktree whose repository is also gone is not counted as a repository", () => {+ const gone = join(home, "work", "gone-repo");+ session(join(gone, ".claude", "worktrees", "feat-x"), "g-1");+ const json = discover();+ expect(json.tools.claude_code.total_sessions).toBe(1);+ expect(json.repos).toHaveLength(0);+ });++ test("a removed directory that is not a Claude worktree is not counted as a repository", () => {+ const main = repo("work/real", "https://github.com/acme/real.git");+ session(join(main, "some", "deleted-dir"), "d-1");+ session(join(main, ".claude", "worktrees"), "d-2");+ session(main, "r-1");+ const json = discover();+ expect(json.tools.claude_code.total_sessions).toBe(3);+ expect(json.repos).toHaveLength(1);+ expect(json.repos[0].sessions.claude_code).toBe(1);+ });++ describe("parentRepoOfClaudeWorktree", () => {+ let parentRepoOfClaudeWorktree: (cwd: string) => string | null;+ beforeEach(async () => {+ parentRepoOfClaudeWorktree = (await import("../bin/gstack-global-discover.ts")).parentRepoOfClaudeWorktree;+ });++ test("returns the repository root for a worktree path, with or without a subdirectory", () => {+ expect(parentRepoOfClaudeWorktree("/Users/me/code/app/.claude/worktrees/feat-x")).toBe("/Users/me/code/app");+ expect(parentRepoOfClaudeWorktree("/Users/me/code/app/.claude/worktrees/feat-x/src/lib")).toBe("/Users/me/code/app");+ expect(parentRepoOfClaudeWorktree("C:\\code\\app\\.claude\\worktrees\\feat-x")).toBe("C:\\code\\app");+ });++ test("returns null for any other path", () => {+ for (const p of [+ "/Users/me/code/app",+ "/Users/me/code/app/.claude/worktrees",+ "/Users/me/code/app/.claude/worktrees/",+ "/Users/me/code/not.claude/worktrees/x",+ "/.claude/worktrees/x",+ ]) expect(parentRepoOfClaudeWorktree(p)).toBeNull();+ });+ });});});