Skip to content

feat: close window when last terminal exits (term:closeonlasttermclose)#3058

Open
apanchoo wants to merge 3 commits intowavetermdev:mainfrom
apanchoo:feat/close-on-last-terminal-exit
Open

feat: close window when last terminal exits (term:closeonlasttermclose)#3058
apanchoo wants to merge 3 commits intowavetermdev:mainfrom
apanchoo:feat/close-on-last-terminal-exit

Conversation

@apanchoo
Copy link

Closes #3026

Summary

  • Adds a new global setting term:closeonlasttermclose (boolean, default false)
  • When enabled, closing the last shell/terminal block automatically closes the window
  • No delay when triggered by this setting (unlike cmd:closeonexit which defaults to 2s)
  • Non-last terminals are unaffected

How to enable

Add to your settings.json:

{ "term:closeonlasttermclose": true }

Test plan

  • Enable the setting, open one terminal, type exit → window closes immediately
  • Enable the setting, open two terminals, type exit in one → only that block stays (no close)
  • Disable the setting → behavior unchanged (shows "shell terminated" message)

Adds a new global setting `term:closeonlasttermclose` that automatically
closes the window when the last shell/terminal block exits. When enabled,
typing `exit` in the last remaining terminal closes the window immediately
(no delay), while non-last terminals are unaffected.

Closes wavetermdev#3026

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Mar 13, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1274d1c2-92fd-4e04-a355-7c651c21c001

📥 Commits

Reviewing files that changed from the base of the PR and between 96dbd53 and 4947330.

📒 Files selected for processing (4)
  • frontend/types/gotypes.d.ts
  • pkg/wconfig/metaconsts.go
  • pkg/wconfig/settingsconfig.go
  • schema/settings.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/wconfig/settingsconfig.go
  • frontend/types/gotypes.d.ts

Walkthrough

Adds a new global configuration key term:closeonlasttermclose (schema, wconfig constant, SettingsType field, and frontend type). Introduces isLastShellBlockInWorkspace in the shell controller and updates checkCloseOnExit to consult the new global setting and workspace-level last-shell check, using a configurable default delay when deciding whether to close on exit.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature: adding a setting to close the window when the last terminal exits, matching the changeset perfectly.
Description check ✅ Passed The description is well-related to the changeset, explaining the new setting, its behavior, and how to enable it with a test plan.
Linked Issues check ✅ Passed The PR implementation addresses issue #3026 by adding a new configurable setting (term:closeonlasttermclose) that allows the window to close when the last terminal exits, resolving the reported Linux behavior issue.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the term:closeonlasttermclose feature: type definitions, configuration constants, settings struct, schema, and shell controller logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 13, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The inline issue previously identified (fail-closed error handling in isLastShellBlockInWorkspace) has been addressed in a subsequent commit. The code now correctly returns false on database read errors rather than continuing, which ensures the last-shell detection is conservative.

Files Reviewed (5 files)
  • frontend/types/gotypes.d.ts - TypeScript type for new setting
  • pkg/blockcontroller/shellcontroller.go - Main implementation with isLastShellBlockInWorkspace() function and modified checkCloseOnExit() logic
  • pkg/wconfig/metaconsts.go - Config key constant
  • pkg/wconfig/settingsconfig.go - Settings struct field
  • schema/settings.json - JSON schema

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/blockcontroller/shellcontroller.go`:
- Around line 665-673: The DB reads in the last-shell detection loop currently
ignore errors by continuing (wstore.DBGet[*waveobj.Tab](ctx, wsTabId) and
wstore.DBGet[*waveobj.Block](ctx, wsBlockId)); change this to fail closed by
returning false when either DBGet returns a non-nil error (or nil result with an
error), instead of continuing, so any read error makes the function
conservatively return false; update the logic around the tab/block retrieval and
the loop over tab.BlockIds accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ccf9be1b-d0c4-4408-a949-2a0d917f18f6

📥 Commits

Reviewing files that changed from the base of the PR and between 4034526 and e9750be.

📒 Files selected for processing (5)
  • frontend/types/gotypes.d.ts
  • pkg/blockcontroller/shellcontroller.go
  • pkg/wconfig/metaconsts.go
  • pkg/wconfig/settingsconfig.go
  • schema/settings.json

apanchoo and others added 2 commits March 13, 2026 21:40
Fail closed on DB errors instead of skipping blocks with continue,
which could undercount shell blocks and incorrectly trigger window close.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: App doesn't close on terminal exit

2 participants