@devries-cameron20 / t3code-1 / commits / d46b90c634
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): the Welcome page offers repositories you only worked on in worktrees (#33923)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Dominik Žabčík committed Nov 12, 2026 at 22:06 UTC d46b90c63459df9ad269d283b310a7b480955efb
3 files changed +144 -47
apps/server/src/project/AgentSessionScanner.test.ts
+65 -6
@@ -869,7 +869,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
869 }),
870 );
871
872 - it.effect("skips linked git worktrees and reports the origin of real checkouts", () =>
872 + it.effect("folds linked git worktrees into their checkout and reports real origins", () =>
873 Effect.gen(function* () {
874 const path = yield* Path.Path;
875 const fileSystem = yield* FileSystem.FileSystem;
@@ -905,8 +905,56 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
905 path.join(submodule, ".git"),
906 `gitdir: ${submoduleGitDir}\n`,
907 );
908 + // A repository whose sessions all ran in a linked worktree is still offered.
909 + const worktreeOnly = yield* makeTempDir("t3code-workspace-worktree-only-");
910 + const worktreeOnlyCheckout = yield* makeTempDir("t3code-workspace-worktree-only-wt-");
911 + const worktreeOnlyGitDir = path.join(worktreeOnly, ".git", "worktrees", "wt");
912 + yield* fileSystem.makeDirectory(worktreeOnlyGitDir, { recursive: true });
913 + yield* fileSystem.writeFileString(
914 + path.join(worktreeOnly, ".git", "config"),
915 + '[remote "origin"]\n\turl = git@github.com:pingdotgg/other.git\n',
916 + );
917 + yield* fileSystem.writeFileString(path.join(worktreeOnlyGitDir, "commondir"), "../..\n");
918 + yield* fileSystem.writeFileString(
919 + path.join(worktreeOnlyCheckout, ".git"),
920 + `gitdir: ${worktreeOnlyGitDir}\n`,
921 + );
922 +
923 + // Not offered: the config is unreadable, so the repository could be bare; and
924 + // the main checkout is reached through a symlink into T3's own state.
925 + const configBaseDir = yield* fileSystem.realPath(
926 + yield* makeTempDir("t3code-scanner-base-"),
927 + );
928 + const links = yield* makeTempDir("t3code-workspace-links-");
929 + const unknown = yield* makeTempDir("t3code-workspace-unknown-");
930 + yield* fileSystem.makeDirectory(path.join(configBaseDir, "state-repo"));
931 + yield* fileSystem.symlink(path.join(configBaseDir, "state-repo"), path.join(links, "repo"));
932 + const hiddenCheckouts: Array<string> = [];
933 + for (const [main, config] of [
934 + [unknown, null],
935 + [path.join(links, "repo"), "[core]\n"],
936 + ] as const) {
937 + const gitDir = path.join(main, ".git", "worktrees", "wt");
938 + yield* fileSystem.makeDirectory(gitDir, { recursive: true });
939 + if (config !== null) {
940 + yield* fileSystem.writeFileString(path.join(main, ".git", "config"), config);
941 + }
942 + yield* fileSystem.writeFileString(path.join(gitDir, "commondir"), "../..\n");
943 + const checkout = yield* makeTempDir("t3code-workspace-hidden-wt-");
944 + yield* fileSystem.writeFileString(path.join(checkout, ".git"), `gitdir: ${gitDir}\n`);
945 + hiddenCheckouts.push(checkout);
946 + }
947
909 - for (const [index, cwd] of [repo, worktree, plain, noRemote, submodule].entries()) {
948 + const sessionDirectories = [
949 + repo,
950 + worktree,
951 + plain,
952 + noRemote,
953 + submodule,
954 + worktreeOnlyCheckout,
955 + ...hiddenCheckouts,
956 + ];
957 + for (const [index, cwd] of sessionDirectories.entries()) {
958 yield* writeTranscript({
959 filePath: path.join(claudeHomePath, "projects", `-slug-${index}`, "a.jsonl"),
960 contents: claudeSessionLine(cwd),
@@ -914,23 +962,34 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
962 });
963 }
964
917 - const result = yield* runScan({ claudeHomePath, codexHomePath });
965 + const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });
966
967 expect(
920 - result.candidates.map((candidate) => ({ path: candidate.path, git: candidate.git })),
968 + result.candidates.map((candidate) => ({
969 + path: candidate.path,
970 + git: candidate.git,
971 + threadCount: candidate.threadCount,
972 + })),
973 ).toEqual([
974 + {
975 + path: worktreeOnly,
976 + git: { remoteKey: "github.com/pingdotgg/other", repository: "pingdotgg/other" },
977 + threadCount: 1,
978 + },
979 {
980 path: submodule,
981 git: {
982 remoteKey: "gitlab.com/pingdotgg/libs/vendor",
983 repository: "pingdotgg/libs/vendor",
984 },
985 + threadCount: 1,
986 },
929 - { path: noRemote, git: { remoteKey: null, repository: null } },
930 - { path: plain, git: null },
987 + { path: noRemote, git: { remoteKey: null, repository: null }, threadCount: 1 },
988 + { path: plain, git: null, threadCount: 1 },
989 {
990 path: repo,
991 git: { remoteKey: "github.com/pingdotgg/t3code", repository: "pingdotgg/t3code" },
992 + threadCount: 2,
993 },
994 ]);
995 }),
apps/server/src/project/AgentSessionScanner.ts
+75 -38
@@ -876,6 +876,20 @@ export const make = Effect.gen(function* () {
876 return `path:${normalizeProjectPathForComparison(realPath)}`;
877 });
878
879 + /** Stats a directory that may be offered as a project, or none when it is missing or excluded. */
880 + const projectDirectoryStats = Effect.fn("AgentSessionScanner.projectDirectoryStats")(function* (
881 + directory: string,
882 + ) {
883 + if (isExcludedProjectPath(directory)) return Option.none<FileSystem.File.Info>();
884 + const stats = yield* statOption(directory);
885 + if (Option.isNone(stats) || stats.value.type !== "Directory") return Option.none();
886 + const realPath = yield* fileSystem
887 + .realPath(directory)
888 + .pipe(Effect.orElseSucceed(() => directory));
889 + // Symlinks can disguise excluded worktree paths; re-check their targets.
890 + return isExcludedProjectPath(realPath) ? Option.none() : stats;
891 + });
892 +
893 // Paths whose own read outlived the deadline, mapped to when they may be read
894 // again. Without this every later scan would wait out the deadline again for
895 // each phase that touches them.
@@ -929,7 +943,11 @@ export const make = Effect.gen(function* () {
943 ) {
944 type GitIdentity =
945 | { readonly _tag: "Repository"; readonly git: AgentSessionProjectGit | null }
932 - | { readonly _tag: "Worktree" }
946 + | {
947 + readonly _tag: "Worktree";
948 + readonly mainCheckout: string | null;
949 + readonly git: AgentSessionProjectGit | null;
950 + }
951 | { readonly _tag: "NotGit" };
952 const identities = new Map<string, GitIdentity>();
953 const repositories: Array<{ directory: string; gitDir: string; linkedWorktree: boolean }> = [];
@@ -962,8 +980,9 @@ export const make = Effect.gen(function* () {
980 );
981 for (const { directory, gitDir } of linkedWorktrees) {
982 const commonDir = (commonDirTexts.get(path.join(gitDir, "commondir")) ?? "").trim();
965 - if (commonDir.length === 0) identities.set(directory, { _tag: "Worktree" });
966 - else
983 + if (commonDir.length === 0) {
984 + identities.set(directory, { _tag: "Worktree", mainCheckout: null, git: null });
985 + } else
986 repositories.push({
987 directory,
988 gitDir: path.resolve(gitDir, commonDir),
@@ -976,20 +995,25 @@ export const make = Effect.gen(function* () {
995 );
996 for (const { directory, gitDir, linkedWorktree } of repositories) {
997 const configText = configTexts.get(path.join(gitDir, "config")) ?? "";
998 + const originUrl = parseOriginUrlFromGitConfig(configText);
999 + const git: AgentSessionProjectGit = {
1000 + remoteKey:
1001 + originUrl === null ? null : sourceControlDefinitions.repositoryKeyFromRemote(originUrl),
1002 + repository: repositoryPathFromRemoteUrl(originUrl),
1003 + };
1004 // Bare repositories have no main checkout, so offer their linked worktrees independently.
1005 if (linkedWorktree && !isBareGitConfig(configText)) {
981 - identities.set(directory, { _tag: "Worktree" });
1006 + identities.set(directory, {
1007 + _tag: "Worktree",
1008 + // Only a common dir named .git sits inside its main checkout, and an
1009 + // unreadable config can't rule out a bare repository.
1010 + mainCheckout:
1011 + configText.length > 0 && path.basename(gitDir) === ".git" ? path.dirname(gitDir) : null,
1012 + git,
1013 + });
1014 continue;
1015 }
984 - const originUrl = parseOriginUrlFromGitConfig(configText);
985 - identities.set(directory, {
986 - _tag: "Repository",
987 - git: {
988 - remoteKey:
989 - originUrl === null ? null : sourceControlDefinitions.repositoryKeyFromRemote(originUrl),
990 - repository: repositoryPathFromRemoteUrl(originUrl),
991 - },
992 - });
1016 + identities.set(directory, { _tag: "Repository", git });
1017 }
1018 return identities;
1019 });
@@ -1701,17 +1725,8 @@ export const make = Effect.gen(function* () {
1725 const expanded = expandHomePath(candidate.cwd.trim(), homeDir);
1726 if (!path.isAbsolute(expanded)) continue;
1727 const resolved = path.resolve(expanded);
1704 - if (directories.has(resolved) || isExcludedProjectPath(resolved)) continue;
1705 - const stats = yield* statOption(resolved);
1706 - if (Option.isNone(stats) || stats.value.type !== "Directory") {
1707 - directories.set(resolved, Option.none());
1708 - continue;
1709 - }
1710 - const realPath = yield* fileSystem
1711 - .realPath(resolved)
1712 - .pipe(Effect.orElseSucceed(() => resolved));
1713 - // Symlinks can disguise excluded worktree paths; re-check their targets.
1714 - directories.set(resolved, isExcludedProjectPath(realPath) ? Option.none() : stats);
1728 + if (directories.has(resolved)) continue;
1729 + directories.set(resolved, yield* projectDirectoryStats(resolved));
1730 }
1731 const directoryGitIdentities = yield* readGitIdentities(
1732 Array.from(directories).flatMap(([directory, stats]) =>
@@ -1719,8 +1734,14 @@ export const make = Effect.gen(function* () {
1734 ),
1735 );
1736
1722 - const directoryKeys = new Map<string, string>();
1723 - const gitIdentities = new Map<string, AgentSessionProjectGit | null>();
1737 + const directoryProjects = new Map<
1738 + string,
1739 + {
1740 + readonly key: string;
1741 + readonly path: string;
1742 + readonly git: AgentSessionProjectGit | null;
1743 + } | null
1744 + >();
1745
1746 for (const candidate of raw) {
1747 const expanded = expandHomePath(candidate.cwd.trim(), homeDir);
@@ -1728,27 +1749,43 @@ export const make = Effect.gen(function* () {
1749 const resolved = path.resolve(expanded);
1750 const stats = directories.get(resolved);
1751 if (stats === undefined || Option.isNone(stats)) continue;
1731 - let key = directoryKeys.get(resolved);
1732 - if (key === undefined) {
1752 + let project = directoryProjects.get(resolved);
1753 + if (project === undefined) {
1754 const gitIdentity = directoryGitIdentities.get(resolved);
1734 - if (gitIdentity === undefined || gitIdentity._tag === "Worktree") {
1735 - key = "";
1755 + if (gitIdentity === undefined) {
1756 + project = null;
1757 + } else if (gitIdentity._tag === "Worktree") {
1758 + // A linked worktree's sessions count toward its main checkout's project.
1759 + const { mainCheckout } = gitIdentity;
1760 + const mainStats =
1761 + mainCheckout === null ? Option.none() : yield* projectDirectoryStats(mainCheckout);
1762 + project =
1763 + mainCheckout !== null && Option.isSome(mainStats)
1764 + ? {
1765 + key: yield* directoryIdentity(mainCheckout, mainStats.value),
1766 + path: mainCheckout,
1767 + git: gitIdentity.git,
1768 + }
1769 + : null;
1770 } else {
1737 - key = yield* directoryIdentity(resolved, stats.value);
1738 - gitIdentities.set(key, gitIdentity._tag === "Repository" ? gitIdentity.git : null);
1771 + project = {
1772 + key: yield* directoryIdentity(resolved, stats.value),
1773 + path: resolved,
1774 + git: gitIdentity._tag === "Repository" ? gitIdentity.git : null,
1775 + };
1776 }
1740 - directoryKeys.set(resolved, key);
1777 + directoryProjects.set(resolved, project);
1778 }
1742 - if (key === "") continue;
1779 + if (project === null) continue;
1780
1744 - const existing = merged.get(key);
1781 + const existing = merged.get(project.key);
1782 if (!existing) {
1746 - merged.set(key, {
1747 - path: resolved,
1783 + merged.set(project.key, {
1784 + path: project.path,
1785 sources: [candidate.source],
1786 threadCount: candidate.threadCount,
1787 lastActiveAtMs: candidate.lastActiveAtMs,
1751 - git: gitIdentities.get(key) ?? null,
1788 + git: project.git,
1789 });
1790 continue;
1791 }
docs/user/welcome-page.md
+4 -3
@@ -74,9 +74,10 @@ three conversations, already checked. Projects already in T3 Code are not checke
74 again. Uncheck the box to start without them, or
75 select **Review all** to pick from everything found, with "Select all" and
76 "Select none". Linked worktrees of bare repositories
77 -can be offered as separate projects. Other linked git worktrees, Codex scratch
78 -directories under `Documents/Codex`, and anything under `Downloads` are not
79 -offered.
77 +can be offered as separate projects. Conversations in other linked git worktrees
78 +count toward their main checkout, so a repository is offered even if you only
79 +worked in its worktrees. Codex scratch directories under `Documents/Codex`, and
80 +anything under `Downloads` are not offered.
81
82 A large or malformed history can reach the scan limit. T3 Code keeps the
83 projects it found and warns when projects or conversations may be missing.