CLAUDE.md rules for Vue 3.5 script setup with reactive props destructure, typed emits, race-safe async watchers and Pinia setup stores that return all state.
.claude/rules/claude-vue-3-expert.md. Downloaded files need to be placed in that repository path.---
paths:
- "**/*"
---
# Vue 3 Conventions (Composition API)
Applies to: Vue single-file components, composables and Pinia stores in this repository.
Version baseline: checked against Vue 3.5 and Pinia 4.1 (setup-store rules from the current Pinia docs). Read `package.json`. On Vue 3.3/3.4, use `withDefaults` instead of destructured defaults, because reactive props destructure needs 3.5.
## Components
- Use `<script setup lang="ts">` with type-based `defineProps` and `defineEmits`. Don't use the Options API in new code unless the file already does.
- On Vue 3.5+, destructure props with defaults (`const { editable = false } = defineProps<Props>()`). The destructured variables stay reactive, but to watch one you need a getter (`watch(() => userId, ...)`).
- Declare emits with the named-tuple syntax (3.3+). Never mutate props. Emit an event or use `defineModel` for two-way binding.
- Use `computed` for derived values and keep `watch` for side effects. Guard async watchers against stale responses: cancel the request in `onWatcherCleanup` (3.5+), or ignore results from an outdated id.
```vue
<script setup lang="ts">
import { computed, ref, watch, onWatcherCleanup } from 'vue';
import { useUserStore } from '@/stores/user';
import type { User } from '@/types';
const { userId, editable = false } = defineProps<{ userId: string; editable?: boolean }>();
const emit = defineEmits<{
update: [user: User];
delete: [id: string];
}>();
const store = useUserStore();
const user = ref<User | null>(null);
const loading = ref(true);
const error = ref<string | null>(null);
const displayName = computed(() => user.value?.name ?? 'Unknown user');
watch(
() => userId,
async (id) => {
let cancelled = false;
onWatcherCleanup(() => { cancelled = true; });
loading.value = true;
error.value = null;
try {
const result = await store.fetchUser(id);
if (!cancelled) user.value = result;
} catch (e) {
if (!cancelled) error.value = e instanceof Error ? e.message : 'Failed to load';
} finally {
if (!cancelled) loading.value = false;
}
},
{ immediate: true },
);
</script>
<template>
<div class="user-profile">
<p v-if="loading" role="status">Loading...</p>
<p v-else-if="error" role="alert">{{ error }}</p>
<template v-else-if="user">
<h2>{{ displayName }}</h2>
<button v-if="editable" type="button" @click="emit('update', user)">Edit</button>
</template>
</div>
</template>
```
`onWatcherCleanup` must be called before the first `await`. This example calls it at the top of the callback.
## Pinia (setup stores)
- A setup store must return every state ref it declares. Pinia only treats returned refs as state, and unreturned state breaks SSR, devtools and plugins.
- Expose actions for mutations. In components, use `storeToRefs(store)` when destructuring state so it stays reactive.
```ts
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { api } from '@/api';
import type { User } from '@/types';
export const useUserStore = defineStore('user', () => {
const users = ref(new Map<string, User>());
const currentUserId = ref<string | null>(null);
const currentUser = computed(() =>
currentUserId.value ? users.value.get(currentUserId.value) ?? null : null,
);
async function fetchUser(id: string): Promise<User> {
const cached = users.value.get(id);
if (cached) return cached;
const user = await api.getUser(id);
users.value.set(id, user);
return user;
}
function setCurrentUser(id: string | null) {
currentUserId.value = id;
}
return { users, currentUserId, currentUser, fetchUser, setCurrentUser };
});
```
## Composables
- Name them `useX`, accept refs or getters (`MaybeRefOrGetter` with `toValue`), return refs, and clean up listeners in `onScopeDispose`.
## Verify before finishing
Run when available: `npx vue-tsc --noEmit`, `npx eslint .` (eslint-plugin-vue) and the tests (Vitest with `@vue/test-utils`).
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
Claude
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Claude Code edits Vue 3 single-file components and Pinia stores with this file loaded as a project rule scoped to src/**/*.{vue,ts}.
UserProfile.vue shows the wrong user when userId changes quickly, and the Pinia store's currentUserId does not show in devtools. Fix both. Vue ^3.5, Pinia installed, TypeScript.
Illustrative; not a recorded model run. The component keeps <script setup lang="ts"> with destructured props and a getter-based watch; the async watcher registers onWatcherCleanup before its first await and ignores stale results; named-tuple defineEmits; loading/error states with role=status/alert. The store returns currentUserId (and every other state ref) plus a setCurrentUser action. The summary explains that unreturned setup-store state is not treated as state by Pinia and reports vue-tsc, eslint and test results.
Claude Code loads persistent project instructions from CLAUDE.md files and from Markdown rules in .claude/rules/. Rules can be scoped to file paths with a paths frontmatter field, and CLAUDE.md can import other files with @path syntax. The rules in this directory are written as plain instruction prompts: in Claude Code, save them as CLAUDE.md or .claude/rules/ content; in Claude.ai or the Claude API, use the same text as project instructions or a system prompt instead.
.claude/rules/claude-vue-3-expert.mdStarting point, not a tested configuration for your repository. Loaded when Claude Code works with files matching paths. Review the instructions, adapt the file paths and run your project's existing checks.
---
paths:
- "**/*"
---
# Vue 3 Conventions (Composition API)
Applies to: Vue single-file components, composables and Pinia stores in this repository.
Version baseline: checked against Vue 3.5 and Pinia 4.1 (setup-store rules from the current Pinia docs). Read `package.json`. On Vue 3.3/3.4, use `withDefaults` instead of destructured defaults, because reactive props destructure needs 3.5.
## Components
- Use `<script setup lang="ts">` with type-based `defineProps` and `defineEmits`. Don't use the Options API in new code unless the file already does.
- On Vue 3.5+, destructure props with defaults (`const { editable = false } = defineProps<Props>()`). The destructured variables stay reactive, but to watch one you need a getter (`watch(() => userId, ...)`).
- Declare emits with the named-tuple syntax (3.3+). Never mutate props. Emit an event or use `defineModel` for two-way binding.
- Use `computed` for derived values and keep `watch` for side effects. Guard async watchers against stale responses: cancel the request in `onWatcherCleanup` (3.5+), or ignore results from an outdated id.
```vue
<script setup lang="ts">
import { computed, ref, watch, onWatcherCleanup } from 'vue';
import { useUserStore } from '@/stores/user';
import type { User } from '@/types';
const { userId, editable = false } = defineProps<{ userId: string; editable?: boolean }>();
const emit = defineEmits<{
update: [user: User];
delete: [id: string];
}>();
const store = useUserStore();
const user = ref<User | null>(null);
const loading = ref(true);
const error = ref<string | null>(null);
const displayName = computed(() => user.value?.name ?? 'Unknown user');
watch(
() => userId,
async (id) => {
let cancelled = false;
onWatcherCleanup(() => { cancelled = true; });
loading.value = true;
error.value = null;
try {
const result = await store.fetchUser(id);
if (!cancelled) user.value = result;
} catch (e) {
if (!cancelled) error.value = e instanceof Error ? e.message : 'Failed to load';
} finally {
if (!cancelled) loading.value = false;
}
},
{ immediate: true },
);
</script>
<template>
<div class="user-profile">
<p v-if="loading" role="status">Loading...</p>
<p v-else-if="error" role="alert">{{ error }}</p>
<template v-else-if="user">
<h2>{{ displayName }}</h2>
<button v-if="editable" type="button" @click="emit('update', user)">Edit</button>
</template>
</div>
</template>
```
`onWatcherCleanup` must be called before the first `await`. This example calls it at the top of the callback.
## Pinia (setup stores)
- A setup store must return every state ref it declares. Pinia only treats returned refs as state, and unreturned state breaks SSR, devtools and plugins.
- Expose actions for mutations. In components, use `storeToRefs(store)` when destructuring state so it stays reactive.
```ts
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { api } from '@/api';
import type { User } from '@/types';
export const useUserStore = defineStore('user', () => {
const users = ref(new Map<string, User>());
const currentUserId = ref<string | null>(null);
const currentUser = computed(() =>
currentUserId.value ? users.value.get(currentUserId.value) ?? null : null,
);
async function fetchUser(id: string): Promise<User> {
const cached = users.value.get(id);
if (cached) return cached;
const user = await api.getUser(id);
users.value.set(id, user);
return user;
}
function setCurrentUser(id: string | null) {
currentUserId.value = id;
}
return { users, currentUserId, currentUser, fetchUser, setCurrentUser };
});
```
## Composables
- Name them `useX`, accept refs or getters (`MaybeRefOrGetter` with `toValue`), return refs, and clean up listeners in `onScopeDispose`.
## Verify before finishing
Run when available: `npx vue-tsc --noEmit`, `npx eslint .` (eslint-plugin-vue) and the tests (Vitest with `@vue/test-utils`).
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Imports with @path can nest up to four hops deep, according to the docs. Claude Code can read AGENTS.md as project instructions without extra configuration, but by default only when there is no CLAUDE.md in the working directory or above it. The docs list this behavior for version 2.1.277 and later and describe a setting (claude-md-and-agents-md) that loads both files. If you maintain AGENTS.md for other tools, you can also import it from CLAUDE.md with @AGENTS.md.
Documentation checked 2026-11-05: Claude Code docs: Manage Claude's memory
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.