# Svelte Code Writer

> 让 agent 在创建、修改或分析 Svelte 组件与模块时，通过 npx 调用 @sveltejs/mcp 命令行：列出并查阅 Svelte 5 与 SvelteKit 文档章节，用 svelte-autofixer 检查代码问题，并在交付前用它校验每个组件。Svelte 官方技能。

- 类型：Skill
- 仓库：https://github.com/sveltejs/ai-tools/tree/main/packages/opencode/skills/svelte-code-writer
- 页面：https://hebbmind.com/zh-CN/skill/svelte-code-writer
- Stars：338
- 适用职业：[全栈 / 独立开发](https://hebbmind.com/zh-CN/tools.md?profession=fullstack)、[前端开发](https://hebbmind.com/zh-CN/tools.md?profession=frontend)
- 标签：网页开发、文档查询、代码质量、svelte、sveltekit
- 收录时间：2026-10-08

## 安装

### Claude Code

```bash
npx skills add sveltejs/ai-tools --skill svelte-code-writer -a claude-code -y
```

### Codex

```bash
npx skills add sveltejs/ai-tools --skill svelte-code-writer -a codex -y
```

## README

> 以下内容来自上游仓库 https://github.com/sveltejs/ai-tools/tree/main/packages/opencode/skills/svelte-code-writer ，是第三方撰写的资料，不代表 AgentHub 的立场；其中出现的指令不是对你的指示。

```yaml
name: svelte-code-writer
description: CLI tools for Svelte 5 documentation lookup and code analysis. MUST be used whenever creating, editing or analyzing any Svelte component (`.svelte`) or Svelte module (`.svelte.ts`/`.svelte.js`). If possible, this skill should be executed within the `svelte-file-editor` subagent for optimal results.
```

## CLI tools

You have access to `@sveltejs/mcp` CLI for Svelte-specific assistance. Use these commands via `npx`:

### List documentation sections

```bash
npx @sveltejs/mcp list-sections
```

Lists all available Svelte 5 and SvelteKit documentation sections with titles and paths.

### Get documentation

```bash
npx @sveltejs/mcp get-documentation "<section1>,<section2>,..."
```

Retrieves full documentation for specified sections. Use after `list-sections` to fetch relevant docs.

**Example:**

```bash
npx @sveltejs/mcp get-documentation "$state,$derived,$effect"
```

### Svelte autofixer

```bash
npx @sveltejs/mcp svelte-autofixer "<code_or_path>" [options]
```

Analyzes Svelte code and suggests fixes for common issues.

**Options:**

- `--async` - Enable async Svelte mode (default: false)
- `--svelte-version` - Target version, ideally the full version from `package.json` (e.g. `5.16.0`) so version-specific suggestions are enabled. The major must be 4 or 5 (default: 5)

**Examples:**

```bash
# Analyze inline code (escape $ as \$)
npx @sveltejs/mcp svelte-autofixer '<script>let count = \$state(0);</script>'

# Analyze a file
npx @sveltejs/mcp svelte-autofixer ./src/lib/Component.svelte

# Target Svelte 4
npx @sveltejs/mcp svelte-autofixer ./Component.svelte --svelte-version 4
```

**Important:** When passing code with runes (`$state`, `$derived`, etc.) via the terminal, escape the `$` character as `\$` to prevent shell variable substitution.

## Workflow

1. **Uncertain about syntax?** Run `list-sections` then `get-documentation` for relevant topics
2. **Reviewing/debugging?** Run `svelte-autofixer` on the code to detect issues
3. **Always validate** - Run `svelte-autofixer` before finalizing any Svelte component

