🔥 Launching ClaudeCosts: self-hosted gateway for Claude Code, start free
Prism for Coding Agents · Product documentation

Observability and cost control for Claude Code

Observe every Claude Code session in detail, cut spend with task-aware model routing and caching, block sensitive data leakage from unauthorized MCPs, harmful skills, and prompt injections.

Self-hosted
Runs on your own infrastructure
Docker Compose
One command to start
Claude Code
CLI, IDE, and Desktop
Free POC
Realm Labs License 1.0

Realm's Prism gives you full visibility into Claude Code usage and spend across your organization: what you are paying, broken down by user and session, and where the concrete savings opportunities are. It shows which kinds of tasks drive cost (for example feature building, ML work, or documentation), identifies power users, and lets you drill into session and message level logs covering every tool call, skill, and MCP server used. It ships as a small set of Docker containers and supports personal, team, and enterprise Claude Code installations.

A note on names. Prism for Coding Agents is the product. In the repository, container images, and CLI you will see it referred to as Realm's Prism and published as claudecosts at github.com/realmlabs-ai/claudecosts. They are the same tool. This documentation covers the self-hosted free version.

Key capabilities

Full observability

Trace every session down to request, response, tool call, and line of code in one live dashboard.

Cost breakdown

See dollars spent by every user, project, intent, and model. Get alerts on spend and minimize waste.

Savings analysis

Model-assisted intent classification and cost saving analysis surface where spend can be reduced.

Risk surfacing

Find unauthorized MCP servers, harmful skills, and leaked secrets across your organization's Claude Code usage.

How it works

Claude Code normally talks to the Anthropic API directly. Realm's Prism sits in front of that connection: you point Claude Code at the gateway by setting the ANTHROPIC_BASE_URL environment variable. The gateway meters every call, records it, and forwards it on to Anthropic.

Claude Code
CLI / IDE / Desktop
Realm's Prism gateway
Meters and records
Anthropic API
Model call

Model calls continue to authenticate with your existing credentials, either your Claude login (OAuth) or your ANTHROPIC_API_KEY. The optional LLM_API_KEY you provide to the stack is used only for analysis features such as intent classification and cost saving analysis, never for the Claude Code calls themselves.

Architecture

The stack is defined in docker-compose.yml at the repository root. It runs five long-lived services plus a one-shot migration job.

ServiceImageRole
gatewayrealmlabsai/realm-gatewayMetering proxy for Claude Code traffic. Listens on port 8080 inside the container and is published on the host at CLAUDE_GATEWAY_PORT (default 8080).
frontendrealmlabsai/prism-dashboardDashboard UI. Serves on port 80 inside the container and is published at UI_PORT (default 3000). Proxies API requests to the backend.
backendrealmlabsai/prism-backendCore API and processing service. Exposes an internal health endpoint on port 8000. Not published on the host.
rollup-workerrealmlabsai/prism-rollup-workerBackground worker that aggregates recent activity and runs intent classification on a fixed interval.
postgrespostgres:17-alpineStorage for metered traffic and rollups. Not published on the host.

Request and data flow

1

A developer runs Claude Code with ANTHROPIC_BASE_URL pointing at the gateway.

2

The gateway meters the request and response, then forwards the call to the Anthropic API. Existing Claude Code credentials are used for the model call.

3

Metered sessions and messages are persisted to Postgres.

4

The rollup worker wakes on a fixed interval (default every 120 seconds, looking back one hour), aggregates recent activity, and, when LLM_API_KEY is configured, classifies session intent using the configured classifier model (default claude-haiku-4-5).

5

The dashboard reads aggregated data through the backend API.

Because rollups run periodically, data shown in the dashboard can lag live activity by up to a couple of minutes. Recent sessions and metrics may not appear immediately.

Startup order and health

Compose healthchecks enforce a strict startup order: Postgres must be healthy before migrate runs; migrate must complete successfully before the backend starts; and the gateway and frontend wait for a healthy backend. All long-running services are configured to restart unless explicitly stopped.

Requirements

Software

The only external dependency is Docker with Compose. Realm's Prism runs on any cloud provider. A Linux server is the recommended host, though macOS and Windows are supported as well.

Hardware

Realm's Prism is lightweight. Recommended sizing:

Deployment sizeRecommended hardware
Up to a few users1 CPU core, 2 GB RAM
Up to around 100 users4 to 8 CPU cores, 8 GB RAM

Network

  • Developers' machines must be able to reach the gateway port (CLAUDE_GATEWAY_PORT).
  • Browsers must be able to reach the dashboard port (UI_PORT).
  • The host must have outbound access to the Anthropic API.

