Skip to content

Keep Ghostty terminals in the active working directory - #8033

Open
sebishogun wants to merge 10 commits into
omacom:quattrofrom
sebishogun:fix/ghostty-cwd
Open

sebishogun wants to merge 10 commits into
omacom:quattrofrom
sebishogun:fix/ghostty-cwd

Conversation

@sebishogun

@sebishogun sebishogun commented Aug 24, 2026 •

Copy link
Copy Markdown

Keep Ghostty terminals in the active working directory

Problem

Super+Enter launches the selected terminal with the directory returned by omarchy-cmd-terminal-cwd. Ghostty's packaged desktop entry forces --gtk-single-instance=true, so all top-level windows share one process and Hyprland reports the same PID for each of them. Omarchy can then select a shell belonging to a different window, and Ghostty's single-instance activation also drops the --working-directory argument for a plain new window.

The result is that a new Ghostty window can open in another terminal's directory instead of the active terminal's directory.

Context

Working-directory inheritance predates Ghostty. It was introduced in 2cca0269 while Alacritty was the shipped default, before Omarchy moved terminal launching to xdg-terminal-exec in 4c97a31c and later made Ghostty the default in b6ba588f.

The reported setup previously used Kitty as its selected default terminal, where this behavior worked because current Omarchy can query Kitty's focused window through the per-window remote-control socket. Ghostty's packaged desktop entry changes the process model underneath the same Omarchy feature by forcing all top-level windows into one process.

Reproduction on the affected machine

  1. Select Ghostty as the Omarchy default terminal.
  2. Open two independent Ghostty windows and change each shell to a different directory.
  3. Focus the first window and press Super+Enter.
  4. Observe that the new window can inherit the other Ghostty window's directory instead of the focused window's directory.

On this machine, the packaged /usr/share/applications/com.mitchellh.ghostty.desktop launched both actions with --gtk-single-instance=true and enabled D-Bus activation. The independent windows therefore shared one Ghostty PID. omarchy-cmd-terminal-cwd starts from the PID reported by hyprctl activewindow and selects a child shell, so that shared PID did not uniquely identify the focused window's shell.

The local fix was to set gtk-single-instance = false, install a user desktop entry with bare Ghostty Exec lines and no D-Bus activation, and remove the xdg-terminal-exec cache. After opening new top-level Ghostty windows, Super+Enter inherited the focused window's directory again. This patch makes that repair the Omarchy default and applies it to existing users through an idempotent migration.

Affected machine (original report)

Component Details
System Framework Desktop (AMD Ryzen AI Max 300 Series), revision A6
CPU AMD Ryzen AI Max+ 395
GPU AMD Strix Halo Radeon 8060S
Kernel Linux 7.1.8-arch1-3 x86_64
Omarchy omarchy-dev 4.0.0.r1791.ged7bae4-1
Hyprland 0.56.2-1
Ghostty 1.3.1-2
xdg-terminal-exec 0.14.2-1
uwsm 0.26.6-1

Fix

  • Default Ghostty to gtk-single-instance = false, giving independently launched top-level windows distinct processes that Omarchy can map to their shells.
  • Ship an Omarchy Ghostty desktop entry outside the globally refreshed application set, without the packaged --gtk-single-instance=true override and with DBusActivatable=false, so the user configuration controls the process model.
  • Install that desktop entry during fresh provisioning, direct installation, or default-terminal selection, without replacing an existing user desktop override.
  • Invalidate the xdg-terminal-exec cache after a successful terminal selection or installation so the next launch resolves the selected entry immediately.
  • Migrate existing Ghostty users across both the legacy config and current config.ghostty paths while preserving an explicit gtk-single-instance setting and any existing desktop override.

Tradeoff

Each independently launched Ghostty window now starts a GTK process, which uses more memory and has more startup overhead than sharing one process. This is required for Omarchy's current PID-based working-directory detection.

Ghostty tabs and splits still share their window's process. Omarchy cannot reliably distinguish their focused shell until Ghostty exposes focused-surface process or working-directory information through IPC.

Compatibility with other Ghostty PRs

This fix preserves existing user desktop entries and explicit gtk-single-instance settings, including a deliberate opt-in to single-instance mode.

The following PRs remain open as of 2026-11-16:

Tests

