/stimulus:stimulusfrom stimulus
Use when writing, reviewing or debugging Stimulus (Hotwire) controllers — data-controller, data-action, targets, values, classes, outlets, lifecycle callbacks, registering controllers with Vite, TypeScript controllers, making controllers survive Turbo visits, the cache and morphing, and wrapping third-party libraries. Any backend; examples come from a Void app.
Ships in stimulus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Stimulus attaches behavior to server-rendered HTML. The HTML says which controller, which elements and
which events (data-controller, data-<name>-target, data-action); the controller is a small class. State
lives in the DOM, so the server can render it and Turbo can replace it. Read the reference page before
using an API:
lifecycle-callbacks, actions,
targets, outlets, values, css-classes, using-typescript)https://raw.githubusercontent.com/hotwired/stimulus-site/main/_source/reference/values.md
(and the other reference and handbook files under _source/)This is Stimulus 3.2 (@hotwired/stimulus, which ships its own types).
// src/controllers/index.ts
import { Application } from "@hotwired/stimulus";
import type { ControllerConstructor } from "@hotwired/stimulus";
const application = Application.start();
const modules = import.meta.glob<{ default: ControllerConstructor }>("./**/*_controller.ts", { eager: true });
for (const [path, module] of Object.entries(modules)) {
const name = path.replace(/^\.\//, "").replace(/_controller\.ts$/, "").replaceAll("/", "--").replaceAll("_", "-");
application.register(name, module.default);
}
reset_form_controller.ts registers as reset-form, and bridge/button_controller.ts as bridge--button.
Adding a controller is adding its file. Import controllers/index.ts once, from the browser entry
(src/main.client.ts).
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ["input", "count"];
static values = { max: { type: Number, default: 280 } };
static classes = ["over"];
declare readonly inputTarget: HTMLTextAreaElement;
declare readonly countTarget: HTMLElement;
declare maxValue: number;
declare readonly overClass: string;
update() {
const left = this.maxValue - this.inputTarget.value.length;
this.countTarget.textContent = String(left);
this.countTarget.classList.toggle(this.overClass, left < 0);
}
}
<div data-controller="counter" data-counter-max-value="140" data-counter-over-class="text-error">
<textarea name="body" class="textarea" data-counter-target="input" data-action="input->counter#update"></textarea>
<span data-counter-target="count"></span>
</div>
In TypeScript, declare each target, value and class that the statics create (declare readonly xTarget: HTMLElement, declare readonly hasXTarget: boolean, declare xValue: T), and give Controller<E>
the element's type.
data-action, including on window and
document (resize@window->gallery#layout, keydown.esc@document->modal#close). Stimulus adds and
removes those listeners. A listener added by hand in connect() is removed in disconnect() by the same
bound function.data-*-value attribute: the server renders it, Turbo caches it, morphing
updates it, and xValueChanged() reacts to it (it also runs at connect). Keep library instances and
secrets out of values.static classes for CSS classes (daisyUI's hidden, btn-active,
text-error) and values for URLs and limits, never constants in the controller. Then one controller
serves many pages.document.querySelector. Talk to another controller through
an outlet (data-x-y-outlet="#id"), or with this.dispatch("done", { detail }) and a data-action that
listens for x:done.connect() makes (a library instance, a timer, an observer, a
subscription), disconnect() destroys. Code that assumes it runs once per page load is wrong under
Turbo.reset-form, clipboard, dialog, never
home-page). Put several on one element: data-controller="reset-form autosize".turbo:submit-end->reset-form#reset (where event.detail.success
says whether the form succeeded), turbo:before-cache@document->menu#close.daisyUI's components work without JavaScript wherever HTML can do it. Use those as they are: <dialog class="modal"> with showModal(), <details class="dropdown">, the swap and theme-controller
checkboxes, tabs as radio inputs. A controller is for what HTML cannot do, such as opening a <dialog> from
a button (this.dialogTarget.showModal()), or closing it after a Turbo form inside it succeeds.
| Symptom | Cause |
|---|---|
| Nothing happens, no error | The controller is not registered (name mismatch: foo_bar_controller.ts is foo-bar), or the bundle is not loaded |
Missing target element "x" | data-<controller>-target="x" is missing, or it sits outside the controller's element; guard optional ones with hasXTarget |
| Works on first load, not after a visit | Setup ran in DOMContentLoaded or turbo:load, outside a controller |
| Listeners or timers pile up | disconnect() does not undo connect() |
| A morph refresh loses the controller's state | The state was a JS field; make it a value |
| The back button shows a half-open widget | The DOM was changed and not undone before caching (turbo:before-cache, disconnect()) |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub joeblew999/hotwire-skills --plugin stimulus