# Svelte and AI coding tools

- Published: 2026-12-03
- Tags: Why Svelte, Svelte
- URL: https://devtrillo.com/writing/why-svelte-22-svelte-and-ai-coding-tools/

> Part 22, and the last, of a series on Svelte in 2026. [Part 21](/writing/why-svelte-21-svelte-tailwind-v4-setup/) set up Tailwind v4. This part is about the other thing writing your components now: a coding agent.

Ask a coding agent for a Svelte component and there's a fair chance you get Svelte 4. `export let` for props, `$:` for derived values, `on:click`, a `<slot />`. Svelte 5 came out in October 2024, and most of the Svelte code a model saw in training was written before that.[^alive]

That would be a small problem if the build complained. It doesn't. Svelte 5 decides per file whether a component uses runes, and a file without any is compiled in legacy mode, on purpose, so that old components keep working during a migration. The same feature that made [part 16](/writing/why-svelte-16-migrating-to-sveltekit-3-with-sv-migrate/)'s upgrade gentle means a model can write you the old language and nothing in your toolchain will say so.

The Svelte team saw this coming and shipped tooling for it: an MCP server, a CLI, agent skills and a subagent, all in `sveltejs/ai-tools`.[^overview] I wanted to know which piece matters, so I gave the main one the code that models tend to get wrong and wrote down what it said.

The lab ran Svelte 5.57.3, `@sveltejs/mcp` 0.1.28, `svelte-check` 4.7.7 and `sv` 1.1.1 on Node 24, with jsdom for the one runtime check.

## Svelte 4 compiles clean

Here's a filterable list written the way a model fluent in 2023 Svelte writes it:

```svelte title="Legacy.svelte"
<script>
  import { onMount } from "svelte";
  export let items = [];
  let filter = "";
  $: shown = items.filter((i) => i.name.includes(filter));
  onMount(() => {
    window.addEventListener("keydown", onKey);
  });
  function onKey(e) {
    if (e.key === "Escape") filter = "";
  }
</script>

<input bind:value={filter} />
<button on:click={() => (filter = "")}>Clear</button>
<ul>
  {#each shown as item}
    <li>{item.name}</li>
  {/each}
</ul>
<slot />
```

Svelte 5.57.3's `compile()` returned it with no errors and no warnings. Not one deprecation notice, because in legacy mode none of this is deprecated. `svelte-check` in a strict TypeScript project only complained about implicit `any` types.

A half-migrated file is where it gets noisy. Swap the props for `$props()` and the filter for `$state`, keep `on:click`, and the compiler now knows it's in runes mode and warns `event_directive_deprecated`. The trouble is the version in between, the one that's entirely old and therefore entirely quiet, and that's exactly the one an agent with no Svelte 5 context produces.

## What the autofixer catches

`svelte-autofixer` is the tool in the MCP server that matters most here. It's static analysis over a component, and you can run it without any MCP client at all: `npx @sveltejs/mcp svelte-autofixer src/lib/List.svelte --svelte-version 5.57.3` prints `issues`, `suggestions` and a flag called `require_another_tool_call_after_fixing`.[^cli]

On the legacy file it reported one issue:

```text
Cannot use `export let` in runes mode — use `$props()` instead
https://svelte.dev/e/legacy_export_invalid at line 3, column 2
```

So the autofixer analyses everything as runes mode, which is the right call: it treats Svelte 4 syntax as wrong rather than as an alternative. It also reports one compile error at a time, since the compiler stops at the first. I fixed `export let` and ran it again, and it moved on to `$:` (`legacy_reactive_statement_invalid`). Fixing that turned up three at once, because those were warnings rather than errors: `on:click` deprecated, `<slot>` deprecated, and "Each block should have a key". A fourth run came back with empty `issues`, empty `suggestions` and `require_another_tool_call_after_fixing: false`.

That flag tells you how the tool expects to be used. It isn't a lint report for you to read; it's one turn in a loop the agent runs until the flag goes false, and the Svelte docs' own `AGENTS.md` text tells the model to "keep calling it until no issues or suggestions are returned."[^instructions] Four calls for a component this size is cheap.

