# agent: Fix terminal_init commands race condition with PTY startup \(\#59613\) · gitcafe/zed

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

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

Visibility: public

Requested revision: a2fee92e30ebd71ed7ac4da8b7b354e252813193

Requested commit: a2fee92e30ebd71ed7ac4da8b7b354e252813193

Commit: a2fee92e30ebd71ed7ac4da8b7b354e252813193

Tree: c412c2b5512d924c1482864fcb81009c8d943f00

Author: MartinYe1234

Committer: GitHub

## Message

```
agent: Fix terminal_init commands race condition with PTY startup (#59613)

Summary:
- Add a shell-level startup handshake owned by the terminal.
- Send a split startup marker through the shell and run the configured
init command after the marker is observed, preventing local echo from
satisfying the handshake.
- Keep display-only/restored terminal behavior unchanged while
preserving startup output when shells fail or users type first.

Tests:
- `cargo test -p terminal test_init_command_startup_marker --
--nocapture`
- `cargo test -p terminal write_init_command_after_startup --
--nocapture`
- `cargo test -p agent_ui init_command -- --nocapture`
- `./script/clippy -p terminal -p agent_ui`

Closes AI-426

Release Notes:

- Fixed terminal init commands sometimes appearing or running
incorrectly when using custom shells

---------

Co-authored-by: Anant Goel <anant@zed.dev>
```

## Parents

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

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