Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 7006ec4

Browse files
new guide
1 parent 5dff046 commit 7006ec4

7 files changed

Lines changed: 308 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ site/resources/
1111
__checks__/screenshots
1212
.vercel
1313
checkly-github-report.md
14+
CLAUDE.md
118 KB
Loading
70.8 KB
Loading
156 KB
Loading
271 KB
Loading
243 KB
Loading
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
---
2+
title: Add in Depth Monitoring With Checkly and Claude Code
3+
description: >-
4+
By integrating AI into your development workflow, you can generate valid Checkly constructs—including URL monitors and Playwright-based browser checks—with minimal effort.
5+
author: Nočnica Mellifera
6+
avatar: 'images/avatars/nica-mellifera.png'
7+
tags:
8+
- FAQ
9+
- AI
10+
---
11+
AI-assisted coding promises to massively upgrade developer productivity, and with Checkly’s model of [Monitoring as Code](https://www.checklyhq.com/blog/monitoring-as-code-in-your-sdlc/), you can create monitoring coverage for all your services in minutes instead of days. This guide will show you how to create an AI development environment that lets you create and deploy all types of Checkly monitoring.
12+
13+
## Setup
14+
15+
If you haven’t already, start by [installing the Checkly CLI](https://www.checklyhq.com/docs/cli/installation/), then create a repository that will be the ‘project’ that contains all your Checkly monitors managed as code. If you don’t already have a project, create one with:
16+
17+
```bash
18+
npm create checkly@latest
19+
```
20+
21+
If you’d like to follow the tutorial examples below, clone the [uptime monitoring demo](https://github.com/serverless-mom/uptimeMonitoring) repository, and copy everything in the `/**__checks__`** folder to your own project.
22+
23+
Next, install [Claude Code](https://www.anthropic.com/claude-code) globally with
24+
25+
```bash
26+
npm install -g @anthropic-ai/claude-code
27+
```
28+
29+
and from the root folder of your project and start Code with the `claude` command.
30+
31+
You’ll be prompted to sign in to or sign up for an Anthropic account.
32+
33+
I recommend using [the Visual Studio Code plugin for Claude](https://marketplace.visualstudio.com/items?itemName=anthropic.claude-code), which will make it easier to connect Claude Code with the VS Code file browser with Claude’s context (the VS Code plugin does a lot more than just context, this is just the most convenient feature we’ll use for this tutorial).
34+
35+
Optionally, from the Claude Code prompt, run `/init` to scan your project and create an initial `CLAUDE.md` context file.
36+
37+
### Add the Playwright MCP
38+
39+
You can give Claude Code access to a browser by adding the [Playwright MCP](https://github.com/microsoft/playwright-mcp) to your local configuration with
40+
41+
```bash
42+
claude mcp add playwright npx @playwright/mcp@latest
43+
```
44+
45+
## Give Claude Code Some Context
46+
47+
To create your Checkly monitoring, you want Claude Code to create files and updates that make sense as a [Checkly construct](https://www.checklyhq.com/docs/cli/constructs-reference/). Let’s add [Checkly’s AI rules file](https://www.checklyhq.com/docs/ai/use-checkly-with-ai-ide/) to our [CLAUDE.md](http://CLAUDE.md) context file:
48+
49+
```bash
50+
mkdir -p .claude &&
51+
curl -o .claude/checkly.rules.md https://www.checklyhq.com/docs/ai/checkly.rules.md -L
52+
echo "- examine checkly.rules.md for code generation rules" >> .claude/CLAUDE.md
53+
```
54+
55+
After this you’ll need to exit and restart Claude Code for it to pick up changes to our context file.
56+
57+
## Create new URL Monitors
58+
59+
We’ll start with something easy. A URL monitor that will check an HTTP endpoint and alert if it doesn’t receive the right status code. With the context set from the section above, try a command like:
60+
61+
> Create a new URL pinger for the site [https://danube-webshop.herokuapp.com/](https://danube-webshop.herokuapp.com/) that runs every five minutes and doesn’t follow redirects
62+
63+
After a few seconds, Claude Code will produce this:
64+
65+
```ts
66+
import { Frequency, UrlMonitor, UrlAssertionBuilder } from 'checkly/constructs'
67+
68+
new UrlMonitor('danube-web-shop-pinger', {
69+
frequency: Frequency.EVERY_5M,
70+
name: 'Danube Web Shop Pinger',
71+
activated: true,
72+
request: {
73+
url: 'https://danube-web.shop/',
74+
skipSSL: false,
75+
followRedirects: true,
76+
assertions: [
77+
UrlAssertionBuilder.statusCode().equals(200),
78+
]
79+
}
80+
})
81+
```
82+
83+
While we’re writing this simplest of monitors, it’s worth testing the limits of Claude Code’s context for writing valid Checkly configuration. One thing I tested while writing this article was whether picking the wrong prompt would result in invalid Checkly construct code. The Frequency class here doesn’t accept arbitrary values, so I wondered what would happen since the [source file for Frequency](https://github.com/checkly/checkly-cli/blob/main/packages/cli/src/constructs/frequency.ts) won’t be part of Claude’s context. I tried requesting a check that ran “every 17 seconds” and Claude Code prompted me to run a `find` on the project to identify valid values for `frequency`. In the end, Claude Code did create valid code with this note in the process feed.
84+
85+
![Feedback on the terminal](/guides/images/claude-monitoring-01.png)
86+
87+
88+
89+
## Create Playwright Synthetics checks with Claude Code
90+
91+
It would be nice to have Claude Code automatically create the Playwright scripts we need to test our site's features. However, without careful controls, any 2025-era coding agent tends to write Playwright code that is either out of date or doesn’t follow best practices. The best way to get high-quality output is through some prompt engineering and careful provision of context.
92+
93+
### 1. Create at least one test with Playwright Codegen
94+
95+
We can capture our behavior in the browser to script a test with [Playwright Codegen](https://www.checklyhq.com/learn/playwright/codegen/), available either as a standalone utility, browser plugin, or VS Code plugin. Once [Codegen is set up](https://www.checklyhq.com/learn/playwright/codegen/), start recording and record the following:
96+
97+
- Navigate to your homepage.
98+
- Browse through multiple pages.
99+
- Assert the visibility of 1-2 page elements.
100+
101+
Once you’re done, copy the resulting code and create a file in `/__checks__` called `homepage-browse.spec.ts`. It should look something like this:
102+
103+
```ts
104+
//homepage-browse.spec.ts
105+
import { test, expect } from '@playwright/test';
106+
107+
test('test', async ({ page }) => {
108+
await page.goto('https://danube-web.shop/');
109+
await page.getByText('Haben oder haben').click();
110+
await page.getByRole('button', { name: 'Add to cart' }).click();
111+
await page.getByRole('link').click();
112+
await page.locator('a').filter({ hasText: 'Fantasy' }).click();
113+
await expect(page.getByText('The Polar Turtle')).toBeVisible();
114+
await expect(page.getByText('$9').first()).toBeVisible();
115+
});
116+
```
117+
118+
Lets make sure our script is valid by running this test:
119+
120+
```bash
121+
npx checkly test homepage-browse
122+
```
123+
124+
*Without an exact file path, the `checkly test` command will run any test that matches this pattern.*
125+
126+
and making sure the test passes.
127+
128+
![Feedback on the terminal](/guides/images/claude-monitoring-02.png)
129+
130+
*Like always with the `checkly test` command, this test isn’t running from my laptop but rather the real Checkly network!*
131+
132+
Next we’ll want to create a `.check.ts` file for this browser check, which sets some check-specific settings and assigns the check’s logical ID.
133+
134+
```ts
135+
//homepage-browse.check.ts
136+
import { AlertChannel, AlertEscalationBuilder, BrowserCheck, RetryStrategyBuilder } from 'checkly/constructs'
137+
138+
new BrowserCheck('browse-danube-homepage-v1', {
139+
name: 'Browse Danube Homepage',
140+
code: {
141+
entrypoint: './homepage-browse.spec.ts',
142+
},
143+
activated: true,
144+
muted: false,
145+
shouldFail: false,
146+
locations: [
147+
'us-east-1',
148+
'us-west-1',
149+
],
150+
frequency: 5,
151+
alertEscalationPolicy: AlertEscalationBuilder.runBasedEscalation(1, {
152+
amount: 0,
153+
interval: 5,
154+
}, {
155+
enabled: false,
156+
percentage: 10,
157+
}),
158+
retryStrategy: RetryStrategyBuilder.linearStrategy({
159+
baseBackoffSeconds: 60,
160+
maxRetries: 2,
161+
maxDurationSeconds: 600,
162+
sameRegion: true,
163+
}),
164+
runParallel: true,
165+
})
166+
```
167+
168+
These settings are all optional and any not specified will default back to the account or project default, but it’s good to include them as our model.
169+
170+
If we want to check our formatting, we can run the `checkly deploy` command with the preview flag:
171+
172+
```bash
173+
npx checkly deploy -p
174+
```
175+
176+
### 2. Add our new Check to Claude’s context
177+
178+
With these checks created, add their references to Claude’s context by giving Claude Code the prompt:
179+
180+
> update my [CLAUDE.md](http://claude.md/) file with the new code in /__checks__
181+
>
182+
183+
Let’s take one additional step, add the following lines to your updated [CLAUDE.md](http://CLAUDE.md) file:
184+
185+
```markdown
186+
- When writing Playwright, don't set locators equal to const, rather just perform expect tests directly on locators
187+
- When writing a spec.ts file, don't use locators based on CSS class
188+
```
189+
190+
pro tip: from the Claude Code prompt just hit octothorp ‘#’ to add to Claude’s memory
191+
192+
### 3. Use Claude Code to create new checks
193+
194+
Now that we’ve got a working test and config, let’s let Claude Code create a check for us:
195+
196+
> Create a new browser check for [https://danube-web.shop/](https://danube-web.shop/) that clicks on a single button then checks the visibility of 10 different elements on
197+
the page
198+
>
199+
200+
The importance of step 1 above is apparent during the output from this task, as Claude Code examines the known good
201+
202+
![Feedback on the terminal](/guides/images/claude-monitoring-03.png)
203+
204+
In order to scan the URL provided, Claude Code will confirm that it can use the Playwright MCP to open a browser and access the site. The result is a nice clean test written to the spec:
205+
206+
```ts
207+
//item-visibility.spec.ts
208+
import { test, expect } from '@playwright/test';
209+
210+
test('item visibility check', async ({ page }) => {
211+
await page.goto('https://danube-web.shop/');
212+
213+
// Click on the "Books" heading
214+
await page.getByRole('heading', { name: 'Books', exact: true }).click();
215+
216+
// Check visibility of 10 different items on the page
217+
await expect(page.getByText('Haben oder haben')).toBeVisible();
218+
// removed 6 more for readability
219+
await expect(page.getByText('Fantasy')).toBeVisible();
220+
await expect(page.getByText('$9.95').first()).toBeVisible();
221+
await expect(page.getByRole('heading', { name: 'Top sellers' })).toBeVisible();
222+
});
223+
```
224+
225+
Claude Code will confirm before creating the check and spec files with the configuration and script, respectively.
226+
227+
You can prompt for multiple checks at the same time, as the output is relatively token-efficient. As you can imagine, this unlocks the creation of a large number of synthetic monitors relatively quickly. Another use case that may be useful for larger projects, try prompting Claude Code with something like:
228+
229+
>
230+
>
231+
>
232+
> update every `.check.ts` file for a check that touches [danube-web.shop](http://danube-web.shop/), and change
233+
> the frequency to every 30 minutes.
234+
>
235+
236+
Not only did this request work, but I even got sensible feedback about the checks that currently had no frequency setting:
237+
238+
```bash
239+
The url.check.ts and api.check.ts files don't have individual frequency settings -
240+
they inherit the default frequency from the project configuration in
241+
checkly.config.ts.
242+
```
243+
244+
Once we’re done creating new checks, it’s time to run them all with:
245+
246+
```bash
247+
npx checkly test
248+
```
249+
250+
When I ran a number of generated tests, the only issue I ran into was a failure with the message: “Error: expect.toBeVisible: Error: strict mode violation: getByText('Crime & Thrillers') resolved to 2 elements:” As the error message implies, the issue is that this locator:
251+
252+
```ts
253+
await expect(page.getByText('Fantasy')).toBeVisible();
254+
```
255+
256+
Found multiple results on the page. There are a number of ways to fix this with Claude Code, we could prompt Claude Code with:
257+
258+
> revise locators in item-visibility.spec.ts to look at only the first result
259+
>
260+
261+
This would change every locator, which may or may not be what you want! You could also paste in the error message to Claude and ask it to fix the script. Whatever route you take the result will be an edit to:
262+
263+
```ts
264+
await expect(page.getByText('Fantasy').first()).toBeVisible();
265+
```
266+
267+
If you’re having trouble reading the generated tests, take a look at [Checkly’s Playwright documentation](https://www.checklyhq.com/learn/playwright/). Once Claude Code added a single `.first()` to my check, everything was passing:
268+
269+
![Feedback on the terminal](/guides/images/claude-monitoring-04.png)
270+
271+
## Deploy With the Checkly CLI
272+
273+
In our example, we want to create over 50 checks at once, so it’s worth checking whether the configuration is properly formatted before deployment. Many problems would have been revealed while running `test` but if, for example, the [logical IDs](https://www.checklyhq.com/docs/cli/constructs-reference/#synthetic-checks) of current and existing checks are colliding, we’ll need to run `deploy` to detect that. Run the `deploy` command with the `-p` preview flag:
274+
275+
```bash
276+
npx checkly deploy -p
277+
```
278+
279+
This command won’t deploy anything, just parse our project and show us what will be created when we run the command without the preview flag.
280+
281+
![Feedback on the terminal](/guides/images/claude-monitoring-05.png)
282+
283+
*We’ll get a long list of new checks that will be created*
284+
285+
If you’re getting strange results from a preview of `deploy` and you’re not sure why, it might be time to get in touch with the Checkly team, [join our Slack](https://checklyhq.com/slack) for deployment advice!
286+
287+
Once we’re happy with what will be deployed, it’s time to run `npx checkly deploy` and create our checks!
288+
289+
## Conclusion
290+
291+
AI-assisted coding tools like Claude Code can significantly accelerate the creation and deployment of monitoring checks with Checkly’s Monitoring as Code approach. By integrating AI into your development workflow, you can generate valid Checkly constructs—including URL monitors and Playwright-based browser checks—with minimal effort. One of the superpowers that an AI workflow can unlock is the *mass updating of many files in your project.* Updating a large number of test files can go way faster with the help of Claude Code.
292+
293+
While AI can handle much of the boilerplate work, human oversight remains essential for ensuring best practices, refining assertions, and maintaining high-quality monitoring scripts. By combining AI efficiency with developer expertise, teams can achieve comprehensive monitoring coverage in minutes rather than days.
294+
295+
## Further Reading
296+
297+
To learn more about Checkly’s capabilities, explore these resources:
298+
299+
- [Checkly CLI Documentation](https://www.checklyhq.com/docs/cli/) – Learn how to manage checks as code right from your command line.
300+
- [Playwright Testing Guide](https://www.checklyhq.com/learn/playwright/) – Best practices for writing reliable browser checks.
301+
- [What is monitoring as code?](https://www.checklyhq.com/guides/monitoring-as-code/) — A comprehensive guide to infrastructure-as-code principles for monitoring.
302+
- [Checkly Community Slack](https://checklyhq.com/slack) – Join discussions and get support from the Checkly team and other users.
303+
304+
For more tutorials and advanced use cases, visit the [Checkly YouTube channel](https://www.youtube.com/@ChecklyHQ), where you can see great tutorials like this guide to the Playwright MCP server:
305+
306+
{{< youtube id="kzQu0Y_Nxjk" title="Generating Playwright Tests With AI: Let's Try the New Playwright MCP Server!
307+
" >}}

0 commit comments

Comments
 (0)