It's also more than a compiler with the strictness turned up. Given the classic runes mistake, syncing a value with an effect:

```svelte
let shown = $state([]);
$effect(() => {
  shown = items.filter((i) => i.name.includes(filter));
});
```

it came back with suggestions on top of the compiler warnings, among them "The stateful variable "shown" is assigned inside an $effect which is generally consider a malpractice. Consider using $derived if possible." and "Prefer using writable $derived instead of $state and $effect". That's [part 5](/writing/why-svelte-5-effect-escape-hatch/) in two lines, and the Svelte compiler on its own says nothing about it.

**Quiz:** A coding agent hands you a component with export let, $: and on:click. Svelte 5's compiler accepts it without a warning. Why?

- Those features are still the recommended syntax in Svelte 5
- A file with no runes compiles in legacy mode, where that syntax is valid
- The compiler only checks syntax in production builds

**Answer:** A file with no runes compiles in legacy mode, where that syntax is valid — Svelte 5 picks the mode per file. Old components keep working during a migration, which also means old code from a model doesn't get flagged.

- Not "Those features are still the recommended syntax in Svelte 5": They're legacy syntax. The docs and the autofixer both point you to $props, $derived and onclick.
- Not "The compiler only checks syntax in production builds": It checks the same way in dev and prod. The file is valid legacy Svelte, so there's nothing to report.

## What a clean report still lets through

The fourth run said the component was clean. It still had a bug from the first draft: `onMount` adds a `keydown` listener to `window` and never removes it. [Part 9](/writing/why-svelte-9-svelte-best-practices-from-the-docs/) measured that exact leak, three unmounted components all still answering one keypress, and the fix, `<svelte:window onkeydown={...} />`. The autofixer didn't mention it. Moving the listener into an `$effect` with no cleanup didn't get flagged either; it drew only a generic "you are calling a function inside an $effect" suggestion about derived state, nothing about teardown.

The second one is a React habit, and it's worse because it fails silently at runtime:

```svelte
<button onClick={() => (open = !open)}>Toggle</button>
```

Svelte 5 event attributes are case-sensitive. That compiles to `$.event('Click', button, ...)`, a listener for an event called `Click`, which no browser fires. In jsdom, clicking the button left the list closed; with `onclick` it opened. The compiler gave no warning and neither did the autofixer. What caught it was `svelte-check` in a TypeScript project, with "`"onClick"` does not exist in type `HTMLProps<"button", ...>`". Even that only showed up after I removed a `className` from the same tag, because TypeScript reports one excess property per object literal and `className` got reported first.

So I'd treat the autofixer as one check in a stack, not as the stack. It's very good at "this is Svelte 4" and at a handful of runes anti-patterns; types catch a different set; and behaviour still needs a test, [part 17](/writing/why-svelte-17-testing-svelte-components/)'s kind, clicking the button and looking at the DOM.

## Docs the model can read

The other half of the tooling is context. Every docs page has an `llms.txt` version, and `svelte.dev/llms.txt` indexes three bundles of the whole Svelte and SvelteKit docs.[^llms] The day I fetched them, the full one was about 1.27 MB, the "abridged" one about 877 KB and the "compressed" one 53 KB. Only that last one is something you'd paste into a prompt without thinking about your context window, and it keeps the size down by dropping most of the examples.

The MCP server does this lazily instead. `list-sections` returned 205 sections, each with a `use_cases` field, and `get-documentation` fetches just the ones the agent asks for. The skills go further. `svelte-core-bestpractices` is the page part 9 tested, packaged as a skill of about 1,100 words plus nine reference files; the agent loads it only when it's working on a `.svelte` file. `svelte-code-writer` teaches the agent the CLI commands, for clients where the MCP server isn't connected.[^skills]

React has a docs index for models too: `react.dev/llms.txt` lists every page as Markdown. What it doesn't have is an official tool that runs on a component and says "this is old React", partly because React's old code mostly still is React. Class components and `useEffect`-for-everything are discouraged, not a different syntax. Svelte's break between 4 and 5 is sharper, which is why its tooling leans so hard on correction rather than reference.

