# agent_ui: Fix agent terminal close behavior with keyboard shortcuts \(\#58217\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/104ccf4bb6eace1b7b01a9929c301f362f0c67f9)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 104ccf4bb6eace1b7b01a9929c301f362f0c67f9

Requested commit: 104ccf4bb6eace1b7b01a9929c301f362f0c67f9

Commit: 104ccf4bb6eace1b7b01a9929c301f362f0c67f9

Tree: 84fa0ee991699e58f6bf398234ba08aedd01857d

Author: Hugh L

Committer: GitHub

## Message

```
agent_ui: Fix agent terminal close behavior with keyboard shortcuts (#58217)

Self-Review Checklist:

- [ *] I've reviewed my own diff for quality, security, and reliability
- [ *] Unsafe blocks (if any) have justifying comments
- [ *] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ *] Tests cover the new/changed behavior
- [ *] Performance impact has been considered and is acceptable

What:
  - Closing the active terminal from the sidebar activated the remaining
terminal.But closing a terminal with Ctrl-D could leave the agent panel
in an
uninitialized `Zed Agent` state instead of activating the remaining
terminal.
<img width="804" height="380" alt="image"
src="https://github.com/user-attachments/assets/eaa67c6e-7f3d-4a1c-b72d-9cabfaab872b"
/>

How:
  - Terminal exits emit `TerminalCloseRequested`.
- The sidebar handles that request through the same close path used by
the
  sidebar close button.
- Neighbor activation, draft fallback, metadata cleanup, and
linked-worktree/
  archive handling stay centralized in the sidebar close flow.

Added test coverage for closing an active terminal via terminal exit and
  activating the remaining terminal neighbor.

Testing:
  - `cargo check -p agent_ui`
  - `cargo check -p sidebar`
  - Manually verified Ctrl-D terminal close behavior with multiple agent
  threads/terminals

Release Notes:

- Fixed closing an agent terminal with Ctrl-D leaving the agent panel
  uninitialized instead of activating the remaining terminal
```

## Parents

- [9a5344b9eb49d4734b00bce786d4bf0c5f70f3a0](https://git.cafe/gitcafe/zed/commit/9a5344b9eb49d4734b00bce786d4bf0c5f70f3a0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/104ccf4bb6eace1b7b01a9929c301f362f0c67f9?format=markdown)
