Skip to content

Commit 41983a5

Browse files
authored
feat: symlink claude config to user workspaces (#687)
1 parent 6406b75 commit 41983a5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/agent/src/worktree-manager.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ export class WorktreeManager {
269269
}
270270
const gitTime = Date.now() - gitStart;
271271

272+
await this.symlinkClaudeConfig(worktreePath);
273+
272274
const createdAt = new Date().toISOString();
273275

274276
this.logger.info("Worktree created successfully", {
@@ -357,6 +359,8 @@ export class WorktreeManager {
357359
}
358360
const gitTime = Date.now() - gitStart;
359361

362+
await this.symlinkClaudeConfig(worktreePath);
363+
360364
const createdAt = new Date().toISOString();
361365

362366
this.logger.info("Worktree for existing branch created successfully", {
@@ -492,6 +496,32 @@ export class WorktreeManager {
492496
}
493497
}
494498

499+
private async symlinkClaudeConfig(worktreePath: string): Promise<void> {
500+
const sourceClaudeDir = path.join(this.mainRepoPath, ".claude");
501+
const targetClaudeDir = path.join(worktreePath, ".claude");
502+
503+
try {
504+
await fs.access(sourceClaudeDir);
505+
} catch {
506+
this.logger.debug("No .claude directory in main repo to symlink");
507+
return;
508+
}
509+
510+
try {
511+
await fs.symlink(sourceClaudeDir, targetClaudeDir, "dir");
512+
this.logger.info("Symlinked .claude config to worktree", {
513+
source: sourceClaudeDir,
514+
target: targetClaudeDir,
515+
});
516+
} catch (error) {
517+
if ((error as NodeJS.ErrnoException).code === "EEXIST") {
518+
this.logger.debug(".claude symlink already exists in worktree");
519+
} else {
520+
this.logger.warn("Failed to symlink .claude config", { error });
521+
}
522+
}
523+
}
524+
495525
private parseWorktreeList(output: string): WorktreeInfo[] {
496526
const worktrees: WorktreeInfo[] = [];
497527
const entries = output.split("\n\n").filter((e) => e.trim());

0 commit comments

Comments
 (0)