**Quiz:** An agent's autofixer loop ends with no issues and require_another_tool_call_after_fixing: false. What does that tell you?

- The component is correct
- No legacy syntax or known runes anti-pattern was found
- svelte-check will also pass

**Answer:** No legacy syntax or known runes anti-pattern was found — That's its job: Svelte 4 syntax, unkeyed each blocks, effects that should be deriveds. Types and tests cover what it doesn't.

- Not "The component is correct": In the lab, a clean report still left a window listener with no cleanup and an onClick that never fires.
- Not "svelte-check will also pass": svelte-check runs TypeScript. It caught the onClick the autofixer missed, so the two can disagree.

## The setup I'd use

`npx sv add ai-tools` does the wiring. With Claude Code picked and individual tools selected, it wrote an `.mcp.json` that runs `npx -y @sveltejs/mcp`, an `AGENTS.md` with the tool instructions, a `.claude/CLAUDE.md` that imports it, the best-practices skill and the `svelte-file-editor` subagent.[^addon] The plugin option does the same through a committed `.claude/settings.json` and keeps itself updated. There's also a remote server at `mcp.svelte.dev/mcp`, and the team says it doesn't log, store or inspect the code you send it.[^remote]

I'd take the local server, the best-practices skill and the `AGENTS.md` text, and skip the playground tool, which only matters if your agent writes code into a chat window instead of files. The subagent is worth it on a long session: it runs the docs lookup and autofixer loop in its own context, so twenty rounds of tool output don't crowd out the rest of the conversation.

And keep `svelte-check` and a component test in CI, because the autofixer agreed with me twice when I was wrong. Svelte's honest advantage here isn't that models write it better than React; they mostly don't, yet. It's that the gap is small, mechanical and documented, and the people who make the framework have written the tool that closes most of it.

## Where the series stops

This is the last part. [Part 1](/writing/why-svelte-1-why-should-you-care/) asked you to look, not to switch. Twenty-two posts later that's still roughly where I land, with better reasons.

The case for Svelte held up when I measured it. The counter shipped about 10 kB gzipped against React's 69 kB in [part 2](/writing/why-svelte-2-svelte-is-a-compiler/), and in [part 19](/writing/why-svelte-19-svelte-vs-react-one-component-two-ways/) ticking one item in a 100-item list re-ran zero component functions in Svelte and 101 in React, Compiler or not. Runes turned out to be a smaller language than hooks, with fewer ways to get the same thing subtly wrong.

The case against held up too. React's ecosystem and hiring pool are bigger, and remote functions were still experimental when I tested them. [Part 20](/writing/why-svelte-20-a-component-library-in-svelte/)'s library broke on a template that lagged its own docs. And the models writing more of our code are still more fluent in React, and in Svelte 4, than in Svelte 5. If your team already ships React and nothing hurts, none of that adds up to a rewrite. If you're starting something new, or something keeps re-rendering that shouldn't, build one real screen in Svelte 5 with the autofixer in the loop. Then decide.

[^alive]: Svelte blog, [Svelte 5 is alive](https://svelte.dev/blog/svelte-5-is-alive), October 2024.

[^overview]: Svelte docs, [AI overview](https://svelte.dev/docs/ai/overview): instructions, MCP server, skills and subagents. Source in [sveltejs/ai-tools](https://github.com/sveltejs/ai-tools).

[^cli]: Svelte docs, [CLI](https://svelte.dev/docs/ai/cli) and [Tools](https://svelte.dev/docs/ai/tools).

[^instructions]: Svelte docs, [AGENTS.md](https://svelte.dev/docs/ai/instructions).

[^llms]: [svelte.dev/llms.txt](https://svelte.dev/llms.txt). Sizes are the bytes downloaded on the day I ran the lab, rounded; they move with every docs change.

[^skills]: Svelte docs, [Skills](https://svelte.dev/docs/ai/skills) and [Subagent](https://svelte.dev/docs/ai/subagent).

[^addon]: Svelte CLI docs, [ai-tools](https://svelte.dev/docs/cli/ai-tools).

[^remote]: Svelte docs, [Remote setup](https://svelte.dev/docs/ai/remote-setup).
