adding-tauri-command
Skill2 starsChanged 10 days agoMITView on GitHub
Add a new Tauri IPC command end-to-end in AntanI (Rust command, registration, capability, TS wrapper, types). TRIGGER — read BEFORE writing any `#[tauri::command]` fn, any new `src-tauri/src/*.rs` module with commands, any `tauri::generate_handler!` edit, or any new/edited `src/lib/*.ipc.ts` file — even if the change looks like "just one function" or you already know the pattern from reading existing modules (pty.rs, api.ipc.ts, etc.) firsthand in this session. Trigger on requests like "add a command", "expose X to the frontend", "wire up IPC for Y", "new backend endpoint", or when a plan you're implementing includes a new Rust command + TS wrapper pair. Re-check this skill even mid-implementation if you notice you're about to hand-roll the same steps from memory instead of following the checklist.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- src/CLAUDE.mdCLAUDE.md
- prepare-releaseSkill
The file
Files
Add a Tauri IPC command
AntanI's frontend is a thin view over Rust state (see root CLAUDE.md /
src/CLAUDE.md / src-tauri/src/CLAUDE.md). Adding a new command touches
several files, and skipping one is easy to miss — this is a checklist, not new
policy.
Steps
- Write the Rust command in the right module (
state,pty,vscode_server,ide_webview, or a new module for a new concern — don't let concerns bleed together). Signature:#[tauri::command] fn do_thing(state: State<AppState>, some_arg: String) -> Result<AppData, String> { mutate(&state, |d| d.do_thing(&some_arg)) }- Lock the state mutex once, mutate, persist, return the full updated
state (
AppData/Settings) — never a partial diff. The frontend adopts this return value instead of optimistically mutating local state. - Real logic (mutation, validation) belongs in
state.rs's data model, not in the command wrapper —state.rsstays Tauri-free so it unit-tests without a Tauri runtime. The command is a thin wrapper. - No
unwrap/expecton user input or file contents — surface failure asResult<_, String>. - Structs crossing this boundary need
#[serde(rename_all = "camelCase")].
- Lock the state mutex once, mutate, persist, return the full updated
state (
- Register it in the
tauri::generate_handler![...]list inlib.rs(module-qualified if it lives outsidelib.rs, e.g.pty::pty_spawn). Forgetting this step compiles fine and fails silently at call time. - Capability check: custom app commands (anything in this crate) need
no entry in
src-tauri/capabilities/default.json. Only plugin/core commands (dialog, notification, opener, etc.) need a permission there. Add one only if you're calling a new plugin API, not for your own command. - TS wrapper in
src/lib/api.ipc.ts(or a sibling*.ipc.tsif it's a distinct concern, e.g.notifications.ipc.ts):export function doThing(someArg: string): Promise<AppData> { return invoke<AppData>("do_thing", { someArg }); }- Tauri v2 maps camelCase JS keys to snake_case Rust params — call with
camelCase (
someArg), not the Rust name. - Any new file that's purely
invoke/listen/plugin-API wrapping must use the.ipc.tssuffix —vitest.config.tsexcludessrc/lib/**/*.ipc.tsfrom the coverage gate by that pattern. A wrapper file without the suffix drags down the global 90% coverage target for no testing value.
- Tauri v2 maps camelCase JS keys to snake_case Rust params — call with
camelCase (
- Mirror types in
src/lib/types.ts(camelCase, matching the Rust struct exactly) if the command introduces or changes a shape. - Don't write a component/IPC-mock test for this. Vitest only covers pure
logic in
src/lib; Rust-side behavior worth testing lives instate.rs's own unit tests (state/merge logic, save→load round-trips), not the command wrapper.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