Updated against quattro at fad23cf8 on 2026-11-16. Focused validation on the updated branch:

  • bash test/shell.d/default-apps-test.sh: 30 checks passed. Ghostty selection, direct installation, and application refresh install missing desktop entries, preserve existing entries and dangling symlinks, and invalidate the terminal cache where applicable. Refresh coverage is in this existing suite alongside the installation and selection coverage.
  • bash test/shell.d/terminal-cwd-test.sh: 6 checks passed.
  • ./test/cli: passed.
  • desktop-file-validate default/ghostty/com.mitchellh.ghostty.desktop: passed.
  • Bash syntax validation for the changed commands, migration, and default-apps tests, plus git diff --check: passed.

The full shell suite was not rerun for this update. The latest full-suite report records five failures that also reproduce on quattro; the focused passes above do not establish a green full suite. That report also documents a live reproduction and successful fix with Ghostty 1.4.0-1 on a disposable worker.

Fixes #3963

Related to #5447 and #6567

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures new Ghostty windows inherit the active terminal’s working directory by avoiding shared-process launches.

Changes:

  • Disables Ghostty single-instance mode and provides an Omarchy desktop entry.
  • Updates selection, installation, refresh, and migration flows.
  • Adds integration and migration coverage.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
config/ghostty/config Disables single-instance mode.
default/ghostty/com.mitchellh.ghostty.desktop Adds the multi-process desktop entry.
bin/omarchy-default-terminal Installs the entry and clears terminal cache.
bin/omarchy-install-terminal Integrates the entry during installation.
bin/omarchy-refresh-applications Restores a missing Ghostty entry.
migrations/1787566169.sh Migrates existing Ghostty users safely.
test/shell.d/default-apps-test.sh Tests selection and installation flows.
test/shell.d/ghostty-cwd-test.sh Tests configuration and desktop contracts.
test/shell.d/ghostty-cwd-migration-test.sh Tests migration behavior and idempotency.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

migrations/1787566169.sh:10

  • This migration only recognizes Ghostty's legacy ~/.config/ghostty/config path. Ghostty 1.3.1 also uses ~/.config/ghostty/config.ghostty as its primary config path (while still loading the legacy file), so an existing user with only the current-format config is treated as a non-user: the migration exits before installing the desktop override, and the packaged --gtk-single-instance=true behavior remains. Collect both existing config paths, preserve an explicit setting found in either, and append the default to the later-loaded current-format file when present.
ghostty_config="$HOME/.config/ghostty/config"
ghostty_desktop="$HOME/.local/share/applications/com.mitchellh.ghostty.desktop"

[[ -f $ghostty_config ]] || exit 0

@sebishogun

Copy link
Copy Markdown
Author

Addressed Copilot's suppressed config.ghostty finding in abe29cf1.

Ghostty 1.3.1 loads both XDG config filenames in this order:

  1. legacy ~/.config/ghostty/config;
  2. current ~/.config/ghostty/config.ghostty.

The migration now collects both existing files in that order, preserves an explicit gtk-single-instance assignment found in either file, and appends the Omarchy default to the later-loaded config.ghostty file when it exists. Current-format-only users now also receive the desktop override and cache invalidation.

Coverage now includes current-format-only users, both-file precedence, explicit settings in either file, idempotence, and users with no Ghostty config. The focused tests and all 192 shell test files pass.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 9 changed files in this pull request and generated 1 comment.

Comment thread migrations/1787566169.sh Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

migrations/1787566169.sh:16

  • Ghostty 1.3.1 does not load these files in sequence: it uses the first non-empty config.ghostty, otherwise the first non-empty legacy config. Grepping both files can therefore let a setting in the ignored legacy file suppress the required setting in the active current file. Worse, when config.ghostty exists but is empty, appending here makes it active and causes Ghostty to stop loading the user's non-empty legacy configuration. Select the same single non-empty file Ghostty selects, then inspect and update only that file.
if ! grep -Eq '^[[:space:]]*gtk-single-instance[[:space:]]*=' "${ghostty_configs[@]}"; then
  printf '\ngtk-single-instance = false\n' >>"${ghostty_configs[-1]}"

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 4dfcbdd and reproduced on a disposable Omarchy worker (Hyprland 0.56.2, Ghostty 1.3.1-2 installed on top, Ghostty set as the default terminal). Two Ghostty windows sat in /tmp/cwd-a and /tmp/cwd-b, and a foot window in /tmp/cwd-c. Each window was focused in turn, then omarchy-launch-terminal ran, as Super+Enter does.

