# acp_thread: Shrink ACP terminal scrollback to used on exit \(\#60019\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 7ed553b391393ee4e62782e710605778e2200a18

Requested commit: 7ed553b391393ee4e62782e710605778e2200a18

Commit: 7ed553b391393ee4e62782e710605778e2200a18

Tree: c695aa39023db43fa67378a7ae2b8bf8612a4da2

Author: Maja Backman

Committer: GitHub

## Message

```
acp_thread: Shrink ACP terminal scrollback to used on exit (#60019)

# Objective

ACP agents (Cursor, Claude Code, Codex, etc.) start a display-only
`terminal::Terminal` for each bash tool call. After the call exits, the
terminal stays alive so that its output stays visible. But the
`alacritty` `Grid` keeps a `Storage` cache that's never reclaimed.
Across a long session this memory adds up.

Partially fixes #57099

## Solution

Added `Terminal::shrink_to_used`, called from the `Exit` branch of
`on_terminal_provider_event`. This calls `Grid::truncate()` on the
alacritty grid, shrinking the `Storage` cache portion while leaving
user-visible scrollback.

## Testing

- `cargo nextest run -p terminal
shrink_to_used_preserves_user_visible_scrollback` passes — exercises the
path with >10K rows of scrollback.
- `./script/clippy` clean.
- Manually verified: ran a noisy bash tool call via an ACP agent,
observed exit, then scrolled back through the output, no regression.

## 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:

- Improved memory usage of ACP terminals after the tool call exits

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
```

## Parents

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

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