roninforge/roninforge-astro/astro-new-action

Claude Code and agent skill by roninforge/roninforge-astro

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Scaffold a new Astro 6 server action in src/actions/index.ts using defineAction with a zod input schema imported from astro:schema (NOT raw zod), optional accept:'form' for HTML form posts (with multipart enctype example for file uploads), and example call sites: server-side via Astro.callAction(actions.x, input) and client-side via actions.x(input). Refuses defineAction without input schema, refuses import from 'zod' inside src/actions/, refuses action named 'apply' outside index.ts. Pairs with astro-actions-and-forms and astro-anti-patterns rules.

Install

npx vskill@latest install roninforge/roninforge-astro/astro-new-action

SKILL.md

The same SKILL.md was published earlier as roninforge/roninforge-astro/astro-new-action.

Scaffold a New Astro Action

When to use

Use when:

  • Adding a server-side mutation (subscribe, login, upload, delete)
  • Wiring an HTML form to a typed handler (accept: 'form')
  • Migrating a hand-rolled API endpoint to a typed action

Target: astro ^6.3.3. The companion astro-actions-and-forms and astro-anti-patterns rules cover the surrounding patterns.

Output

For a subscribe action plus a uploadAvatar action accepting form data:

src/actions/index.ts
ts
import { defineAction, ActionError } from 'astro:actions'
import { z } from 'astro:schema'
export const server = {
subscribe: defineAction({
input: z.object({
email: z.string().email(),
}),
handler: async ({ email }) => {
const exists = await db.subscribers.byEmail(email)
if (exists) {
throw new ActionError({ code: 'CONFLICT', message: 'Already subscribed' })
}
await db.subscribers.insert({ email })
return { ok: true }
},
}),
uploadAvatar: defineAction({
accept: 'form',
input: z.object({
avatar: z.instanceof(File),
userId: z.string(),
}),
handler: async ({ avatar, userId }, ctx) => {
if (!ctx.locals.user || ctx.locals.user.id !== userId) {
throw new ActionError({ code: 'UNAUTHORIZED', message: 'Forbidden' })
}
const bytes = new Uint8Array(await avatar.arrayBuffer())
await storage.put(`avatars/${userId}`, bytes)
return { ok: true }
},
}),
}
Server-side call (.astro frontmatter)
astro
---
import { actions } from 'astro:actions'
let message = ''
if (Astro.request.method === 'POST') {
const data = await Astro.request.formData()
const email = data.get('email')?.toString() ?? ''
const { data: result, error } = await Astro.callAction(actions.subscribe, { email })
message = error ? error.message : 'Subscribed.'
}
---
<form method="POST">
<input name="email" type="email" required />
<button type="submit">Subscribe</button>
</form>
{message && <p>{message}</p>}
Client-side call
ts
import { actions } from 'astro:actions'
const form = document.querySelector<HTMLFormElement>('#subscribe')!
form.addEventListener('submit', async e => {
e.preventDefault()
const data = new FormData(form)
const { data: result, error } = await actions.subscribe({
email: data.get('email')!.toString(),
})
alert(error ? error.message : 'Subscribed.')
})
HTML form with file upload (multipart)
astro
<form method="POST" enctype="multipart/form-data" action={actions.uploadAvatar}>
<input type="hidden" name="userId" value={Astro.locals.user!.id} />
<input type="file" name="avatar" accept="image/*" required />
<button type="submit">Upload</button>
</form>
Reading the result on a static page

Astro.callAction requires per-request server rendering. On a static page (no export const prerender = false), read the result of the previous submit with Astro.getActionResult instead:

astro
---
import { actions } from 'astro:actions'
const result = Astro.getActionResult(actions.subscribe)
---
<form method="POST" action={actions.subscribe}>
<input name="email" type="email" required />
<button type="submit">Subscribe</button>
</form>
{result && !result.error && <p>Subscribed.</p>}
{result?.error && <p class="error">{result.error.message}</p>}

If the page MUST run server logic in its frontmatter on every submit, add export const prerender = false and switch to Astro.callAction.

Workflow

  1. Place the action in src/actions/index.ts under the server namespace.
  2. Always declare an input schema (anti-pattern #3). Import z from astro:schema (anti-pattern #46).
  3. For HTML form posts, set accept: 'form' and use z.instanceof(File) for file inputs.
  4. Throw ActionError with a code (UNAUTHORIZED, BAD_REQUEST, NOT_FOUND, CONFLICT, INTERNAL_SERVER_ERROR) for typed failures.
  5. Pick the right call site:
  • Server frontmatter on an on-demand page: Astro.callAction(actions.x, input).
  • Server frontmatter on a static page: Astro.getActionResult(actions.x) (read-only).
  • Client island: await actions.x(input) returns { data, error }.

Common mistakes

  • No input schema (anti-pattern #3).
  • import { z } from 'zod' instead of astro:schema (anti-pattern #46).
  • File form without enctype="multipart/form-data" (anti-pattern #31).
  • Calling actions.subscribe(input) directly from frontmatter (use Astro.callAction or Astro.getActionResult).
  • Using Astro.callAction on a prerendered page without export const prerender = false (dead code at build time).
  • Action named apply outside index.ts (anti-pattern #44).

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/roninforge/roninforge-astro/astro-new-action/badge)](https://verified-skill.com/skills/roninforge/roninforge-astro/astro-new-action)

Something wrong with this skill or its page? Tell us.