CLI
Alchemy doesn’t have a traditional CLI tool like wrangler
or terraform
because it’s designed to be an embeddable TypeScript library. Instead, it provides automatic CLI argument parsing when you initialize an alchemy application, making it easy to run your infrastructure scripts with common options.
No CLI, but CLI Arguments
Section titled “No CLI, but CLI Arguments”Rather than building a separate CLI tool, Alchemy automatically parses CLI arguments when you call:
const app = await alchemy("my-app");
This design choice keeps Alchemy simple while still providing the convenience of CLI arguments for common operations.
Supported Arguments
Section titled “Supported Arguments”Phase Control
Section titled “Phase Control”Control what phase your infrastructure script runs in:
# Deploy/update resources (default)bun ./alchemy.run
# Read-only mode - doesn't modify resourcesbun ./alchemy.run --read
# Destroy all resourcesbun ./alchemy.run --destroy
# Deploy/update resources (default)npx tsx ./alchemy.run
# Read-only mode - doesn't modify resourcesnpx tsx ./alchemy.run --read
# Destroy all resourcesnpx tsx ./alchemy.run --destroy
# Deploy/update resources (default)pnpm tsx ./alchemy.run
# Read-only mode - doesn't modify resourcespnpm tsx ./alchemy.run --read
# Destroy all resourcespnpm tsx ./alchemy.run --destroy
# Deploy/update resources (default)yarn tsx ./alchemy.run
# Read-only mode - doesn't modify resourcesyarn tsx ./alchemy.run --read
# Destroy all resourcesyarn tsx ./alchemy.run --destroy
Learn more about phases in the phase concepts guide.
Output Control
Section titled “Output Control”Control logging output:
# Quiet mode - suppress Create/Update/Delete messagesbun ./alchemy.run --quiet
# Quiet mode - suppress Create/Update/Delete messagesnpx tsx ./alchemy.run --quiet
# Quiet mode - suppress Create/Update/Delete messagespnpm tsx ./alchemy.run --quiet
# Quiet mode - suppress Create/Update/Delete messagesyarn tsx ./alchemy.run --quiet
Environment Control
Section titled “Environment Control”Specify which stage/environment to target:
# Deploy to a specific stagebun ./alchemy.run --stage productionbun ./alchemy.run --stage stagingbun ./alchemy.run --stage dev
# Deploy to a specific stagenpx tsx ./alchemy.run --stage productionnpx tsx ./alchemy.run --stage stagingnpx tsx ./alchemy.run --stage dev
# Deploy to a specific stagepnpm tsx ./alchemy.run --stage productionpnpm tsx ./alchemy.run --stage stagingpnpm tsx ./alchemy.run --stage dev
# Deploy to a specific stageyarn tsx ./alchemy.run --stage productionyarn tsx ./alchemy.run --stage stagingyarn tsx ./alchemy.run --stage dev
By default, the stage is set to process.env.USER
(your username). You can also use ALCHEMY_STAGE
or PASSWORD
environment variables to control staging behavior.
Secret Management
Section titled “Secret Management”Provide encryption password via environment variable:
# Set password for encrypting/decrypting secretsALCHEMY_PASSWORD=my-secret-key bun ./alchemy.run
# Set password for encrypting/decrypting secretsALCHEMY_PASSWORD=my-secret-key npx tsx ./alchemy.run
# Set password for encrypting/decrypting secretsALCHEMY_PASSWORD=my-secret-key pnpm tsx ./alchemy.run
# Set password for encrypting/decrypting secretsALCHEMY_PASSWORD=my-secret-key yarn tsx ./alchemy.run
How It Works
Section titled “How It Works”When you call alchemy("my-app")
, it automatically:
- Parses
process.argv
for supported arguments - Merges CLI options with any explicit options you provide
- Explicit options always take precedence over CLI arguments
// CLI args are parsed automaticallyconst app = await alchemy("my-app");
// Explicit options override CLI argsconst app = await alchemy("my-app", { phase: "up", // This overrides --destroy or --read stage: "prod", // This overrides --stage quiet: false, // This overrides --quiet});
Environment Variables
Section titled “Environment Variables”Alchemy also supports these environment variables:
ALCHEMY_PASSWORD
- Password for encrypting/decrypting secretsALCHEMY_STAGE
- Default stage nameUSER
- Fallback for stage name (uses your username)
Complete Example
Section titled “Complete Example”Here’s how you might use CLI arguments in practice:
import alchemy from "alchemy";import { Worker } from "alchemy/cloudflare";
const app = await alchemy("my-app");
const worker = await Worker("api", { script: "export default { fetch() { return new Response('Hello'); } }",});
console.log({ url: worker.url });
await app.finalize();
Deploy commands:
# Deploybun ./alchemy.run
# Deploy to Productionbun ./alchemy.run --stage production
# Read-only Checkbun ./alchemy.run --read
# Quiet Deploybun ./alchemy.run --quiet
# Destroy Everythingbun ./alchemy.run --destroy
# Deploy with SecretsALCHEMY_PASSWORD=my-secret-key bun ./alchemy.run
# Deploynpx tsx ./alchemy.run
# Deploy to Productionnpx tsx ./alchemy.run --stage production
# Read-only Checknpx tsx ./alchemy.run --read
# Quiet Deploynpx tsx ./alchemy.run --quiet
# Destroy Everythingnpx tsx ./alchemy.run --destroy
# Deploy with SecretsALCHEMY_PASSWORD=my-secret-key npx tsx ./alchemy.run
# Deploypnpm tsx ./alchemy.run
# Deploy to Productionpnpm tsx ./alchemy.run --stage production
# Read-only Checkpnpm tsx ./alchemy.run --read
# Quiet Deploypnpm tsx ./alchemy.run --quiet
# Destroy Everythingpnpm tsx ./alchemy.run --destroy
# Deploy with SecretsALCHEMY_PASSWORD=my-secret-key pnpm tsx ./alchemy.run
# Deployyarn tsx ./alchemy.run
# Deploy to Productionyarn tsx ./alchemy.run --stage production
# Read-only Checkyarn tsx ./alchemy.run --read
# Quiet Deployyarn tsx ./alchemy.run --quiet
# Destroy Everythingyarn tsx ./alchemy.run --destroy
# Deploy with SecretsALCHEMY_PASSWORD=my-secret-key yarn tsx ./alchemy.run