# Set up tollbar: instructions for a coding agent

You are a coding agent (Claude Code or similar) helping a person install **tollbar** on this machine. Follow the steps in order. After each step, tell the person what happened in plain words and in their language. Ask before anything that changes a repository.

## What tollbar is

- A code review CLI that runs on this machine, against local git repos. It needs no account, has no server, and never connects to GitHub or any other remote.
- It runs deterministic rules first, then reviews the logic with the AI the person already has.
- With **Claude Code** installed and logged in, tollbar uses it automatically (`provider: claude-cli`). That includes personal, Team and Enterprise accounts, and Bedrock, Vertex or gateway setups.
- npm package: `@ernestojost/tollbar`. Command: `tollbar`. Requires Node.js 20+ and git.
- Full docs: https://github.com/ernestojost/tollbar#readme

## Ground rules

- Don't commit anything to the person's repositories. Everything below lives outside the repo or in files git ignores (the one exception is the GitHub workflow of the `ci` profile, which the person commits themselves).
- Don't change company-managed settings, proxies or security tools, and don't try to get around a block. If something is blocked, stop and explain what failed.
- Never put tokens or keys in any file or command.

## 1. Check the machine

Run each of these:

```
node -v
git --version
claude --version
```

- `node -v` must be 20 or higher. If Node is missing or older, stop and tell the person. Don't install Node on a company machine without asking.
- If `claude` is missing, tollbar uses `ANTHROPIC_API_KEY` when it is set; otherwise it works with rules only (no AI). Tell the person which one applies.

## 2. Install

```
npm install -g @ernestojost/tollbar
tollbar --version
```

If the install fails, stop and show the person the error. Typical causes are a company proxy or a blocked public registry. Check `npm config get registry`: many companies use an internal npm mirror, and the person may need to ask for the package there.

## 3. Ask the person two questions

Ask in their language and wait for the answers.

1. **Where will they use tollbar?**
   - `personal`: their own machine and projects.
   - `work`: a work machine. Nothing is added to the repo: the settings stay in `~/.tollbar/config.yml`, the Claude Code hook goes to `.claude/settings.local.json` (ignored by git), false alarms are kept inside `.git`, and imported package names are never looked up on the public npm registry (so internal names don't leave the machine).
   - `ci`: only GitHub Actions. It adds `.github/workflows/tollbar.yml`, which the person commits.
2. **When should it review?** Any combination:
   - `pre-push`: before every `git push` from this repo. If something serious shows up, the push stops. `pre-push:ai` also reviews the logic (15 to 40 seconds per push); `pre-push:rules` takes under a second.
   - `claude-stop`: when Claude Code finishes a task, so the agent fixes serious problems before saying "done". `claude-stop:rules` by default; `claude-stop:ai` also reviews the logic.
   - `deploy`: prints the lines for the person's deploy script; it installs nothing.
   - `none`: only when the person runs `tollbar review`.

Don't ask about the AI unless the person wants something other than Claude Code: tollbar uses Claude Code when it is installed (`--ai claude-cli`). For an API key, pass `--ai anthropic` (or `openai`, `openrouter`, `gemini`) with `--model <model>`, and `--api-key-env <NAME>` if the key lives in a variable with another name. Only the variable's name is written, never the key.

## 4. Show the plan, then apply it

In the repo the person named, with their answers (example for a work machine):

```
cd <repo>
tollbar setup --print --profile work --hooks pre-push:ai,claude-stop:rules
```

`--print` writes nothing: it shows what would change. Show it to the person. If they agree, run the same command with `--yes` instead of `--print`:

```
tollbar setup --yes --profile work --hooks pre-push:ai,claude-stop:rules
```

`tollbar setup --help` lists every option. If `tollbar setup` answers "Unknown command", the installed tollbar is too old: `npm install -g @ernestojost/tollbar@latest`.

Safety notes:

- **`core.hooksPath`:** if the repo sends its hooks to another folder (for example `.husky`, which is usually committed), setup doesn't install the pre-push hook and says why. Ask the person before running it again with `--allow-hooks-path`, because the hook would become part of the repo.
- **An existing pre-push hook:** setup never overwrites a hook that isn't tollbar's. It prints one line to add to that hook; ask the person before adding it.
- **`.claude/settings.local.json`:** with the work profile (or `--local`), setup adds it to `.git/info/exclude` if git doesn't ignore it already. Check it:

  ```
  git check-ignore -q .claude/settings.local.json && echo ignored
  ```

  If it doesn't print `ignored`, tell the person, so the file isn't committed by accident.
- **No questions without a terminal:** without `--yes` or `--print`, `tollbar setup` asks its questions on the terminal. When there is none (as when an agent runs it), it prints the options and exits with code 2 without changing anything. Always pass `--yes` or `--print`.

## 5. Check it

```
tollbar status
```

It shows the settings in use, the AI and whether it was found, where the code goes, which hooks are installed and where, and the deploy mark. Exit code 1 means something is broken; the output says what.

To test the AI with a real call, ask the person first (it spends a few tokens of their account):

```
tollbar status --check
```

If the test fails with `claude-cli`, run `claude -p "reply with ok"`.
- If that fails too, Claude Code isn't logged in or can't run non-interactively. Tell the person: they may need to run `claude` and log in, or company policy may not allow it.
- If it works, show the person the tollbar error.

## 6. First review (read-only)

```
tollbar review
```

This reviews uncommitted changes, or the last commit if there are none. It doesn't modify any file in the repo.

Check the last line of the output:

- **`AI: claude-cli (...)`**: the AI review works.
- **`no AI (rules only)`** or an error: go back to the test in step 5.

## 7. Wrap up

Tell the person:

- **What was installed and where:** the global npm package, `~/.tollbar/config.yml`, and the hooks `tollbar status` lists.
- **How to review on demand:**
  - `tollbar review`: uncommitted changes, or the last commit.
  - `tollbar review --base origin/main`: everything the branch adds.
- **How to skip one push:** `git push --no-verify`.
- **How to silence a false alarm:** `tollbar ignore <n> --reason "why"`. With the work profile it stays inside `.git`; otherwise it writes `.tollbar/learnings.md` inside the repo, and the person decides whether to commit it.
- **How to change it:** run `tollbar setup` again (or `tollbar setup --yes` with other options). In another repo, the same command installs the hooks there.
- **How to take the hooks out:** `tollbar hook uninstall --git` (pre-push) and `tollbar hook uninstall --local` (Claude Code; without `--local` for `.claude/settings.json`). Only tollbar's own hooks are removed.
