# Set up monitoring with Claude Code

> Ask Claude Code to add error and uptime monitoring to your app: it installs the package, keeps the token in .env, sends a test event and checks it arrived.

Claude Code can add monitoring to your app in one session: it installs the package, puts the token in `.env`, sends a test event and checks that it arrived. You stay in charge of three things: which environment it touches, where the secrets go, and who owns the account at the end.

This guide sets up Lampwick, where Claude Code can also create the workspace itself and hand you a link to claim it. The preparation and the checks apply to any monitoring tool.

## Before you start

- **Start on dev or staging.** A monitoring tool receives exception messages, request URLs and log lines. Point the first setup at an environment without customer data, and move to production once you have read the terms and the data processing agreement.
- **Keep `.env` out of git.** Check that `.gitignore` lists it: `git check-ignore .env` prints `.env` when it does.
- **Keep secrets out of the conversation.** Everything Claude Code reads goes into its context. Deny it reading `.env` in `.claude/settings.json`; it can still append to the file with a shell command, which you approve:

```json
{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)"]
  }
}
```

The `deny` rules are in the [Claude Code settings docs](https://code.claude.com/docs/en/settings).

## 1. Give it the prompt

Start `claude` in the repository and paste:

```text
Set up Lampwick monitoring for this app. Read https://lampwick.dev/docs/agents.md and follow it. Keep the tokens out of the chat, use a dev or staging environment, and give me the claim link when the first event has arrived.
```

The [agent setup page](/docs/agents/) is written for agents: exact requests, fields and errors. Pointing Claude Code at it beats describing the steps yourself, because it follows the same page every time.

## 2. Approve the requests

Claude Code asks before each command. Expect these, in this order:

1. A line that adds `.lampwick-workspace.json` to `.gitignore`. Claude Code runs every command in a fresh shell, so the setup passes values on through that file and `.env`.
2. One long command: `curl` to `/api/v1/workspaces/challenge`, a one-line `python3` command that solves a proof-of-work (a few seconds), and `curl -X POST` to `/api/v1/workspaces` with your team and project name and `"agent":"Claude Code"`. It saves the answer, with a workspace token (`lws_…`), an ingest token and a claim link, to `.lampwick-workspace.json` and prints only the workspace's name.
3. A command that appends `LAMPWICK_WORKSPACE_TOKEN` and `LAMPWICK_TOKEN` to `.env`, after adding a final newline if the file lacks one.
4. `composer require lampwick/laravel` and `php artisan lampwick:test`, or a `curl` to `/ingest` for other apps. `lampwick:test` exits 1 while the ingest daemon isn't running; its test record still counts. Then it starts the ingest daemon (`php artisan lampwick:agent`) in this environment and loads a page, so real requests arrive.
5. Optionally `curl -X POST` to `/api/v1/projects/…/monitors` for an uptime check of your staging URL.
6. `curl` to `/api/v1/setup-status`, until it says `"ready_to_hand_off": true`.

Say no when a command prints a token to the terminal, or writes one anywhere but `.env` and `.lampwick-workspace.json`. Ask it to redo the step.

## 3. Check its work

Don't take "done" on trust. `getSetupStatus` answers with what Lampwick actually received:

```json
{
  "ready_to_hand_off": true,
  "blocking": [],
  "next_action": "Give your human the claim link with the text of handoff_message.",
  "projects": [{ "id": 3, "name": "acme-web", "first_event_at": "2026-11-09T17:40:47.648610Z", "last_deploy_at": null }]
}
```

Run on 9 Nov 2026 against a Lampwick server. `first_event_at` is set only when a record arrived. Until then `blocking` says `no events yet from acme-web`, and Claude Code should fix that before it hands off.

## 4. Claim the workspace

Claude Code ends with a message like this one, from `handoff_message`:

```text
Lampwick is set up for Acme. Open this link to put it in your name: https://app.lampwick.dev/claim/lwc_… — claim it before Thu 12 Nov, 17:40 UTC, or it stops and is deleted.
```

1. Open the link. It shows who set the workspace up, what it holds and when it is deleted. Claim it only if you asked for it.
2. Log in or create an account, then click **Claim workspace**.
3. Choose **Read-only (recommended)** or **Read & write**, click **Show code for the agent**, and paste the code into Claude Code. It sends it with `confirmWorkspaceAccess`.

Read-only is the safer choice for an agent that reads production errors: those messages can contain text meant to steer it. The agent keeps the access you chose for 30 days, then connects by signing in. No code within 15 minutes means it loses access, and Lampwick replaces the ingest tokens.

## 5. Go to production

Once the workspace is yours:

- Run the ingest daemon under a process manager: `php artisan lampwick:agent` ([Laravel docs](/docs/laravel/)).
- Set `LAMPWICK_TOKEN` in production's environment, not in a committed file.
- Record each deploy from CI with `php artisan lampwick:deploy` (it uses the same `LAMPWICK_TOKEN`), so every issue shows the deploy that brought it.
- Turn on [alerts](/docs/alerts/). An agent can't do that for you: alert channels, status pages and billing stay with people.

## Next step

Now let Claude Code read what breaks: [debug Laravel production errors with Claude Code](/guides/debug-laravel-production-errors-with-claude-code/).
