# CLI commands

The binary is `rebate`. Running it with no subcommand starts the interactive onboarding.

| Command | What it does |
| --- | --- |
| `rebate` | Interactive onboarding: detect Claude Code and Codex, get consent, back up settings/hooks, patch supported tools, and enable sponsored footers. `-y`/`--yes` skips prompts. |
| `rebate on` | Same as `rebate`. Also accepts `-y`/`--yes` and `--dry-run`. |
| `rebate plan` | Show exactly which files and keys `rebate on` would change without mutating anything. |
| `rebate doctor` | Diagnose auth, device, Claude settings, Codex hooks/launcher, prompt refresh hooks, latest sponsor, and update state with repair commands. Also refreshes the signed update manifest and warns when this CLI should be updated. |
| `rebate status` | Show on/off state, auth, device id if one exists, latest sponsor, dashboard URL, and any cached update warning. |
| `rebate dashboard` | Open the Rebates earnings dashboard. |
| `rebate open` | Open the current sponsor in your browser. |
| `rebate off` | Remove Rebate-owned Claude Code settings, remove Rebate-owned Codex hooks, restore the original Codex launcher, and restore previous values for keys Rebate touched. `--purge` also removes local Rebate credentials, device id, cache, and update state. |
| `rebate update` | Show update mode/channel and available-version state. |
| `rebate update auto\|notify\|manual\|off` | Set the background updater mode. |
| `rebate upgrade` | Check for and install the latest signed Rebate release now. |

Hidden subcommands exist for the integrations themselves: `rebate session-start`,
`rebate refresh`, `rebate turn-end`, and `rebate statusline` are Claude Code
entrypoints; `rebate codex-prompt` and `rebate __exec-codex` are Codex
entrypoints. You never need to run them yourself. `rebate display` remains only
as a no-output migration shim for old Claude settings and is not installed by
current onboarding.

Use `rebate plan` before first install or after hand-editing tool config. It
prints the Claude settings path, Codex hooks path, Codex launcher restore path,
backup paths, `/ad` command path, credential store, and latest sponsor snapshot
before anything is changed. In scripts, `rebate on --dry-run` is the same
preview.

## The `/ad` slash command

Onboarding installs one Claude Code command file at `~/.claude/commands/ad.md`. Typing `/ad` inside a Claude Code session runs `rebate open`, which opens the current sponsor link in your browser. This works from any terminal, including ones that do not render hyperlinks. `rebate off` removes the file.

## What gets written to Claude Code settings

Rebate writes these Claude Code settings:

```json
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [{ "type": "command", "command": "rebate session-start", "timeout": 3 }]
      }
    ],
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [{ "type": "command", "command": "rebate refresh", "timeout": 8 }]
      }
    ],
    "Stop": [
      {
        "hooks": [{ "type": "command", "command": "rebate turn-end", "timeout": 3 }]
      }
    ]
  },
  "statusLine": {
    "type": "command",
    "command": "rebate statusline"
  },
  "spinnerVerbs": { "mode": "replace", "verbs": ["<latest real ad text>"] },
  "env": { "FORCE_HYPERLINK": "1" }
}
```

`spinnerVerbs` is written only when Rebate has a real sponsor. If the API no-fills, requires login, or times out, Rebate clears its sponsor snapshot and renders no sponsored footer or placeholder spinner text.

`FORCE_HYPERLINK` is the documented override for the `supports-hyperlinks` package, whose terminal allowlist misses several hyperlink-capable terminals; without it OSC 8 footer links may not reach the terminal. A first-install backup is written to `settings.json.rebate-backup` before the first patch so `rebate off` can restore previous values for keys Rebate touched.

## What gets written to Codex

Rebate writes one prompt hook to `~/.codex/hooks.json`:

```json
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [{ "type": "command", "command": "rebate codex-prompt", "timeout": 8 }]
      }
    ]
  }
}
```

Rebate also replaces the detected `codex` launcher path with a Rebate-owned shim
that records restore metadata under `~/.rebate/codex-launcher.json`.
Noninteractive Codex commands pass through to the real Codex binary. Interactive
Codex sessions run the real Codex TUI through `rebate __exec-codex`, which draws
the current sponsor in the footer row.

## Local files

| Path | Contents |
| --- | --- |
| `~/.rebate/device` | Your local device id (a random UUID, claimed to your account after login) |
| `~/.rebate/credentials.json` | Device-flow bearer tokens, stored per API origin |
| `~/.rebate/ad.json` | Latest sponsor snapshot fetched for the current prompt |
| `~/.rebate/config.json` | Rebate-owned update preferences |
| `~/.rebate/codex-launcher.json` | Restore metadata for the Rebate-owned Codex launcher shim |
| `~/.claude/settings.json.rebate-backup` | Byte-exact backup of your original settings |
| `~/.claude/commands/ad.md` | The `/ad` slash command |
| `~/.codex/hooks.json.rebate-backup` | Byte-exact backup of your original Codex hooks file |

## Environment overrides

| Variable | Purpose |
| --- | --- |
| `REBATE_API_URL` | Where to fetch ads and build earnings links (default `https://app.rebates.ai`) |
| `REBATE_SETTINGS_PATH` | The settings file to patch (for `claude --settings <file>`) |
| `REBATE_CLAUDE_DIR` | Claude Code's config dir (default `~/.claude`) |
| `REBATE_CODEX_DIR` | Codex config dir (default `CODEX_HOME`, then `~/.codex`) |
| `REBATE_CODEX_HOOKS_PATH` | Codex hooks file to patch |
| `REBATE_CODEX_LAUNCHER_PATH` | Codex launcher path to patch |
| `REBATE_DIR` | Rebates state dir (default `~/.rebate`) |
| `REBATE_PROMPT_REFRESH_CMD` | The command string written into `hooks.UserPromptSubmit` |
| `REBATE_CODEX_PROMPT_CMD` | The command string written into Codex `hooks.UserPromptSubmit` |
| `REBATE_AD_COMMAND_PATH` | Where the `/ad` command file is written |
| `REBATE_HTTP_TIMEOUT_MS` | Ad-fetch timeout in milliseconds (default 4000) |
| `REBATE_UPDATE_MODE` | One-run update mode override: `auto`, `notify`, `manual`, or `off` |
| `REBATE_NO_UPDATE` | Hard off-switch for update checks |
| `REBATE_LOCAL_DEV_API_BASE` | Local API origin probed by the source-backed development shim |

## Testing hidden commands directly

You can exercise the hidden command entrypoints directly with fixture JSON:

```bash
echo '{"session_id":"demo"}' | rebate statusline
echo '{"hook_event_name":"Stop","session_id":"demo"}' | rebate turn-end
echo '{"hook_event_name":"UserPromptSubmit","session_id":"demo"}' | rebate codex-prompt
```
