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

# Configuration

> Configure the DealMachine CLI

# Configuration

The CLI stores its configuration at `~/.dealmachine/config.json`. This file is created during `dm login` and contains your credentials and preferences.

## Config File

**Location:** `~/.dealmachine/config.json`

**Permissions:** `0600` (owner-only read/write)

```json theme={null}
{
  "apiKey": "dm_sk_live_xxx",
  "keyId": "key_abc123def456",
  "organizationId": 1,
  "organizationName": "My Company",
  "organizationSlug": "my-company",
  "apiEnvironment": "production"
}
```

## Configuration Values

| Key                | Type   | Editable | Description                                     |
| ------------------ | ------ | -------- | ----------------------------------------------- |
| `apiKey`           | string | No       | Your API key (set during login)                 |
| `keyId`            | string | No       | API key identifier                              |
| `organizationId`   | number | No       | Internal organization ID                        |
| `organizationName` | string | No       | Organization display name                       |
| `organizationSlug` | string | No       | Organization URL slug                           |
| `apiEnvironment`   | string | **Yes**  | API target: `local`, `staging`, or `production` |

## Changing the API Environment

Switch between local development and production:

```bash theme={null}
# Target local API server (http://localhost:3001)
dm config set apiEnvironment local

# Target staging (https://api-staging.v2.dealmachine.com)
dm config set apiEnvironment staging

# Target production (https://api.v2.dealmachine.com)
dm config set apiEnvironment production
```

## Environment Variable Overrides

Environment variables take precedence over config file values:

| Variable                | Priority | Description                         |
| ----------------------- | -------- | ----------------------------------- |
| `DM_API_URL`            | Highest  | Full API base URL                   |
| `DM_ENV`                | Medium   | `local`, `staging`, or `production` |
| Config `apiEnvironment` | Low      | Stored preference                   |
| Default                 | Lowest   | `production`                        |

```bash theme={null}
# One-off local request
DM_ENV=local dm account

# One-off staging request
DM_ENV=staging dm account

# Point to custom server
DM_API_URL=https://api-staging.v2.dealmachine.com/v1 dm account
```

<Note>
  The longer forms `DEALMACHINE_API_URL` and `DEALMACHINE_ENVIRONMENT` also work.
</Note>

## API URL Resolution

| Environment  | URL                                         |
| ------------ | ------------------------------------------- |
| `local`      | `http://localhost:3001/v1`                  |
| `staging`    | `https://api-staging.v2.dealmachine.com/v1` |
| `production` | `https://api.v2.dealmachine.com/v1`         |

## Local Development Setup

If you're working on the DealMachine codebase and want to run the CLI against your local API:

```bash theme={null}
# 1. Set up the database (if you haven't already)
npm run db:setup

# 2. Set up the CLI (generates API key, builds, links `dm`, auto-logs in)
npm run dm:setup
```

Then start the API in another terminal:

```bash theme={null}
npm run api:dev
```

<Note>
  `dm:setup` does not start or manage MySQL — it assumes you've already run `npm run db:setup`. It only generates an API key, builds the CLI, links it globally, and logs you in against `localhost:3001`.
</Note>

## Updating the CLI

<CodeGroup>
  ```bash npm theme={null}
  npm update -g dealmachine
  ```

  ```bash yarn theme={null}
  yarn global upgrade dealmachine
  ```

  ```bash pnpm theme={null}
  pnpm update -g dealmachine
  ```
</CodeGroup>

## Uninstalling

<CodeGroup>
  ```bash npm theme={null}
  npm uninstall -g dealmachine
  ```

  ```bash yarn theme={null}
  yarn global remove dealmachine
  ```

  ```bash pnpm theme={null}
  pnpm remove -g dealmachine
  ```
</CodeGroup>
