Repository navigation
feat(cli): add functions skill topic #7891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Prashansa-K
merged 6 commits into
develop
from
prashansakulshrestha/cli-3303-add-functions-skill-topic
Dec 1, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5ea5b1
feat(cli): add functions skill topic
Prashansa-K 7be393e
docs(cli): fix functions skill topic review findings
Prashansa-K 709f7c1
docs(cli): address review comments on skill topics
Prashansa-K 7b64462
refactor(cli): replace skill topic footer with related topics
Prashansa-K b3c0bfa
refactor(cli): limit related topics to db-query and migrations
Prashansa-K 9cc15d6
docs(cli): address review comments on functions skill topic
Prashansa-K File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| Use this topic for Edge Functions: creating, serving, deploying, and downloading them. Read the overview first (`supabase skill display`) for targeting, credentials, and the approval flow that this topic builds on. | ||
|
|
||
| ## Where things run | ||
|
|
||
| - `functions new` and `functions serve` are local only. They never take `--remote` and never need approval. | ||
| - `functions deploy` and `functions download` are hosted only. They use the linked project, or the one named with `--remote=<ref|branch>`. Deploy changes the hosted project and needs approval (see Deploying). Download only reads the hosted project. | ||
| - Functions live in `supabase/functions/<name>/index.ts`. A name must start with a letter and contain only letters, digits, `_`, and `-`. | ||
|
|
||
| ## Creating a function | ||
|
|
||
| - Run `supabase functions new <name>`. It writes `index.ts`, `deno.json`, and `.npmrc` in `supabase/functions/<name>/` and adds a `[functions.<name>]` entry to the config. If the entry exists already, it is left alone. | ||
| - `--auth` exists only on `functions new` and sets what the template checks: `apikey` (default, callers send an `apikey` header with the publishable key), `user` (also sets `verify_jwt = true`; callers send a user access token), or `none`. Pick it only when the user stated how callers authenticate. It cannot change an existing function. | ||
| - If it fails with "file already exists", the function exists: edit `index.ts` or choose another name. Do not delete the directory to make it succeed. | ||
| - If it rejects the name, fix the name to match the rule above and run the command again with it. | ||
|
|
||
| ## Serving locally | ||
|
|
||
| `functions serve` runs in the foreground until it is stopped, so a plain tool call that waits for it never returns. Stop it with SIGINT or SIGTERM, including during startup: it then removes the runtime it created, or restores the settings of a Functions service that `supabase start` manages. If startup itself fails, see "When something fails". | ||
|
|
||
| - Start it as a background process in your shell tool, or with `nohup supabase functions serve > "$LOG" 2>&1 & echo $!` where `LOG` is a log file outside the repository; keep the printed PID to stop it later. Do not run it in the foreground and interrupt it after a timeout. | ||
| - Make sure the local stack is running first: run `supabase status`, and `supabase start` if it is stopped. | ||
| - Do not treat the first output as readiness. The legacy Docker backend prints "Setting up Edge Functions runtime..." on stderr and then streams the runtime logs. When using the experimental stack backend (`SUPABASE_EXPERIMENTAL_STACK=1`), it prints `Serving Functions at <url>`; with the `stream-json` format it emits a result event holding `instance_id` and `url`. Agents get `stream-json` by default there; JSON output is rejected. | ||
| - Confirm readiness by calling the function you intend to use: `curl -i "<api-url>/functions/v1/<name>"` where the API URL comes from `supabase status`, with the credentials that function requires (for the default template, the header `apikey: <publishable key>` from `supabase status`; for `--auth user`, a signed-in user's access token). Check for the response the function is expected to give. A connection error or a 5xx from the runtime means it is not ready; a 401 means the call lacks valid credentials, not that the function works. | ||
| - It serves every function in `supabase/functions`. Positional function names are accepted but all functions are still served. | ||
| - The legacy backend watches the files and restarts the runtime after edits. The stack backend has no watcher: after editing a function, stop `serve` and start it again. | ||
| - To stop it, run `kill <pid>` (SIGTERM) on the serve process, not the shell that started it. The legacy backend prints `Stopped serving supabase/functions` and removes its container; the stack backend prints nothing on stop. Never use `kill -9`: it can bypass cleanup and leave the runtime or changed settings behind. `supabase stop` also stops the runtime. | ||
| - Under the experimental stack backend, `--import-map`, `--inspect`, `--inspect-mode`, and `--inspect-main` are rejected with a flags error. Remove them. | ||
|
|
||
| ## Secrets and environment | ||
|
|
||
| - Local serve reads `supabase/functions/.env` and `supabase/functions/<name>/.env`. `--env-file <path>` replaces both. After changing an env file, stop `serve` and start it again. | ||
| - Never put secrets in `index.ts`, the config, or a committed file. Use `Deno.env.get("NAME")` in the function. | ||
| - Hosted functions do not read local `.env` files. Set their secrets with `supabase secrets set NAME=<value>` or `supabase secrets set --env-file <path>`, which changes the hosted project and needs approval in the same way as deploy. It also sends any `[edge_runtime.secrets]` from the config. Show the user the project ref and the secret names, including those from the config, with literal values redacted from any command you display. `supabase secrets list` shows names. | ||
| - Deploy does not send secrets. If a deployed function reports a missing variable, show the user which names the code reads and ask before setting them. Never print secret values in your replies. | ||
|
|
||
| ## Deploying to a hosted project | ||
|
|
||
| - Deploy is a hosted change. Unless approval is already present, the first run fails with "Confirmation required: Deploy N Function(s)". The error shows the action, the counts, and usually the target, but not function names or flags. Nothing was deployed. | ||
| - Name the functions to deploy explicitly: the ones the user asked for, or, for a full deploy, the directories in `supabase/functions` that the config does not disable. Show the user the exact command, the project ref, and that list of function names, then ask. If the user named no project, ask which one. | ||
| - After the user approves, re-run the same command with `--yes` added and with `--remote=<ref>` instead of bare `--remote`. Keep the same function names and flags. Leave the function files, `deno.json`, import map, and config unchanged until it finishes; if the list or any of them changed, ask again. If the run succeeds, it is done; never deploy twice. | ||
| - Add `--no-verify-jwt` only when the user asks for a function that is public. It turns off the JWT check for what is deployed. | ||
| - `--prune` deletes every hosted function that is not part of this deploy. With named functions, that is every other hosted function, even one that still exists locally. Use it only when the user asked for it. The error gives only a count ("delete M Functions with --prune"), so before asking, compare `supabase functions list --remote=<ref>` with the functions you are deploying and show the user which hosted functions would be deleted. Before adding `--yes`, check both lists again and ask again if either changed. | ||
| - Deploy bundles with Docker when it is available and falls back to server-side bundling when it is not. `--use-api` skips Docker. `--jobs` (parallel deploys) needs `--use-api` when above 1. | ||
| - `--import-map` points at an import map file. Without it, the function's `import_map` entry in the config is used, then its own `deno.json`. `functions new` writes that entry, so edit both when you change imports. | ||
| - If a deploy fails after approval, read the error before anything else. If it is a bundling error, fix the code or the import and ask the user again before re-deploying. For credential errors, follow the overview. Never re-run unchanged. | ||
|
|
||
| ## Downloading a function | ||
|
|
||
| - `supabase functions download <name>` writes the hosted source into `supabase/functions/<name>/`. Without a name it downloads all functions. It overwrites matching local files, so check `git status` first and commit or back up local edits. | ||
| - If unbundling with Docker fails, run `supabase functions download --use-api <name>`, which unbundles on the server. | ||
|
|
||
| ## When something fails | ||
|
|
||
| - **A stack-backend startup error.** Read the message: | ||
| - "The local stack is not running." Run `supabase status`, then `supabase start`, then start `serve` again in the background. | ||
| - "Standalone Functions instance ... is already active." Another standalone Functions session holds it. The CLI suggests stopping the stack before starting another session: ask the user, run `supabase stop`, then start `serve` again. | ||
| - A Docker inspect error. Ask the user to start Docker. | ||
| - "Enable edge_runtime in <config> before serving Functions." Ask the user before enabling `edge_runtime` in the config, then start `serve` again. | ||
| - **"supabase start is not running." (legacy backend only).** Run `supabase start`, then start `serve` again. | ||
| - **A Docker error from `serve`.** Serve needs Docker: ask the user to start it. Deploy and download print "WARNING: Docker is not running" and fall back to server-side bundling on their own; if a Docker step fails while Docker is running, retry with `--use-api`. | ||
| - **`serve` exits right after starting.** Read its log file for the runtime error, usually a syntax error or a failed import in a function. Fix it, then start again. | ||
| - **A function returns 401.** Two checks can cause it: the runtime's JWT verification (on when `verify_jwt = true`, as in the `user` template) and the handler's own auth check. Read the response body and the serve log to see which one, then check the `withSupabase` auth option in `index.ts` for what the function expects: an `apikey` header with the publishable key, or a signed-in user's access token. Fix the caller. To make the function public, ask the user first, then change the check in `index.ts`, the `verify_jwt` setting in the config, or run `serve` with `--no-verify-jwt` for a local-only fix. On a hosted deploy, `--no-verify-jwt` changes the deployed config. `functions new --auth` cannot change an existing function. | ||
| - **"Confirmation required".** See Deploying. This is the approval step, not a bug. | ||
| - **"Access token not provided" or a project-not-linked error.** Follow "Linking and credentials for `--remote`" in the overview; for bare `--remote` ask the user which project to use and pass `--remote=<ref>`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```bash | ||
| # Alternatives: pick one. | ||
| supabase functions new hello-world | ||
| supabase functions new hello-world --auth user | ||
| supabase functions serve --env-file supabase/functions/.env.local | ||
| supabase functions list --remote="$PROJECT_REF" | ||
| supabase functions deploy hello-world --remote="$PROJECT_REF" | ||
| supabase functions deploy hello-world --use-api --remote="$PROJECT_REF" | ||
| supabase functions download hello-world --remote="$PROJECT_REF" | ||
| supabase secrets set --env-file supabase/functions/.env.production --remote="$PROJECT_REF" | ||
| ``` | ||
|
|
||
| Set `PROJECT_REF` to the real project ref before running the hosted examples. The deploy and secrets commands need the approval flow above first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.