User context in Astro components works by setting user data once in a parent component using setContext. Child components then access this data with getContext to personalize their output, such as greeting the user by name. The execution flow starts with the user logging in, setting the context, children accessing it, rendering personalized UI, and finally clearing the context on logout. Variables like 'user' change from null to user data and back to null, affecting what the child components display. This method avoids passing user data through many props and keeps components clean and focused.