Skip to content

feat(desktop): add a default directory setting for new terminals - #76785

Draft
lukebaber-posthog wants to merge 1 commit into
masterfrom
posthog-code/default-terminal-directory
Draft

feat(desktop): add a default directory setting for new terminals#76785
lukebaber-posthog wants to merge 1 commit into
masterfrom
posthog-code/default-terminal-directory

Conversation

@lukebaber-posthog

Copy link
Copy Markdown
Contributor

Problem

New terminals in the desktop app pick their working directory implicitly. With one registered project folder that folder gets used, with several you get a folder prompt every time, and with none it falls back to your home directory. There is no way to pin a directory, and it has to be a registered project folder, so a plain notes or scratch directory cannot be the default at all.

Changes

Settings > Terminal now has a Default directory row: a native directory picker that accepts any path, not just a registered project folder. Once set, new terminals open there with no prompt. A "Terminal in..." entry stays in the new-terminal footer for one-off overrides, so folder choice is not lost. When the setting is empty, behaviour is exactly what it is today.

ShellService.resolveWorkingDir now expands a leading ~ before its existsSync check. A tilde path previously failed that check and was silently swapped for the home directory, which also quietly affected the cwd="~" used by the CLI onboarding step.

The preference lives in the existing persisted settingsStore next to the other terminal settings, so there is no new tRPC procedure or host-side store. The row is hidden on hosts without local workspaces, since there is no local pty there.

No screenshots: I was not able to run the Electron app in this environment. See below for what that leaves unverified.

How did you test this code?

Automated only, all run by me (Claude) in this repo after porting the change:

Check Result
packages/ui settingsStore.test.ts 43 passed
packages/ui command-center (incl. TaskSelector.test.tsx) 37 passed
packages/workspace-server shell.test.ts 14 passed
biome check, 8 touched files clean
packages/ui typecheck 76 errors, identical count to the unmodified tree (unbuilt @posthog/agent dist in my sandbox), none in touched files

New test groups, and the regression each one catches that no existing test did:

  • settingsStore.test.ts > "terminal default directory": the setting silently failing to persist. Adding a field to the store but omitting it from partialize still type-checks and still passes every other test, and the value is then lost on restart.
  • shell.test.ts > "createSession working directory": a tilde path being discarded in favour of the home directory, which is the exact bug fixed here, plus the empty, missing and undefined cwd fallbacks that nothing pinned before.
  • TaskSelector.test.tsx > two new cases: the default being ignored so the folder prompt still appears, and the "Terminal in..." escape hatch vanishing once a default is set. The two existing cases in that file only cover popup width.

Note

Not verified: I did not drive the running app, so the directory picker dialog and the new-terminal footer layout are unexercised. That footer can now show up to four buttons (New task, Terminal, Terminal in..., Brainrot) and may want a width check before this leaves draft.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Luke asked for new terminals to always open in a directory of his choosing. I (Claude, via PostHog Code) wrote all of the code here. No skills invoked.

This began as PostHog/code#3890. That repo froze on 1 August behind the monorepo migration, and a repo-wide ruleset now blocks every ref update there, so the finished branch could not be pushed. I rebased it onto products/desktop here instead. terminalDefaultCwd did not exist in the monorepo yet, so nothing is duplicated.

Decisions worth a reviewer's eye:

  • Did not reuse FolderPicker. Its "Open folder..." path calls addFolder(), which registers the directory as a project repository. A default terminal directory should be able to be any directory, so this calls os.selectDirectory directly, matching "Default folders for new chats" in WorkspacesSettings.
  • Kept the "Terminal in..." escape hatch rather than removing folder choice, so a pinned default does not make one-off terminals elsewhere impossible.
  • Analytics records set versus unset rather than the path, since a local filesystem path is user data. Same reasoning as terminal_custom_font_family.

Only TaskSelector.tsx had moved on in the monorepo (#76570 swapped a utility class for an inline style). No overlap with my hunks, and both changes coexist. Its TaskSelector.test.tsx is new here and had no counterpart in the old repo, which is where the two component tests went.

New standalone terminals inferred their working directory. One registered
folder was used automatically, several meant a folder prompt every time, and
nothing registered fell back to the home directory. There was no way to pin a
directory, and it had to be a registered project folder at all.

Adds Settings > Terminal > Default directory, a native directory picker that
accepts any path. Once set, new terminals open there with no prompt, and a
"Terminal in..." entry stays available to pick a different directory for
one-offs. Behaviour is unchanged when the setting is empty.

Also expands a leading "~" in ShellService.resolveWorkingDir before the
existsSync check, so tilde paths are no longer silently discarded for home.

Generated-By: PostHog Code
Task-Id: 0f581bf1-c527-4e0c-9e73-eee5559a508f
@lukebaber-posthog lukebaber-posthog self-assigned this Aug 3, 2026
@trunk-io

trunk-io Bot commented Aug 3, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions github-actions Bot added the feature/desktop Feature Tag: Desktop label Aug 3, 2026
@trunk-io

trunk-io Bot commented Aug 3, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/desktop Feature Tag: Desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant