server-actions — Claude Code rule: what it does, how to install
This Claude Code rule guides the choice between Server Actions and API routes for reading or changing data. It applies when an agent writes server-side application logic.
AGPL-3.0 ★ 1,120 updated 2026-11-16
.cursor/rules/server-actions.mdcWhat server-actions does
The rule steers data reads and mutations toward Server Actions rather than API routes. An action is marked with 'use server' at file or function scope.
Actions belong either in an actions.ts file beside their component or in the shared @/actions/ directory. API routes are reserved for external webhooks, REST endpoints required by third-party services, and cases that need explicit control over HTTP headers or status codes.
What it helps with
- choose a server-side approach for fetching data
- handle a mutation with a Server Action
- place actions alongside a component or in a shared folder
- keep an API route for an external webhook
Example prompts for the agent
- Add a server-side action to save settings and choose between Server Actions and API routes.
- Move this data read from an API route to a Server Action.
- Create a webhook endpoint that needs custom HTTP status codes.
How to install server-actions
Manually: put the files in place
.cursor/rules/server-actions.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/server-actions.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/server-actions.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/server-actions.mdManually: put the files in place
.clinerules/server-actions.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about server-actions
How do I install server-actions in Claude Code?
Create .claude/rules/server-actions.md and put the rule in that file.
What does server-actions do?
It guides the agent to use Server Actions for data reads and mutations, while keeping API routes for specific cases.
When does the rule allow API routes?
For external webhooks, REST endpoints required by third-party services, or when HTTP headers and status codes need direct control.