Skip to content

Caveman Cloud· HostedAnalytics

Set up analytics for Claude Code, Codex, and other agents

Route Claude Code, Codex, Gemini CLI, opencode, Aider, and other coding agents through Caveman Cloud on personal keys so spend maps to each person.

Coding agent analytics in Caveman Cloud depend on one thing: each developer's agent sends its model calls through the gateway on that developer's personal key. Once it does, every request is attributed to the person, labeled with the agent that made it, and grouped into sessions you can trace back to a repository and branch. This guide covers the two ways to connect each supported agent and how to roll it out across a team.

Choose a connection method#

MethodAgentsWhat you run
Direct connectClaude Code, CodexEnvironment variables copied from Developers → Connect an agent. No extra tooling.
caveman CLI wrapperClaude Code, Codex, Gemini CLI, opencode, Aider, Hermes Agent, OpenClawcaveman <agent> starts the agent through a local proxy and injects the gateway settings for you.

Both methods produce the same attribution in the Developers space. The wrapper also reports per-machine data to Your agents (routing decisions, model mix, measured tokens, and tokens kept out of context).

Before you start#

  • An owner or admin has connected the provider your agent uses (Anthropic for Claude Code, OpenAI for Codex) under Gateway → Providers in the project. If not, the connect page shows Connect first.
  • You know your gateway origin. Set it once:
export CAVE_GATEWAY_URL="https://gateway.caveman.so"

Get your personal key#

  1. Open Connect an agent

    In the console, go to Developers → Connect an agent and pick the project you want your usage attributed to.

  2. Reveal the key

    Click Get my key. The key is shown once, so copy it now. If you already have one, Rotate & reveal issues a new key and revokes the old one.

  3. Export it

    export CAVE_API_KEY="<your personal key>"

Tag sessions with repository and branch#

Set CAVE_TAGS in the shell before starting the agent. The gateway records repo and branch on each request, which is what links sessions to merged pull requests in Repositories and Delivery.

export CAVE_TAGS="repo=$(git remote get-url origin 2>/dev/null | sed -E 's#\.git$##; s#.*[:/]([^/:]+/[^/]+)$#\1#'),branch=$(git branch --show-current 2>/dev/null)"

The value is sent in the x-cave-tags header. The gateway drops a repo value that is not in owner/name form. Repository and branch are caller-reported metadata; no prompts or source code are needed to link them.

Connect each agent#

Direct connect. Claude Code reads its base URL, token, and extra headers from the environment.

export ANTHROPIC_BASE_URL="${CAVE_GATEWAY_URL}/w/claude"
export ANTHROPIC_AUTH_TOKEN="$CAVE_API_KEY"
export ANTHROPIC_CUSTOM_HEADERS="x-cave-upstream-key: $ANTHROPIC_API_KEY\nx-cave-tags: $CAVE_TAGS"
claude

If your project uses a stored Anthropic credential, leave out the x-cave-upstream-key line.

Wrapper.

npm i -g @anthropic-ai/claude-code
caveman claude

Install and sign in to the wrapper#

npm i -g @caveman-ai/cli
caveman login

caveman login registers the machine. After that, caveman <agent> (or caveman run -- <agent>) starts any of the seven profiles. Each machine and agent then appears under Developers → Your agents, and a person's device count and last login show in team views. For profile details, see Route agent traffic through the gateway.

Verify it worked#

  1. Keep Developers → Connect an agent open while you send your first prompt. It switches from "Waiting for your first agent session…" to a connected message such as "Claude Code connected: your session activity is arriving."
  2. Click Inspect sessions to open Developers → Sessions and find your session.
  3. Open My usage to see your requests and catalog spend by coding tool and model.

Roll out to your team#

  1. Create one project per team

    Each project is a team in the Developers space. Create more projects for sub-teams.

  2. Connect providers once

    Add Anthropic and OpenAI connections in Gateway → Providers so developers can omit their own upstream keys.

  3. Share the setup

    Ask each developer to get a personal key and add the exports above (including CAVE_TAGS) to their shell profile, or install the caveman CLI.

  4. Connect GitHub

    Have an owner or admin connect GitHub to the project so sessions link to merged changes.

  5. Check attribution

    In Developers → Team, the Attribution panel shows how much project spend is linked to people. A low share means traffic is running on shared keys or is app traffic.

Agent labels#

The agent label comes from the x-cave-agent header that each profile or direct-connect path sets. Unknown labels display as sent. Traffic with no label shows as Unlabeled, and wrapper traffic without a specific profile shows as Caveman CLI. Charts show the top five agents and group the rest as "other".

Next steps#

Esc

Start here