Note that localhost addresses only work on the machine running the stack. For team or organization-wide use, deploy the gateway on a host your team can reach and use that address (see Connecting Claude Code).

Installation and deployment

1 · Clone the repository

The stack is defined in docker-compose.yml, so you need a local copy of the repository before you can bring it up.

bash
git clone https://github.com/realmlabs-ai/claudecosts.git
cd claudecosts

Run all commands below from inside this claudecosts directory.

2 · Start the stack

bash
LLM_API_KEY=sk-ant-api... CLAUDE_GATEWAY_PORT=9090 UI_PORT=3001 docker compose up -d

This pulls the published images, runs the database migrations, and starts every service in the background. The startup variables are:

VariableDefaultDescription
LLM_API_KEY(empty)Your Anthropic API key (sk-ant-...). Used only for model-dependent analysis features. See the note below.
CLAUDE_GATEWAY_PORT8080Host port the Claude Code gateway listens on.
UI_PORT3000Host port the dashboard UI is served on.

Important. Without an LLM_API_KEY, functionality will be limited. The stack still comes up and meters traffic, but features that rely on the model, such as intent classification and cost saving analysis, are unavailable until you provide a key. This key is not used for the actual Claude Code calls, which continue to go through your pre-existing OAuth credentials (Claude login) or ANTHROPIC_API_KEY.

Once docker compose up -d finishes, all services should report as running. You can confirm with docker compose ps.

3 · Open the dashboard

With the example ports above, the dashboard is available at:

url
http://localhost:3001

On a fresh install the dashboard is empty until traffic starts flowing through the gateway (see Connecting Claude Code).

4 · Stop the stack

bash
docker compose down

Warning. In this free version, database data is not retained across restarts. Stopping and removing the containers wipes all stored data.

If you only exported the base URL in a shell, restart your terminal to go back to Anthropic directly. If you made a system, team, or enterprise level change, remove ANTHROPIC_BASE_URL from the local settings.json or managed-settings.json respectively.

Connecting Claude Code

Realm's Prism works by sitting in front of Claude Code: instead of talking to Anthropic directly, Claude Code sends its traffic to the gateway, which meters every call and then forwards it on. The only thing you have to configure on the Claude Code side is the API base URL:

env
ANTHROPIC_BASE_URL = https://<ADDRESS>:<PORT>
  • <ADDRESS> is where the gateway is reachable, for example localhost for a local stack, or your gateway host or domain.
  • <PORT> is the gateway port, that is CLAUDE_GATEWAY_PORT from your compose configuration (default 8080).

There are two ways to apply this, depending on whether you are setting it up for yourself or rolling it out across an organization.

Best for trying Realm's Prism on your own machine, or for a single developer.

One-off (current shell only)

bash
export ANTHROPIC_BASE_URL=http://localhost:9090
claude

Important. An export is scoped to the current terminal only. It does not persist to new terminals and it does not affect Claude Code running in your IDE or Desktop app, since those do not inherit your shell's environment. Use one of the persistent options below for those cases.

Persistent (every new shell)

Add the same line to your shell profile, for example ~/.zshrc or ~/.bashrc:

bash
echo 'export ANTHROPIC_BASE_URL=http://localhost:9090' >> ~/.zshrc

User level (all your projects)

Claude Code reads environment variables from your personal settings file at ~/.claude/settings.json. Setting the base URL here routes every Claude Code session for your user account through the gateway, regardless of project, with no shell profile edit needed:

json · ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://<ADDRESS>:<PORT>"
  }
}

Per project

Claude Code also reads environment variables from .claude/settings.local.json inside a repository, so you can scope the gateway to a single project using the same JSON structure.

Best for rolling Realm's Prism out to a whole team so every developer's Claude Code traffic is metered, without each person configuring their own machine. This uses Anthropic's managed settings for Claude Code, which override user and project settings and apply across the CLI, IDE, and Desktop app.

1

Open managed settings

In the Anthropic Console, go to Organization settings > Claude Code > Managed settings (settings.json) and click Manage.

2

Add the gateway configuration

Set ANTHROPIC_BASE_URL to your gateway so all org members route through Realm's Prism. The optional announcement gives users a visible heads-up that Realm's Prism is active:

json · managed-settings.json
{
  "companyAnnouncements": [
    "Realm's Prism Enabled."
  ],
  "env": {
    "ANTHROPIC_BASE_URL": "https://<ADDRESS>:<PORT>"
  }
}
3

Save and roll out

Once saved, the managed settings propagate to your organization's Claude Code installs. New sessions route through the gateway automatically.

