# Count the AI tools across your devices

> Roll up which AI tools and versions your realm's devices have installed, and find the devices that haven't reported for a day.

Your security team wants a number for each AI tool: how many machines have Claude Code, which versions of Cursor are
out there, and whether an old version that needs patching is still around. They also want to know which devices have
stopped reporting, since a quiet device is one you can't see. Your realm's AI fleet holds the answer; this guide rolls
it up with `curl` and `jq`.

## Before you start

- You hold a privilege that reads the realm's configuration, such as `RealmViewer` or `RealmOwner`, with your session
  in `$CVYUH_SESSION` ([Call the API](../../../develop/api/)), and `jq` to read the answers.
- Your devices are enrolled and approved for AI governance; see
  [Get started with AI Governance](../../get-started/).

## Roll it up

<Steps>

1. **Save the fleet's device list:**

   ```sh
   curl -s https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/devices \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" > fleet.json
   ```

2. **Count the devices that have each tool**, from each device's `installed_tools`:

   ```sh
   jq -r '[.[].installed_tools[]] | group_by(.) | map([.[0], length]) | sort_by(-.[1])[] | @tsv' fleet.json
   ```

   ```
   claude-code   42
   vscode        37
   cursor        12
   ```

3. **Count each tool by version.** Versions are in each device's own record, so read each one:

   ```sh
   jq -r '.[].id' fleet.json | while read -r id; do
     curl -s "https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/devices/$id" \
       -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" |
       jq -r '.discoveries[] | [.kind, (if .version == "" then "unknown" else .version end)] | @tsv'
   done | sort | uniq -c | sort -rn
   ```

   ```
        30 claude-code   <version>
        12 claude-code   <older version>
         4 grok          unknown
   ```

   A version shows as `unknown` where the install keeps none discovery can read; see
   [Supported tools](../../discovery/supported-tools/).

4. **Find the devices not seen for a day.** `last_seen_at` is in seconds since the Unix epoch:

   ```sh
   jq -r --argjson now "$(date +%s)" \
     '.[] | select((.last_seen_at // 0) < $now - 86400) | [.hostname, .id, (.last_seen_at // "never")] | @tsv' \
     fleet.json
   ```

   Each line is a device that's off, off the network, revoked, or whose user's approval has lapsed.

</Steps>

<Aside type="note" title="Installed, not used">
  These counts are of tools installed on each device, not of how much they're used. A device with Claude Code counts
  once, however many of its users have it.
</Aside>

## Check it worked

The total in step 2 for a tool is never more than the number of devices in `fleet.json`
(`jq length fleet.json`). Install a supported tool on one device, wait for it to report (at most 15 minutes), and run
steps 1 and 2 again: its count goes up by one.

## Undo it

Nothing to undo: these calls only read. Delete `fleet.json` when you're done.

## Related

- [Fleet records](../../fleet/fleet-records/#field-reference): every field these steps read.
- [Find the MCP servers on your devices](../find-mcp-servers/): the MCP servers behind these tools.
- [AI governance sign-in](../../fleet/user-sign-in/#troubleshooting): bring a quiet device back.
