Gpui Context

Master GPUI context management for smooth UI state and async operations

✨ The solution you've been looking for

Verified
Tested and verified by our team
9771 Stars

Context management in GPUI including App, Window, and AsyncApp. Use when working with contexts, entity updates, or window operations.

gpui ui-framework state-management rust context async gui-development reactive-ui
Repository

See It In Action

Interactive preview & real-world examples

Live Demo
Skill Demo Animation

AI Conversation Simulator

See how users interact with this skill

User Prompt

How do I update my component's state and notify the UI to re-render when a user clicks a button in GPUI?

Skill Processing

Analyzing request...

Agent Response

Code showing proper Context<T> usage with state updates, cx.notify() calls, and reactive UI patterns

Quick Start (3 Steps)

Get up and running in minutes

1

Install

claude-code skill install gpui-context

claude-code skill install gpui-context
2

Config

3

First Trigger

@gpui-context help

Commands

CommandDescriptionRequired Args
@gpui-context component-state-updatesManaging component state changes and triggering re-renders in GPUI applicationsNone
@gpui-context async-data-fetchingHandling asynchronous operations like API calls while maintaining UI responsivenessNone
@gpui-context window-managementWorking with window-specific operations, bounds, focus states, and multi-window applicationsNone

Typical Use Cases

Component State Updates

Managing component state changes and triggering re-renders in GPUI applications

Async Data Fetching

Handling asynchronous operations like API calls while maintaining UI responsiveness

Window Management

Working with window-specific operations, bounds, focus states, and multi-window applications

Overview

Overview

GPUI uses different context types for different scenarios:

Context Types:

  • App: Global app state, entity creation
  • Window: Window-specific operations, painting, layout
  • Context<T>: Entity-specific context for component T
  • AsyncApp: Async context for foreground tasks
  • AsyncWindowContext: Async context with window access

Quick Start

Context - Component Context

 1impl MyComponent {
 2    fn update_state(&mut self, cx: &mut Context<Self>) {
 3        self.value = 42;
 4        cx.notify(); // Trigger re-render
 5
 6        // Spawn async task
 7        cx.spawn(async move |cx| {
 8            // Async work
 9        }).detach();
10
11        // Get current entity
12        let entity = cx.entity();
13    }
14}

App - Global Context

 1fn main() {
 2    let app = Application::new();
 3    app.run(|cx: &mut App| {
 4        // Create entities
 5        let entity = cx.new(|cx| MyState::default());
 6
 7        // Open windows
 8        cx.open_window(WindowOptions::default(), |window, cx| {
 9            cx.new(|cx| Root::new(view, window, cx))
10        });
11    });
12}

Window - Window Context

1impl Render for MyView {
2    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
3        // Window operations
4        let is_focused = window.is_window_focused();
5        let bounds = window.bounds();
6
7        div().child("Content")
8    }
9}

AsyncApp - Async Context

1cx.spawn(async move |cx: &mut AsyncApp| {
2    let data = fetch_data().await;
3
4    entity.update(cx, |state, inner_cx| {
5        state.data = data;
6        inner_cx.notify();
7    }).ok();
8}).detach();

Common Operations

Entity Operations

 1// Create entity
 2let entity = cx.new(|cx| MyState::default());
 3
 4// Update entity
 5entity.update(cx, |state, cx| {
 6    state.value = 42;
 7    cx.notify();
 8});
 9
10// Read entity
11let value = entity.read(cx).value;

Notifications and Events

 1// Trigger re-render
 2cx.notify();
 3
 4// Emit event
 5cx.emit(MyEvent::Updated);
 6
 7// Observe entity
 8cx.observe(&entity, |this, observed, cx| {
 9    // React to changes
10}).detach();
11
12// Subscribe to events
13cx.subscribe(&entity, |this, source, event, cx| {
14    // Handle event
15}).detach();

Window Operations

1// Window state
2let focused = window.is_window_focused();
3let bounds = window.bounds();
4let scale = window.scale_factor();
5
6// Close window
7window.remove_window();

Async Operations

1// Spawn foreground task
2cx.spawn(async move |cx| {
3    // Async work with entity access
4}).detach();
5
6// Spawn background task
7cx.background_spawn(async move {
8    // Heavy computation
9}).detach();

Context Hierarchy

App (Global)
  └─ Window (Per-window)
       └─ Context<T> (Per-component)
            └─ AsyncApp (In async tasks)
                 └─ AsyncWindowContext (Async + Window)

Reference Documentation

  • API Reference: See api-reference.md
    • Complete context API, methods, conversions
    • Entity operations, window operations
    • Async contexts, best practices

What Users Are Saying

Real feedback from the community

Environment Matrix

Dependencies

GPUI framework
Rust 1.70+

Framework Support

GPUI ✓ (required)

Context Window

Token Usage ~1K-3K tokens for typical context management patterns

Security & Privacy

Information

Author
longbridge
Updated
2026-01-30
Category
productivity-tools