> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getgriffinapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Environments

> Run the same monitors against different deployments

Environments let you deploy the same monitors against different API deployments — for example, staging and production. Each environment has its own variables, secrets, and independent run history.

## How environments work

When you run `griffin init`, a `default` environment is created automatically. You can add more:

```bash theme={null}
griffin env add staging
griffin env add production
```

Each monitor is deployed to a specific environment. The same monitor file can be deployed to multiple environments with different configuration.

## Variables

Variables are stored in `griffin.variables.json` at the project root and are scoped per environment. The file is intended to be checked in so teams can share variable keys and values. Use variables to change values like base URLs between environments:

```bash theme={null}
# Sync variable keys from your monitor files (creates or updates griffin.variables.json)
griffin variables pull

# Set different API hosts per environment
griffin variables add API_HOST=https://api.staging.example.com --env staging
griffin variables add API_HOST=https://api.example.com --env production
```

In your monitor files, reference variables with the `variable()` function:

```typescript theme={null}
import { createMonitorBuilder, GET, Json, variable, Frequency } from "@griffin-app/griffin";

const monitor = createMonitorBuilder({
  name: "health-check",
  frequency: Frequency.every(5).minutes(),
})
  .request("check", {
    method: GET,
    base: variable("API_HOST"),
    response_format: Json,
    path: "/health",
  })
  .build();

export default monitor;
```

When you run `griffin apply staging`, the CLI resolves `variable("API_HOST")` to `https://api.staging.example.com`.

## Secrets

Secrets are also scoped per environment. See [Secrets](/writing-tests/secrets) for details.

```bash theme={null}
griffin secrets set API_KEY --env staging
griffin secrets set API_KEY --env production
```

## Deploying to environments

Most CLI commands accept an environment argument:

```bash theme={null}
# Deploy monitors to staging
griffin apply staging

# Preview changes for production
griffin plan production

# Run a specific monitor in staging
griffin run staging --monitor health-check

# View runs for production
griffin runs production

# View metrics for staging
griffin metrics staging
```

When no environment is specified, commands use the `default` environment.

## Managing environments

```bash theme={null}
# List all environments
griffin env list

# Add an environment
griffin env add <name>

# Remove an environment
griffin env remove <name>
```

<Note>
  Removing an environment locally does not delete monitors already deployed to the hub for that environment. Use `griffin apply <env> --prune` to clean up remote monitors.
</Note>
