Gpui Context
Master GPUI context management for smooth UI state and async operations
✨ The solution you've been looking for
Context management in GPUI including App, Window, and AsyncApp. Use when working with contexts, entity updates, or window operations.
See It In Action
Interactive preview & real-world examples
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
Install
claude-code skill install gpui-context
claude-code skill install gpui-contextConfig
First Trigger
@gpui-context helpCommands
| Command | Description | Required Args |
|---|---|---|
| @gpui-context component-state-updates | Managing component state changes and triggering re-renders in GPUI applications | None |
| @gpui-context async-data-fetching | Handling asynchronous operations like API calls while maintaining UI responsiveness | None |
| @gpui-context window-management | Working with window-specific operations, bounds, focus states, and multi-window applications | None |
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 creationWindow: Window-specific operations, painting, layoutContext<T>: Entity-specific context for componentTAsyncApp: Async context for foreground tasksAsyncWindowContext: 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
Framework Support
Context Window
Security & Privacy
Information
- Author
- longbridge
- Updated
- 2026-01-30
- Category
- productivity-tools
Related Skills
Gpui Context
Context management in GPUI including App, Window, and AsyncApp. Use when working with contexts, …
View Details →Gpui Entity
Entity management and state handling in GPUI. Use when working with entities, state management, or …
View Details →Gpui Entity
Entity management and state handling in GPUI. Use when working with entities, state management, or …
View Details →