`astro dev --background` silently drops `--mode` (and `--site`, `--base`, `--out-dir`, `--verbose`, `--silent`, `--open`)
pkg: astro- P4: importanttriage: fix verified
### Astro Info
```block
Astro v7.2.4
Vite v8.1.2
Node v26.4.0
System Linux (x64)
Package Manager npm
Output static
Adapter none
Integrations @astrojs/sitemap (v3.7.3)
```
### If this issue only occurs in one browser, which browser is a problem?
_No response_
### Describe the Bug
When the dev server runs in the background — either via `--background`, or automatically because Astro detected an AI agent environment — the flags passed on the command line are not all forwarded to the spawned child process. The server starts successfully and reports no warning, but runs with different configuration than was asked for.
`--mode` is the most damaging one, because it silently changes which `.env.[mode]` file is loaded. A project that uses `astro dev --mode staging` to point at a staging API gets the default `.env` instead, with no indication anything was ignored.
This also affects `astro preview --background`, which shares the same argv builder.
**Cause:** `buildBackgroundArgs()` in `packages/astro/src/cli/server.ts` reconstructs the child's argv from a fixed allowlist instead of forwarding the parsed flags:
```js
function buildBackgroundArgs(command, flags) {
const args = [command];
if (flags.port) args.push("--port", String(flags.port));
if (flags.host != null) { /* ... */ }
if (flags.config) args.push("--config", String(flags.config));
if (flags.root) args.push("--root", String(flags.root));
if (flags.allowedHosts) args.push("--allowed-hosts", String(flags.allowedHosts));
if (flags.json) args.push("--json");
return args;
}
```
Comparing that against `flagsToAstroInlineConfig()` in `packages/astro/src/cli/flags.ts`, which is what the child eventually applies, these supported flags are silently lost: **`--mode`, `--site`, `--base`, `--out-dir`, `--verbose`, `--silent`, `--open`**. (`--force` and `--ignore-lock` are consumed by the parent, so those are fine.)
The agent-detection path makes this easy to hit without opting in: in `packages/astro/src/cli/dev/index.ts`, `agentDetected` (via `am-i-vibing`) routes to the background path with no `--background` flag present, so anyone running Astro under an AI coding agent gets background mode — and flag loss — by default.
### What's the expected result?
Flags accepted by `astro dev` should behave identically in foreground and background. Either forward every flag that `flagsToAstroInlineConfig()` reads, or error out when a flag that cannot be forwarded is passed, rather than starting a server that silently ignores it.
### Link to Minimal Reproducible Example
https://github.com/aheckerling/astro-mode-background-repo
### Participation
- [x] I am willing to submit a pull request for this issue.
3 条评论