On quattro both Ghostty windows share one process. With window A focused, omarchy-cmd-terminal-cwd returns B's directory, which is #3963 exactly. Ghostty still opens a new window from a focused Ghostty window in the right place, because single-instance mode drops --working-directory and inherits from the focused surface instead. It goes wrong everywhere else. A Ghostty window launched from the foot window opened in /tmp/cwd-b instead of /tmp/cwd-c, and anything else that reads omarchy-cmd-terminal-cwd, such as omarchy-launch-nautilus-cwd, gets the wrong directory. After the migration in this PR, each window has its own process and all three launches land in the right directory. Removing the desktop entry and the config line brings the failure back. The desktop entry alone fixes the xdg-terminal-exec path. The gtk-single-instance = false line is what keeps a Ghostty started with no arguments, from an app launcher, out of single-instance mode under Ghostty's detect default.

./test/cli passes on the worker, and so do ghostty-cwd-test.sh (5), ghostty-cwd-migration-test.sh (7) and default-apps-test.sh (15). In the full shell suite, 2444 tests pass and 1 fails: branding-about-animation-test.sh, which fails the same way on quattro without this change.

Codex Medium reviewed it separately. It agreed that the problem is real and that the desktop entry is the essential part, though its independence is not guaranteed. It also pointed out something the tests miss: config/ reaches every user through /etc/skel, so every user has ~/.config/ghostty/config. The migration therefore also runs for people who only use foot. For them it appends an unused line to their Ghostty config, installs a desktop entry that TryExec hides while Ghostty is absent, and clears the xdg-terminal-exec cache. Nothing visible changes for them, so no change was pushed. omarchy-cmd-present ghostty || exit 0 near the top of the migration would limit it to people who have Ghostty, if that is preferred. Tabs and splits inside one window still share a process, as the description says.

This now waits on the maintainer. Separate processes per window cost memory and startup time in exchange for correct directories and crash isolation, which is also what #5447 and #6567 ask for. Owning a copy of Ghostty's desktop entry means later upstream changes to it will not reach users without another migration.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
quattro moved omarchy-default-terminal's notification to omarchy-i18n; keep that alongside this branch's xdg-terminal-exec cache invalidation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro had moved far enough that this no longer merged, so I pushed 1ff1028, a merge of quattro (84cfb93) into fix/ghostty-cwd. The only conflict was in bin/omarchy-default-terminal, where quattro moved the closing notification to omarchy-i18n default.terminalSet. The resolution keeps that and keeps this branch's xdg-terminal-exec cache removal just above it. Nothing else in the branch changed.

I reproduced it again at 1ff1028 on a disposable Omarchy worker with Ghostty 1.3.1-2, using the same setup as before: two Ghostty windows opened the way Super+Enter opens them, in /tmp/cwd-a and /tmp/cwd-b, plus a foot window in /tmp/cwd-c. On quattro both Ghostty windows share one process, so omarchy-cmd-terminal-cwd gives B's directory for window A, and omarchy-launch-terminal --pid from the foot window opens Ghostty in /tmp/cwd-b. On this branch, after the migration, each window has its own process and all four checks land in the right directory. Removing the desktop entry and the gtk-single-instance line brings the failure back. The launcher changes that landed on quattro since the last review, --pid from Lua and reading /proc child lists, still map a window to its shell through the process, so this fix is still needed.

./test/cli passes on the worker, and so do ghostty-cwd-test.sh (5), ghostty-cwd-migration-test.sh (7), default-apps-test.sh (17) and terminal-cwd-test.sh (3). The full shell suite has 10 failures, in files such as ascii-test.sh, battery-status-test.sh, launch-browser-test.sh and sleep-lock-test.sh, none of which this branch touches. All 10 fail the same way on quattro, so they belong to the worker image rather than this change. They still keep the suite from being green.

Codex Medium reviewed the merged head separately and found no defects. It agreed the resolution is correct, the migration's older timestamp is harmless because omarchy-migrate runs every pending file, and the fix is proportionate, though its independence is not guaranteed.

