# Detect crawlers and bots

To detect crawlers or bots, first [pass the user agent to Hypertune](/guides/pass-the-user-agent-to-hypertune.md).

Next, add a rule to your flag that checks whether the user agent matches a crawler or bot using a regular expression:

{% code title="regex" %}

```regex
(?i)(bot|crawler|crawl|spider|slurp|fetch|search|monitor|scraper|python|perl|php|java|wget|curl|httpclient|libwww|bingpreview|mediapartners\-google)
```

{% endcode %}

<figure><img src="/files/ccFuYqZ2HH6a4i4Mw5Xy" alt=""><figcaption></figcaption></figure>

In the example above, the rule runs before the default rule that contains the `Experiment` expression. As a result, crawlers and bots will exit the flag logic immediately. They won’t enter the experiment, which keeps exposures and analytics clean.

For this reason, we recommend keeping all targeting logic within a single flag rather than spreading it across multiple flags or hardcoding it in your application.

Hypertune makes this possible via its flexible configuration language, [Hyperlang](/concepts/logic.md#hyperlang).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hypertune.com/guides/detect-crawlers-and-bots.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