Replace <ADDRESS>:<PORT> with an address reachable by your team. localhost only works on the same machine as the gateway; for organization-wide use, deploy the gateway on an internal host or domain.

Verify the connection

Run a Claude Code session, then open the Realm's Prism dashboard (UI_PORT, default 3000) and confirm that sessions and costs are showing up.

Disconnect

To stop routing through the gateway, unset the variable (unset ANTHROPIC_BASE_URL) or remove it from your shell profile, settings.json, or the organization's managed-settings.json.

Configuration reference

All configuration is supplied as environment variables consumed by Docker Compose, either inline on the docker compose up command or via the shell environment. In addition to the startup variables in Installation and deployment, the rollup worker accepts the following tuning variables:

VariableDefaultPurpose
CLASSIFIER_MODELclaude-haiku-4-5Model used for intent classification.
CLASSIFIER_MAX_PER_PASS25Maximum number of items classified per rollup pass.
CLASSIFIER_TIMEOUT_S30Timeout for classifier calls, in seconds.
ROLLUP_SLEEP_SECONDS120Interval between rollup passes, in seconds.
ROLLUP_LOOKBACK1 hourWindow of recent activity each rollup pass processes.
LOG_LEVELINFORollup worker log verbosity.

Two further variables are internal wiring and require no changes for a standard deployment: DB_DSN_TEMPLATE points the backend, worker, and migration job at Postgres, and BACKEND_UPSTREAM points the frontend at the backend service (backend:8000). Both are set in docker-compose.yml.

Security and privacy

Credentials

The gateway does not replace Claude Code authentication. Model calls continue to use your pre-existing OAuth credentials (Claude login) or ANTHROPIC_API_KEY. The LLM_API_KEY supplied to the stack is used exclusively for analysis features.

Transport

For anything beyond local testing, terminate TLS in front of the gateway and use an https:// base URL.

Network exposure

Only the gateway and dashboard ports are published on the host. Postgres is not published and relies on trust authentication inside the Compose network; do not expose port 5432 externally. Restrict access to the gateway and dashboard ports to your intended users.

Telemetry

To help improve the product, the containers report anonymous, aggregated usage metrics to Realm Labs. This does not include any PII, prompt content, or source code.

Known limitations

The free version is intended for testing and evaluation. Be aware of the following:

  • Small-scale testing only. This version is meant for small setups. For larger deployment needs, contact hello@realmlabs.ai and Realm Labs will work with you directly.
  • Trace view limitations. The information and metrics shown in the trace view may have some limitations in this version.
  • Dashboard data may lag. Data shown in the UI can lag behind live activity by up to a couple of minutes, so recent sessions and metrics may not appear immediately.
  • Data is not retained across restarts. Stopping and removing the containers (docker compose down) wipes all stored data.

Troubleshooting

SymptomWhat to check
Dashboard stays emptyConfirm traffic is actually routed through the gateway. An export applies only to the current terminal; IDE and Desktop sessions need the settings.json or managed settings approach (see Connecting Claude Code).
Recent sessions missingRollups run about every two minutes. Wait briefly and reload the dashboard.
Port already in useStart the stack with different CLAUDE_GATEWAY_PORT or UI_PORT values.
A service is not runningInspect status with docker compose ps and logs with docker compose logs <service>.
Intent or savings features missingProvide a valid LLM_API_KEY when starting the stack (see Installation and deployment).

Support and resources

The best place to share feedback, ask questions, and connect with the community is the Realm Labs Discord: discord.gg/6RPjGBEZW. The team is most active there.

License

Realm's Prism is distributed under the Realm Labs License 1.0. The full license text is available in the LICENSE file at the root of the repository: github.com/realmlabs-ai/claudecosts.

Quick reference

ActionCommand
Start the stackLLM_API_KEY=sk-ant-... docker compose up -d
Start with custom portsCLAUDE_GATEWAY_PORT=9090 UI_PORT=3001 docker compose up -d
Check service statusdocker compose ps
View logs for a servicedocker compose logs <service>
Route current shell via gatewayexport ANTHROPIC_BASE_URL=http://localhost:9090
Stop routing via gatewayunset ANTHROPIC_BASE_URL
Stop the stack (wipes data)docker compose down
Open the dashboardhttp://localhost:<UI_PORT>

Put Prism for Coding Agents in front of your Claude Code

Meter every session, break down spend by user and project, and surface where the savings are. Deploy it on your own infrastructure in minutes.

Questions on deployment, configuration, or larger rollouts? Reach the team on Discord or at hello@realmlabs.ai.