Skip to content

Commit 0f74849

Browse files
built-by-asclaude
andcommitted
Move worktrees from .fleetcode to ~/worktrees
- Worktrees now live in ~/worktrees/<project-hash>/<session-name> - MCP config files also moved to ~/worktrees - Removed ensureFleetcodeExcluded function (no longer needed) - Uses MD5 hash of project directory to organize worktrees by project 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 26d3491 commit 0f74849

File tree

1 file changed

+16
-49
lines changed

1 file changed

+16
-49
lines changed

main.ts

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ function writeMcpConfigFile(projectDir: string, mcpServers: any): string | null
6767
const crypto = require("crypto");
6868
const hash = crypto.createHash("md5").update(projectDir).digest("hex").substring(0, 8);
6969

70-
const fleetcodeDir = path.join(projectDir, ".fleetcode");
71-
if (!fs.existsSync(fleetcodeDir)) {
72-
fs.mkdirSync(fleetcodeDir, { recursive: true });
70+
const worktreesDir = path.join(os.homedir(), "worktrees");
71+
if (!fs.existsSync(worktreesDir)) {
72+
fs.mkdirSync(worktreesDir, { recursive: true });
7373
}
7474

75-
const configFilePath = path.join(fleetcodeDir, `mcp-config-${hash}.json`);
75+
const configFilePath = path.join(worktreesDir, `mcp-config-${hash}.json`);
7676
const configContent = JSON.stringify({ mcpServers }, null, 2);
7777

7878
fs.writeFileSync(configFilePath, configContent, "utf8");
@@ -268,49 +268,19 @@ function spawnSessionPty(
268268
}
269269

270270
// Git worktree helper functions
271-
async function ensureFleetcodeExcluded(projectDir: string) {
272-
// Check if we've already initialized this project (persisted across app restarts)
273-
const initializedProjects: string[] = (store as any).get("excludeInitializedProjects", []);
274-
if (initializedProjects.includes(projectDir)) {
275-
return;
276-
}
277-
278-
const excludeFilePath = path.join(projectDir, ".git", "info", "exclude");
279-
const excludeEntry = ".fleetcode/";
280-
281-
try {
282-
// Ensure .git/info directory exists
283-
const infoDir = path.dirname(excludeFilePath);
284-
if (!fs.existsSync(infoDir)) {
285-
fs.mkdirSync(infoDir, { recursive: true });
286-
}
287-
288-
// Read existing exclude file or create empty string
289-
let excludeContent = "";
290-
if (fs.existsSync(excludeFilePath)) {
291-
excludeContent = fs.readFileSync(excludeFilePath, "utf-8");
292-
}
293-
294-
// Check if .fleetcode/ is already excluded
295-
if (!excludeContent.includes(excludeEntry)) {
296-
// Add .fleetcode/ to exclude file
297-
const newContent = excludeContent.trim() + (excludeContent.trim() ? "\n" : "") + excludeEntry + "\n";
298-
fs.writeFileSync(excludeFilePath, newContent, "utf-8");
299-
}
300-
301-
// Mark this project as initialized and persist
302-
initializedProjects.push(projectDir);
303-
(store as any).set("excludeInitializedProjects", initializedProjects);
304-
} catch (error) {
305-
console.error("Error ensuring .fleetcode excluded:", error);
306-
}
307-
}
271+
// No longer needed since worktrees are in ~/worktrees, not in project directory
308272

309273
async function createWorktree(projectDir: string, parentBranch: string, sessionNumber: number, sessionUuid: string, customBranchName?: string): Promise<{ worktreePath: string; branchName: string }> {
310274
const git = simpleGit(projectDir);
311-
const fleetcodeDir = path.join(projectDir, ".fleetcode");
275+
276+
// Create a hash of the project directory for unique worktree directory
277+
const crypto = require("crypto");
278+
const hash = crypto.createHash("md5").update(projectDir).digest("hex").substring(0, 8);
279+
280+
const worktreesBaseDir = path.join(os.homedir(), "worktrees");
281+
const projectWorktreeDir = path.join(worktreesBaseDir, hash);
312282
const worktreeName = customBranchName || `session${sessionNumber}`;
313-
const worktreePath = path.join(fleetcodeDir, worktreeName);
283+
const worktreePath = path.join(projectWorktreeDir, worktreeName);
314284

315285
// Use custom branch name if provided, otherwise generate default
316286
let branchName: string;
@@ -322,9 +292,9 @@ async function createWorktree(projectDir: string, parentBranch: string, sessionN
322292
branchName = `fleetcode/${worktreeName}-${shortUuid}`;
323293
}
324294

325-
// Create .fleetcode directory if it doesn't exist
326-
if (!fs.existsSync(fleetcodeDir)) {
327-
fs.mkdirSync(fleetcodeDir, { recursive: true });
295+
// Create worktrees directory if it doesn't exist
296+
if (!fs.existsSync(projectWorktreeDir)) {
297+
fs.mkdirSync(projectWorktreeDir, { recursive: true });
328298
}
329299

330300
// Check if worktree already exists and remove it
@@ -420,9 +390,6 @@ ipcMain.on("create-session", async (event, config: SessionConfig) => {
420390
// Generate UUID for this session (before creating worktree)
421391
const sessionUuid = uuidv4();
422392

423-
// Ensure .fleetcode is excluded (async, don't wait)
424-
ensureFleetcodeExcluded(config.projectDir);
425-
426393
// Create git worktree with custom or default branch name
427394
const { worktreePath, branchName } = await createWorktree(config.projectDir, config.parentBranch, sessionNumber, sessionUuid, config.branchName);
428395

0 commit comments

Comments
 (0)