# Add Dark Mode to a Reflex App

Yes. An agent adds a light, dark and system toggle to a Reflex app with rx.color_mode.button, keeps colours on theme tokens, adds a browser test and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-dark-mode/reflex/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the app is themed before it adds a toggle, because Reflex does most of this job through its Radix theme and the app decides the rest. In an app like the `todo` example in reflex-dev/reflex-examples, `rxconfig.py` sets `app_name="todo"`, `env=rx.Env.DEV` and `plugins=[rx.plugins.RadixThemesPlugin()]` with no `theme` argument, and `todo/todo/todo.py` ends with `app = rx.App()` and `app.add_page(index, title="Todo App")`, so the theme is the plugin's default. The page is an `rx.center` around an `rx.vstack` with a heading, the add form, a divider and the list; its background is `rx.color("gray", 7)` and the input's is `rx.color("gray", 2)`, both Radix colour tokens, and `requirements.txt` says `reflex>=0.9.2`. Nothing calls `rx.color_mode`, `toggle_color_mode` or `rx.color_mode_cond`, so a reader on a dark system gets the light appearance with no way to change it.

The repository's `nba` example shows the pattern the agent follows: its navbar places `rx.color_mode.button()` in an `rx.hstack`, and its `rxconfig.py` passes `rx.theme(appearance="light", has_background=True, radius="large", accent_color="orange")` to the plugin. Reflex's theming documentation says `rx.color(name, shade)` tokens change on their own when the appearance switches between light and dark, that `rx.color_mode_cond(light=..., dark=...)` renders one value per mode for a component or a prop, and that `toggle_color_mode` flips the mode from any event trigger. In Reflex's source, `rx.color_mode.button` is a `ColorModeIconButton` whose `position` prop takes `top-left`, `top-right`, `bottom-left` or `bottom-right` and then sets `position: fixed` with a 2rem offset, and whose `allow_system` flag turns the button into a menu that also offers the system setting through `set_color_mode`.

So the change is small. In `todo.py` the agent adds `rx.color_mode.button(position="top-right", allow_system=True)` to the index page, so the button floats in the corner and offers light, dark and system, and moves the theme into `rxconfig.py` as `rx.theme(appearance="inherit", has_background=True)` so the app starts in the mode the browser reports. It checks every colour in the page: the two `rx.color` tokens already adapt, and there is no hex value or named colour to replace, which is the thing that usually goes wrong in a larger app. It adds nothing to the state, because the colour mode lives in the browser, not in `State`.

The proof follows the repository's own test pattern. `counter/tests/test_counter.py` starts the app with `reflex.testing.AppHarness.create(root=...)`, drives a browser through `harness.frontend()` and polls with `poll_for_content`, with `pytest`, `selenium`, `pytest-playwright` and the rest in `counter/requirements-dev.txt`, and `.github/workflows/app_harness.yml` runs every example directory that has a `tests` folder. The agent adds `todo/tests/test_color_mode.py` on that pattern: it opens the page, reads the `class` attribute of the Radix root element, which Reflex's colour mode provider sets to `light` or `dark`, clicks the button, chooses dark and checks the class flips, reloads and checks it is still dark, then chooses system and checks the class matches the browser's preference, and `todo/requirements-dev.txt` enrols the example in the workflow's matrix. In its sandbox the agent runs `reflex init`, `reflex run` and the test headless, and opens the app in its own browser in both modes.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a dark mode toggle to this Reflex app. Read rxconfig.py, requirements.txt, the app module, and the tests and requirements-dev.txt of any sibling example that already has them first. Add rx.color_mode.button with position top-right and allow_system so the reader can pick light, dark or system, set the theme's appearance to inherit through the RadixThemesPlugin in rxconfig.py, and check every colour on the page is an rx.color token or an rx.color_mode_cond rather than a fixed value, replacing any that is not. Keep the state unchanged. Add a tests directory with an AppHarness test on the pattern the repository already uses that reads the Radix root element's class, switches to dark, reloads and confirms it stays dark, then switches to system, plus a requirements-dev.txt. Run reflex init, the app and the test headless, open the app in a browser in both modes, and open a pull request that links the issue and lists the commands and their output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `todo/todo/todo.py` and `todo/rxconfig.py`, and adds `todo/tests/test_color_mode.py` and `todo/requirements-dev.txt`. Its description shows the test run's output, two screenshots of the page in light and dark, the list of colour values it checked with the note that both were already tokens, and the sentence from the theming documentation on how `rx.color` adapts. `requirements.txt` does not change.

