# Fix selection loss while an agent thread is loading \(\#64252\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f8c2cc844057540ca1eac7de4f19f50d7597dead

Requested commit: f8c2cc844057540ca1eac7de4f19f50d7597dead

Commit: f8c2cc844057540ca1eac7de4f19f50d7597dead

Tree: 17ebed5243beb8d06f5ce4c2d0a48a33105b36ae

Author: Dom Porada

Committer: GitHub

## Message

````
Fix selection loss while an agent thread is loading (#64252)

## Objective

Fix the bug where selected context is lost if “Add Selection to Thread”
runs before a new agent thread finishes loading. This can leave the
message empty, particularly with slower-starting external agents such as
Claude ACP.

This addresses the [loading bug
mentioned](https://github.com/zed-industries/zed/pull/62957#issuecomment-5408347793)
in #62957.

## Solution

Preserve selected context until the destination thread’s message editor
is ready, then add it without sending the message or taking focus from
the source. This fixes the existing “Add Selection to Thread” behavior
without introducing another action.

## Testing

GPUI regression tests pass on macOS for context delivery during delayed
startup, with additional authentication, draft lifecycle, and retry
coverage.

Recommended manual check: on macOS with the default keymap, temporarily
add [this
entry](https://github.com/porada/domfiles/blob/ad86e7d0a38cd477070dec7f12a1ade4a6dce504/home/.config/zed/keymap.json#L27-L33)
to your keymap:

```json
{
  "context": "!AcpThread > (Editor && mode == full)",
  "bindings": {
    "ctrl-enter": [
      "workspace::SendKeystrokes",
      "cmd-? cmd-n cmd-? cmd->"
    ]
  }
}
```

Make sure Claude ACP is set as the default for new threads. Select code
in the editor and press `ctrl-enter`. After the thread loads, confirm
that the selected context appears in the new message and the message
remains unsent.

## Self-Review Checklist:

- [x] I’ve reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed’s UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed the bug where selected context can get lost when added before an
agent thread finishes loading.

---------

Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
````

## Parents

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

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