# agent: Ensure context meter updates when context is cleared \(\#30320\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 51b25b5c223aebe6bb707121697612604565cbaf

Requested commit: 51b25b5c223aebe6bb707121697612604565cbaf

Commit: 51b25b5c223aebe6bb707121697612604565cbaf

Tree: d0f16806f92cc1105f0cfb781e880b9a630abcf2

Author: Mani Rash Ahmadi

Committer: GitHub

## Message

```
agent: Ensure context meter updates when context is cleared (#30320)

Addresses an issue where the agent context token meter in the panel
toolbar (showing usage like "X / Y tokens") failed to update its count
after the user cleared the current context via the context editor UI.
While the meter updated correctly when adding items, clearing them left
the display showing the old count.

The root cause was traced to the `ContextStore::clear` method in
`crates/agent/src/context_store.rs`. This method correctly cleared the
internal data structures holding the context items but neglected to call
`cx.notify()` to inform listeners of the state change. Consequently, the
UI components responsible for displaying the token count were not
triggered to re-render with the new (presumably lower) count.

This PR fixes the issue by adding the missing `cx.notify()` call to the
`ContextStore::clear` method. This ensures listeners are notified when
the context set is cleared, allowing the token meter UI to update
correctly.

Release Notes:

- Fixed an issue where the agent context token meter did not update when
the context was cleared.
```

## Parents

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

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