This waits on the maintainer. The trade-offs from the previous comment still stand: one process per window, a copy of Ghostty's desktop entry to maintain, and the migration running for foot-only users.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 18, 2026
quattro dropped the mise.sh call from omarchy-refresh-applications (omacom#9596); keep that removal and the Ghostty desktop entry copy this branch adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro had moved again and this no longer merged, so I pushed f353065, a merge of quattro (da2db1a) into fix/ghostty-cwd. The only conflict was in bin/omarchy-refresh-applications, where #9596 on quattro removed the call to install/user/mise.sh. The resolution keeps that removal and keeps this branch's Ghostty desktop entry copy. Nothing else in the branch changed.

I reproduced it again at f353065 on a disposable Omarchy worker with Ghostty 1.3.1-3, using the same setup as before: two Ghostty windows in /tmp/cwd-a and /tmp/cwd-b, plus a foot window in /tmp/cwd-c. On quattro both Ghostty windows share one process. omarchy-cmd-terminal-cwd gives each window the other one's directory, and omarchy-launch-terminal from the foot window opens Ghostty in /tmp/cwd-b. On this branch, after the migration, each window has its own process and every check lands in the right directory. Removing the desktop entry and the gtk-single-instance line brings the failure back.

./test/cli passes on the worker, and so do ghostty-cwd-test.sh (5), ghostty-cwd-migration-test.sh (7), default-apps-test.sh (17) and terminal-cwd-test.sh (3). The full shell suite has 6 failures that fail the same way on quattro, in files this branch does not touch. One more check, in privileged-heredoc-test.sh, failed once inside the full run and passed when that file was rerun alone, on both this branch and quattro. The suite is still not green, so this is not marked ready.

Codex Medium reviewed the merged head separately and found no defects. It agreed that the resolution is correct and loses nothing from either side, that the fix is proportionate, and that the older migration timestamp is harmless because omarchy-migrate runs every file that has no completion marker. Its independence is not guaranteed.

This PR collides with #15780, opened today for #15779, where Ghostty does not launch from the app menu. Both PRs install ~/.local/share/applications/com.mitchellh.ghostty.desktop with DBusActivatable=false, but #15780 copies the packaged entry, which launches Ghostty with --gtk-single-instance=true (the worker's Ghostty processes on quattro show that flag). If #15780 lands first, this branch's migration and omarchy-refresh-applications see that the file already exists and leave it alone. The command-line flag then overrides gtk-single-instance = false in the config, and the bug comes back. If this branch lands first, #15780's migration finds the override and only rewrites a line that is already false, so the two work together. I did not check whether this branch also fixes #15779.

This waits on the maintainer: whether to take it, given the trade-offs from the earlier comments (one process per window, a copy of Ghostty's desktop entry to maintain, a migration that also runs for foot-only users), and how to order it against #15780.

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

Ghostty launches now use separate processes by default so Omarchy can find the active window’s working directory.

  • Ghostty opens new top-level windows in the active terminal’s directory.

No new actionable issues were found. This review inspected the code; it did not rerun tests.

Reviews (3) · Last reviewed commit: "Consolidate Ghostty desktop entry tests" · Reviewed by Greptile

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
omarchybot and others added 2 commits November 16, 2026 19:24
The only conflict was in the default-apps test's package stub, where quattro added plain beside this branch's ghostty; both stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Omarchy's AGENTS.md rules out a test for a migration, since it runs once and is frozen once it ships, and a test that greps the config or the desktop entry for the line just added. What stays tests the guards in the bin/ commands that install the desktop entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro had moved and this no longer merged, so I pushed two commits to fix/ghostty-cwd. 416dc0f merges quattro (dceae18). The only conflict was the package stub in test/shell.d/default-apps-test.sh, where quattro added plain next to this branch's ghostty. Both stay. f61fbf0 removes test/shell.d/ghostty-cwd-migration-test.sh and the checks in ghostty-cwd-test.sh that grep the config and the desktop entry for the lines this PR adds. Omarchy's AGENTS.md rules out both, a test for a migration and a test that greps for the string just added. The tests that stay exercise the guards in omarchy-default-terminal, omarchy-install-terminal and omarchy-refresh-applications. @sebishogun, the PR description's Tests section still lists the migration tests.

I reproduced it again at f61fbf0 on a disposable Omarchy worker, now with Ghostty 1.4.0-1, using two Ghostty windows in /tmp/cwd-a and /tmp/cwd-b and a foot window in /tmp/cwd-c. On quattro, both Ghostty windows share one process and omarchy-cmd-terminal-cwd gives each window the other one's directory. omarchy-launch-terminal from the foot window opens Ghostty in /tmp/cwd-b. After this branch's migration, which changes nothing when run a second time, each window has its own process and every lookup and launch lands in the right directory. Removing the desktop entry and the gtk-single-instance line brings the failure back.

./test/cli passes on the worker, and so do ghostty-cwd-test.sh (3), default-apps-test.sh (27) and terminal-cwd-test.sh (6). The full shell suite has 5 failures, the same 5 on quattro, all in files this branch does not touch. The suite is not green.

Codex Medium and muse-wonder (via pi, thinking high) reviewed f61fbf0 separately. Neither found a defect in the merge, the code as it stands on today's quattro, or the test trim. Both agreed the problem is real and the fix is proportionate. Their independence is not guaranteed.

Both reviewers also named an interaction to settle before any of these land. #9917 and #17257 each make omarchy-launch-terminal start Ghostty directly with --gtk-single-instance=true. A command-line flag overrides gtk-single-instance = false in the config, so either one landing after this would put Super+Enter's windows back in one process and bring the bug back. They would need to drop that flag. #15780 installs the same ~/.local/share/applications/com.mitchellh.ghostty.desktop, copied from Ghostty's packaged entry, which keeps the flag. If it lands first, this branch leaves that file alone and the bug stays. That is what the earlier comment here described.

This waits on the maintainer: whether to give up Ghostty's single-instance mode for one process per window, which means a copy of Ghostty's desktop entry to maintain, and how to order this against #15780, #9917 and #17257.

Comment thread test/shell.d/ghostty-cwd-test.sh Resolved
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @sebishogun. 660923e moves the omarchy-refresh-applications checks into test/shell.d/default-apps-test.sh and drops ghostty-cwd-test.sh, which settles greptile's note about the split suite. The fix itself (the three bin/ commands, the config line, the desktop entry and the migration) is byte-for-byte what was verified at f61fbf0, so I checked this head again rather than taking the earlier result on trust.

On a fresh disposable Omarchy worker with Ghostty 1.4.0-1, installed by quattro's own omarchy-install-terminal, quattro (9f09d60) still fails: both Ghostty windows share one process, omarchy-cmd-terminal-cwd gives each window the other one's directory, and Ghostty opened from a foot window in /tmp/cwd-c lands in /tmp/cwd-b. At 660923e, after the migration (which changes nothing when run a second time), each window has its own process and every lookup and launch lands in the focused window's directory. Removing the desktop entry and the gtk-single-instance line brings the failure back.

./test/cli passes on the worker, and so do default-apps-test.sh (30) and terminal-cwd-test.sh (6). The desktop entry passes desktop-file-validate. The full shell suite has 5 failures at this head. quattro fails the same 5, plus one more, all in files this branch does not touch, so the suite is still not green.

Codex Medium and muse-wonder (via pi, thinking high) reviewed this head. Neither found a defect. Both found the moved tests correctly scoped to the test home and checkout, and found that between them the three checks pin the existing-file-or-symlink guard. Both agreed the problem is real and the change is proportionate. Their independence is not guaranteed. muse-wonder suggested the refresh run now makes the later "picking an editor installs the editor handler" check unable to fail. That check could not fail on quattro either, because omarchy-default-editor always runs omarchy-cmd-editor-mimetypes, which installs the handler, and the editor tests before it already do that. So this branch changes nothing there.

Nothing else has changed since the last comment. This still waits on the maintainer: whether to give up Ghostty's single-instance mode for one process per window, which means keeping a copy of Ghostty's desktop entry, and how to order this against #15780, #9917 and #17257, which would each undo it as they stand.

@sebishogun

Copy link
Copy Markdown
Author

@dhh, this PR has been open since August 24 and has gone through several rounds of review by Copilot, Greptile, and Omarchybot’s Codex and muse-wonder reviewers. The latest commit has no outstanding actionable review findings, and Omarchybot has reverified both the bug and the fix on a fresh worker.

Could you weigh in on the remaining maintainer decision: whether separate Ghostty processes per window are an acceptable tradeoff for correct working-directory detection, and how this should coordinate with #15780, #9917 and #17257? Happy to make further changes if needed.

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

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-cmd-terminal-cwd returns wrong directory with multiple Ghostty windows

3 participants