Skip to content

Commit fd130b0

Browse files
fix: project isolation
1 parent 256ba30 commit fd130b0

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"deny": [],
1919
"ask": [],
2020
"additionalDirectories": [
21-
"/Users/justinschroeder/Projects/dmux/main"
21+
"/Users/justinschroeder/Projects/dmux/main",
22+
"/Users/justinschroeder/.dmux"
2223
]
2324
}
2425
}

src/DmuxApp.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DmuxAppProps {
1919
panesFile: string;
2020
projectName: string;
2121
sessionName: string;
22+
projectRoot?: string;
2223
}
2324

2425
const DmuxApp: React.FC<DmuxAppProps> = ({ dmuxDir, panesFile, projectName, sessionName }) => {
@@ -172,11 +173,20 @@ const DmuxApp: React.FC<DmuxAppProps> = ({ dmuxDir, panesFile, projectName, sess
172173

173174
setStatusMessage('Creating new pane...');
174175

175-
// Get current directory
176-
const currentDir = process.cwd();
176+
// Get git root directory for consistent worktree placement
177+
let projectRoot: string;
178+
try {
179+
projectRoot = execSync('git rev-parse --show-toplevel', {
180+
encoding: 'utf-8',
181+
stdio: 'pipe'
182+
}).trim();
183+
} catch {
184+
// Fallback to current directory if not in a git repo
185+
projectRoot = process.cwd();
186+
}
177187

178-
// Create worktree path
179-
const worktreePath = path.join(currentDir, '..', `${path.basename(currentDir)}-${slug}`);
188+
// Create worktree path relative to project root
189+
const worktreePath = path.join(path.dirname(projectRoot), `${path.basename(projectRoot)}-${slug}`);
180190

181191
// Get the original pane ID (where dmux is running) before clearing
182192
const originalPaneId = execSync('tmux display-message -p "#{pane_id}"', { encoding: 'utf-8' }).trim();

src/index.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path';
77
import { fileURLToPath } from 'url';
88
import { render } from 'ink';
99
import React from 'react';
10+
import { createHash } from 'crypto';
1011
import DmuxApp from './DmuxApp.js';
1112

1213
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -16,15 +17,24 @@ class Dmux {
1617
private panesFile: string;
1718
private projectName: string;
1819
private sessionName: string;
20+
private projectRoot: string;
1921

2022
constructor() {
2123
this.dmuxDir = path.join(process.env.HOME!, '.dmux');
22-
// Get project name from current directory
23-
this.projectName = path.basename(process.cwd());
24+
// Get git root directory to determine project scope
25+
this.projectRoot = this.getProjectRoot();
26+
// Get project name from git root directory
27+
this.projectName = path.basename(this.projectRoot);
28+
29+
// Create a unique identifier for this project based on its full path
30+
// This ensures different projects with the same folder name are kept separate
31+
const projectHash = createHash('md5').update(this.projectRoot).digest('hex').substring(0, 8);
32+
const projectIdentifier = `${this.projectName}-${projectHash}`;
33+
2434
// Create unique session name for this project
25-
this.sessionName = `dmux-${this.projectName}`;
26-
// Store panes per project
27-
this.panesFile = path.join(this.dmuxDir, `${this.projectName}-panes.json`);
35+
this.sessionName = `dmux-${projectIdentifier}`;
36+
// Store panes per project using the unique identifier
37+
this.panesFile = path.join(this.dmuxDir, `${projectIdentifier}-panes.json`);
2838
}
2939

3040
async init() {
@@ -57,7 +67,8 @@ class Dmux {
5767
dmuxDir: this.dmuxDir,
5868
panesFile: this.panesFile,
5969
projectName: this.projectName,
60-
sessionName: this.sessionName
70+
sessionName: this.sessionName,
71+
projectRoot: this.projectRoot
6172
}));
6273
}
6374

@@ -69,6 +80,20 @@ class Dmux {
6980
return false;
7081
}
7182
}
83+
84+
private getProjectRoot(): string {
85+
try {
86+
// Try to get git root directory
87+
const gitRoot = execSync('git rev-parse --show-toplevel', {
88+
encoding: 'utf-8',
89+
stdio: 'pipe'
90+
}).trim();
91+
return gitRoot;
92+
} catch {
93+
// Fallback to current directory if not in a git repo
94+
return process.cwd();
95+
}
96+
}
7297
}
7398

7499
const dmux = new Dmux();

0 commit comments

Comments
 (0)