@@ -7,6 +7,7 @@ import path from 'path';
77import { fileURLToPath } from 'url' ;
88import { render } from 'ink' ;
99import React from 'react' ;
10+ import { createHash } from 'crypto' ;
1011import DmuxApp from './DmuxApp.js' ;
1112
1213const __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
7499const dmux = new Dmux ( ) ;
0 commit comments