A reviewer checks the button's corner, whether the app should start in `inherit` or keep a fixed `light` default, and whether the test's reload step is the persistence proof they wanted. The `app_harness.yml` run on the pull request executes the new test on the next push because the matrix discovers the `tests` directory, so the check appears without a workflow change.

## Run it on every Linear issue labelled ui

A team that triages in Linear adds an automation to the Project with a `linear` trigger on `linear.issue.labeled`, the label `ui` and `plan` mode, so the agent reads the issue and the app and posts the toggle it would add, the colours it found fixed and the test it would write as a comment on the issue. Only a change made by a member of the Rush org fires it, and the comment is the whole result: an automation's runs are read-only and push nothing.

When the plan is agreed, a handler on the team's own server starts the run that pushes: it sends this body with the Linear issue URL added to `resources`, which puts the issue text in front of the agent through the team's Linear connection, and a `request_id` that is a UUID v5 of the issue id, so a redelivered event returns the run already started rather than a second pull request.

## Why run it on Rush?

A colour mode toggle is one component, and the real work is the audit around it: every colour in the app has to be a token or a per-mode value, the theme has to start from the browser's preference, and the choice has to survive a reload. Those are checked in a browser, so the agent runs the app in its own sandbox, drives a real browser through the repository's own harness, takes the screenshots, and keeps every command and its output in the run's record.

It also fits the repository rather than inventing a pattern: the `nba` example's button, the `counter` example's test shape, the `tests` directory and `requirements-dev.txt` the CI matrix looks for. Several apps with the same missing toggle get several pull requests, each reading its own page for colours that would not adapt.

## Frequently asked questions

### Does the choice persist between visits?

Yes. Reflex's colour mode is kept in the browser by its theme provider, which is why the test reloads the page and checks the mode is still dark. Nothing is stored in `State` or on the server, so two browsers can hold two choices.

### What if my app uses hex colours?

A fixed value stays the same in both modes, so a white card on a dark page is the usual result. The agent lists every fixed colour it finds and replaces each with `rx.color(name, shade)`, which adapts, or `rx.color_mode_cond(light=..., dark=...)` where the two modes need different values, and the pull request shows each replacement.

### Can I use a switch instead of the icon button?

Yes. `rx.color_mode.switch` toggles the same mode from a switch component, and `toggle_color_mode` can be attached to any button's `on_click`. The icon button with `allow_system` is the one that also offers the system setting, which is why the pull request uses it.

### Why appearance inherit rather than dark?

`inherit` starts the app in the mode the browser reports, so a reader with a dark system sees dark on the first load and the toggle is for overriding it. A fixed `dark` default would make every light-system reader click once; the pull request keeps `inherit` and says where to change it.

## More Reflex jobs

- [Add Dependabot to a Reflex App](https://getrush.ai/run/add-dependabot/reflex/)
- [Write a Dockerfile for a Reflex App](https://getrush.ai/run/add-dockerfile/reflex/)
- [Add File Uploads to a Reflex Chat App](https://getrush.ai/run/add-file-uploads/reflex/)

## The same job on other stacks

- [Add Dark Mode to a SolidJS App](https://getrush.ai/run/add-dark-mode/solidjs/)
- [Add Dark Mode to Sphinx Docs on the Read the Docs Theme](https://getrush.ai/run/add-dark-mode/sphinx/)
- [Add Dark Mode to a SvelteKit App](https://getrush.ai/run/add-dark-mode/sveltekit/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
