From b25e6c1683b581d664bd90e99b64cfd5824ecc8d Mon Sep 17 00:00:00 2001 From: Jonathan Sydorowicz Date: Wed, 11 Mar 2026 17:55:05 -0500 Subject: [PATCH 1/3] feat: default worktree directory to parent of agent's working directory The worktree config modal now pre-fills the base path with the parent directory of the agent's cwd instead of leaving it empty, so creating a new worktree no longer requires manual directory selection. --- src/renderer/components/WorktreeConfigModal.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/WorktreeConfigModal.tsx b/src/renderer/components/WorktreeConfigModal.tsx index 1325063c8d..5d35c7e1e0 100644 --- a/src/renderer/components/WorktreeConfigModal.tsx +++ b/src/renderer/components/WorktreeConfigModal.tsx @@ -49,8 +49,10 @@ export function WorktreeConfigModal({ const onCloseRef = useRef(onClose); onCloseRef.current = onClose; - // Form state - const [basePath, setBasePath] = useState(session.worktreeConfig?.basePath || ''); + // Form state — default base path to parent directory of the agent's cwd + const defaultBasePath = + session.worktreeConfig?.basePath || session.cwd.replace(/[/\\][^/\\]+$/, ''); + const [basePath, setBasePath] = useState(defaultBasePath); const [watchEnabled, setWatchEnabled] = useState(session.worktreeConfig?.watchEnabled ?? true); const [newBranchName, setNewBranchName] = useState(''); const [isCreating, setIsCreating] = useState(false); @@ -86,7 +88,7 @@ export function WorktreeConfigModal({ useEffect(() => { if (isOpen) { checkGhCli(); - setBasePath(session.worktreeConfig?.basePath || ''); + setBasePath(session.worktreeConfig?.basePath || session.cwd.replace(/[/\\][^/\\]+$/, '')); setWatchEnabled(session.worktreeConfig?.watchEnabled ?? true); setNewBranchName(''); setError(null); From 504889ff6f0637c7a9a355d10ddebf8302742ca9 Mon Sep 17 00:00:00 2001 From: Jonathan Sydorowicz Date: Wed, 11 Mar 2026 18:02:07 -0500 Subject: [PATCH 2/3] refactor: extract getParentDir helper to reduce duplicated regex logic --- src/renderer/components/WorktreeConfigModal.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/renderer/components/WorktreeConfigModal.tsx b/src/renderer/components/WorktreeConfigModal.tsx index 5d35c7e1e0..50f37622b6 100644 --- a/src/renderer/components/WorktreeConfigModal.tsx +++ b/src/renderer/components/WorktreeConfigModal.tsx @@ -15,6 +15,11 @@ interface WorktreeConfigModalProps { onDisableConfig: () => void; } +/** Get parent directory from a path (works with both / and \ separators) */ +function getParentDir(path: string): string { + return path.replace(/[/\\][^/\\]+$/, ''); +} + /** * Validates that a directory exists (works over SSH for remote sessions) */ @@ -50,9 +55,9 @@ export function WorktreeConfigModal({ onCloseRef.current = onClose; // Form state — default base path to parent directory of the agent's cwd - const defaultBasePath = - session.worktreeConfig?.basePath || session.cwd.replace(/[/\\][^/\\]+$/, ''); - const [basePath, setBasePath] = useState(defaultBasePath); + const [basePath, setBasePath] = useState( + session.worktreeConfig?.basePath || getParentDir(session.cwd) + ); const [watchEnabled, setWatchEnabled] = useState(session.worktreeConfig?.watchEnabled ?? true); const [newBranchName, setNewBranchName] = useState(''); const [isCreating, setIsCreating] = useState(false); @@ -88,7 +93,7 @@ export function WorktreeConfigModal({ useEffect(() => { if (isOpen) { checkGhCli(); - setBasePath(session.worktreeConfig?.basePath || session.cwd.replace(/[/\\][^/\\]+$/, '')); + setBasePath(session.worktreeConfig?.basePath || getParentDir(session.cwd)); setWatchEnabled(session.worktreeConfig?.watchEnabled ?? true); setNewBranchName(''); setError(null); From b952a0d8bd52b86f303474b7324e88f7ad41b99f Mon Sep 17 00:00:00 2001 From: Jonathan Sydorowicz Date: Wed, 11 Mar 2026 18:21:15 -0500 Subject: [PATCH 3/3] fix: address review feedback for worktree default directory - Guard getParentDir against root-level paths returning empty string - Fix canDisable to only enable Disable button when config is persisted - Add session.cwd to useEffect dependency array --- src/renderer/components/WorktreeConfigModal.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/WorktreeConfigModal.tsx b/src/renderer/components/WorktreeConfigModal.tsx index 50f37622b6..1b218086e1 100644 --- a/src/renderer/components/WorktreeConfigModal.tsx +++ b/src/renderer/components/WorktreeConfigModal.tsx @@ -17,7 +17,8 @@ interface WorktreeConfigModalProps { /** Get parent directory from a path (works with both / and \ separators) */ function getParentDir(path: string): string { - return path.replace(/[/\\][^/\\]+$/, ''); + const parent = path.replace(/[/\\][^/\\]+$/, ''); + return parent || path; // keep original if we're already at root } /** @@ -63,7 +64,7 @@ export function WorktreeConfigModal({ const [isCreating, setIsCreating] = useState(false); const [isValidating, setIsValidating] = useState(false); const [error, setError] = useState(null); - const canDisable = !!(session.worktreeConfig?.basePath || basePath.trim()); + const canDisable = !!session.worktreeConfig?.basePath; // gh CLI status const [ghCliStatus, setGhCliStatus] = useState(null); @@ -98,7 +99,7 @@ export function WorktreeConfigModal({ setNewBranchName(''); setError(null); } - }, [isOpen, session.worktreeConfig]); + }, [isOpen, session.worktreeConfig, session.cwd]); const checkGhCli = async () => { try {