Files
Claude-Code-Monitor/SETUP.md
T
nntrivi2001 7357070fb9 chore: remove unused desktop app, cloud deployment infra, and monitoring stack
Deletes desktop/ (Electron wrapper), deployments/ (Helm/Kustomize/
Terraform/CI for cloud deploy), and monitoring/ (Prometheus + Grafana
stack) along with DESKTOP.md, DEPLOYMENT.md, docker-compose.full.yml,
their npm scripts, and every dangling reference across README,
ARCHITECTURE, INSTALL, SETUP, docs/, and the repeated per-file
MODULE_GUIDE "Observability" boilerplate comment. The GET /api/metrics
endpoint itself is untouched — it's the dashboard's own route, not
part of the removed monitoring stack.
2026-08-11 12:16:54 +07:00

25 KiB
Raw Blame History

Setup Guide

A comprehensive guide to setting up and configuring the Agent Dashboard, including how it integrates with Claude Code, environment variables, container deployment, and troubleshooting common issues.

How it works

Agent Dashboard integrates with Claude Code through its native hook system. When Claude Code performs any action (session start, tool use, turn completion, subagent finish, session exit), it fires a hook that calls a small Node.js script bundled with this project. That script forwards the event over HTTP to the dashboard server, which stores it in SQLite and broadcasts it to the browser over WebSocket.

Claude Code  →  hook fires  →  hook-handler.js  →  POST /api/hooks/event
                                                         ↓
Browser  ←  WebSocket broadcast  ←  Express server  ←  SQLite

No extra Claude Code configuration is required in the normal host-run path — when you start the dashboard with npm run dev or npm start, the server configures the hooks automatically on startup. Container deployments are the exception: after the container is up, run npm run install-hooks on the host so Claude Code points at http://localhost:4820.


Configuration

Hook auto-installation

When the dashboard is running directly on the host, the server writes the following to ~/.claude/settings.json every time it starts:

{
  "hooks": {
    "SessionStart": [{ "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" SessionStart" }] }],
    "PreToolUse":   [{ "matcher": "*", "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" PreToolUse" }] }],
    "PostToolUse":  [{ "matcher": "*", "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" PostToolUse" }] }],
    "Stop":         [{ "matcher": "*", "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" Stop" }] }],
    "SubagentStop": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" SubagentStop" }] }],
    "Notification": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" Notification" }] }],
    "SessionEnd":   [{ "hooks": [{ "type": "command", "command": "node \"/path/to/scripts/hook-handler.js\" SessionEnd" }] }]
  }
}

Note

Note: SessionStart and SessionEnd hooks do not support the matcher field — they fire unconditionally on every session start and exit.

Existing hooks in that file are preserved. The dashboard only adds or updates entries that contain hook-handler.js.

To re-run hook installation manually:

npm run install-hooks

Tip

Container note: do not rely on hook auto-install from inside Docker or Podman. The hook path written by a container would point at the container filesystem, not the host. Start the container first, then run npm run install-hooks on the host. As a safeguard (issue #193), the installer now detects container execution and refuses to run (exiting non-zero) so it can never poison a bind-mounted host ~/.claude; the containerized server logs the same guidance instead of silently writing a bad path. If you genuinely run Claude Code inside the same container, override with CCAM_ALLOW_CONTAINER_HOOKS=1 npm run install-hooks.

Note

Prefer a ready-made dev environment? This repo ships an optional Dev Container (.devcontainer/) for VS Code / GitHub Codespaces — Node 22, native build tools for better-sqlite3, Python, and ports 4820/5173 preconfigured. It's purely opt-in and changes nothing for host-based development. See .devcontainer/README.md. (Hooks remain host-side there too.)

Container runtime (Docker / Podman)

The repo includes both a multi-stage Dockerfile and a docker-compose.yml file. The container image serves the built client and API on port 4820, stores SQLite data under /app/data, and can import legacy Claude history from a read-only ~/.claude mount.

# Docker Compose
docker compose up -d --build

# Podman Compose
CLAUDE_HOME="$HOME/.claude" podman compose up -d --build

# Plain Docker
docker build -t agent-monitor .
docker run -d --name agent-monitor \
  -p 127.0.0.1:4820:4820 \
  -v "$HOME/.claude:/root/.claude:ro" \
  -v agent-monitor-data:/app/data \
  agent-monitor

# Plain Podman
podman build -t agent-monitor .
podman run -d --name agent-monitor \
  -p 127.0.0.1:4820:4820 \
  -v "$HOME/.claude:/root/.claude:ro" \
  -v "$HOME/.claude/agent-dashboard:/app/data" \
  agent-monitor

Container-specific behavior:

  • The dashboard is available at http://localhost:4820
  • The image sets DASHBOARD_HOST=0.0.0.0 (bind inside the container — its loopback is a separate namespace the published port cannot reach) and DASHBOARD_DATA_DIR=/app/data internally; both are baked into the Dockerfile
  • The examples publish on 127.0.0.1 only, so the dashboard is local-only. To expose it on a LAN, publish on 0.0.0.0 (-p 4820:4820) and set DASHBOARD_TOKEN
  • ~/.claude:/root/.claude:ro is used for history import only
  • ~/.claude/agent-dashboard:/app/data is the canonical SQLite database (shared with native installs)
  • Claude Code hooks still execute on the host, so install them from the host with npm run install-hooks

Environment variables

Variable Default Description
DASHBOARD_PORT 4820 Port the Express server listens on
CLAUDE_DASHBOARD_PORT 4820 Port the hook handler uses when posting events to the dashboard
DASHBOARD_DB_PATH data/dashboard.db Path to the SQLite database file
NODE_ENV development Set to production to serve built client
DASHBOARD_CLIENT_DIST client/dist Directory the built UI is served from in production. Set by the ccam plugin bootstrap to its own runtime dir, because the plugin cache is replaced on every update
CCAM_IMPORT_MAX_BYTES 1073741824 (1 GB) Maximum size per uploaded file on /api/import/upload
CCAM_IMPORT_MAX_FILES 2000 Maximum number of files per upload request
CCAM_IMPORT_MAX_EXTRACT_BYTES 4294967296 (4 GB) Maximum uncompressed bytes any single archive is allowed to expand to (zip-bomb defense)
MCP_DASHBOARD_BASE_URL http://127.0.0.1:4820 Base URL used by the local MCP server to call dashboard APIs
MCP_DASHBOARD_ALLOW_MUTATIONS false Enables mutating MCP tools
MCP_DASHBOARD_ALLOW_DESTRUCTIVE false Enables destructive MCP tools (in addition to mutations)
MCP_TRANSPORT stdio MCP transport mode: stdio, http, repl
MCP_HTTP_PORT 8819 Port for the MCP HTTP+SSE server (only when MCP_TRANSPORT=http)
MCP_HTTP_HOST 127.0.0.1 Bind address for the MCP HTTP server

Example with a custom port:

DASHBOARD_PORT=9000 npm run dev

Note

You usually do not need to set DASHBOARD_PORT manually. npm run dev is wrapped by scripts/dev.js, which probes both 127.0.0.1 and ::1 (so an SSH LocalForward bound to one loopback can't slip past) and picks the first free port in 48204859 automatically. The chosen port is propagated to the Vite dev proxy via DASHBOARD_PORT, and the Express server writes it to ~/.claude/.agent-dashboard.json so the Claude Code hook handler discovers it without any env var.

Multiple dashboards can run side by side — for example two npm run dev checkouts, or npm run dev alongside npm start. Each one appends its {port, pid, startedAt} entry to the discovery file, and scripts/hook-handler.js fan-outs every hook event to every live entry, so both UIs keep their real-time stream.

Setting CLAUDE_DASHBOARD_PORT=N overrides discovery entirely and forces the hook handler to a single port — useful for tests and container setups where the in-process discovery file isn't reachable from the host.

If you bypass the picker (e.g. npm run dev:raw, container builds, or anything else that calls node server/index.js directly), make sure your client is built / proxied against the port the server actually bound.

MCP server (optional)

The project includes a local MCP server under mcp/ so AI agents can call dashboard operations through standardized tools. It supports three transport modes: stdio for MCP host integration, HTTP+SSE for networked clients, and an interactive REPL for operator debugging.

graph LR
    subgraph "MCP Transport Modes"
        STDIO["stdio\n(default)"]
        HTTP["HTTP + SSE\n(:8819)"]
        REPL["Interactive REPL"]
    end

    HOST["MCP Host"] -->|"stdin/stdout"| STDIO
    RC["Remote Client"] -->|"POST /mcp · GET /sse"| HTTP
    OP["Operator"] -->|"interactive CLI"| REPL

    STDIO --> API["Dashboard API<br/>http://127.0.0.1:4820/api/*"]
    HTTP --> API
    REPL --> API

    style STDIO fill:#6366f1,stroke:#818cf8,color:#fff
    style HTTP fill:#f59e0b,stroke:#fbbf24,color:#000
    style REPL fill:#a855f7,stroke:#c084fc,color:#fff

Quick start:

npm run mcp:install
npm run mcp:build
npm run mcp:start              # stdio (for Claude Code / Claude Desktop)
npm run mcp:start:http         # HTTP + SSE server on port 8819
npm run mcp:start:repl         # interactive CLI with tab completion

For full host config and tool catalog, see mcp/README.md.

Agent extension setup (Claude Code + Codex)

This repository ships extension files for both agent ecosystems:

  • Claude Code:
    • CLAUDE.md
    • .claude/rules/*
    • .claude/skills/*
    • .claude/agents/*
  • Codex:
    • AGENTS.md
    • .codex/config.toml
    • .codex/rules/default.rules
    • .codex/agents/*
    • .codex/skills/*

See .codex/README.md for Codex extension details.

VS Code extension setup

The Claude Code Agent Monitor is available as an integrated VS Code extension for seamless monitoring within your editor.

  • Activity Bar View: Adds a custom "Radar" icon to the activity bar providing real-time agent health, token counts, and session stats.
  • Status Bar Integration: Displays live session and agent pulse counts in the bottom bar.
  • Embedded Dashboard: Renders the full web dashboard directly in a VS Code editor tab.
  • Automated Detection: Automatically finds your dashboard server on ports 5173 or 4820.

VS Code Extension Screenshot

To install or develop the extension:

  1. Open the vscode-extension directory in VS Code.
  2. Run npm install and npm run package to generate a local .vsix installer.
  3. For developer details, see vscode-extension/README.md.

Tip

Extension on VS Code Marketplace: Claude Code Agent Monitor

PWA configuration (optional)

The dashboard, landing page, and wiki each ship as independent Progressive Web Apps. No configuration is required — manifests and service workers are included out of the box.

Customising the manifest: Edit the manifest.json in the relevant directory (client/public/ for dashboard, root for landing, wiki/ for wiki). Common fields to change:

  • name / short_name — displayed on the home screen / dock
  • theme_color — address bar / title bar tint (default: #6366f1)
  • background_color — splash screen background
  • start_url — entry point when launched from home screen

Updating the service worker cache: Each SW has a CACHE_NAME constant (e.g. dashboard-v2). After deploying new assets, bump the version string to force browsers to re-fetch — though for the dashboard this is rarely needed: hashed /assets/* URLs are immutable per build, everything else is fetched network-first with cache fallback, and a controllerchange listener in the client reloads the page exactly once when a new SW takes over, so a rebuild propagates without a hard refresh.

Browser support: PWA install prompts appear in Chrome 107+, Edge 107+, and Firefox 110+ (desktop and Android). Safari supports apple-mobile-web-app-capable for iOS home-screen mode but does not show an install banner.

Verifying PWA status: Open DevTools → Application → Manifest to confirm the manifest loads. Check the Service Workers section to verify the SW is registered and active. The Lighthouse PWA audit should pass all core checks.


Database

The SQLite database is created automatically at data/dashboard.db on first run. The directory is created if it does not exist. The database uses WAL mode for concurrent reads and foreign keys for referential integrity.

Clear all data

To remove all sessions, agents, events, and token usage (useful after running seed data or for a clean start):

npm run clear-data

Data management via Settings page

The Settings page (/settings) provides a UI for:

  • Model Pricing — view and edit per-model cost rates, reset to defaults, add custom models
  • Hook Configuration — check which hooks are installed and reinstall them
  • Data Export — download all sessions, agents, events, and pricing as a JSON file
  • Session Cleanup — abandon stale active sessions after N hours, purge old completed sessions after N days
  • Clear All Data — remove all sessions, agents, events, and token usage
  • Data Management and About sections render with loading placeholders while server info is being fetched, so the page is always fully navigable

Seed demo data

To populate the dashboard with sample sessions, agents, and events for UI exploration:

npm run seed

Importing existing Claude Code history

The dashboard automatically imports sessions from ~/.claude/projects/ on every startup, so if Claude Code has been used on this machine, you'll see history immediately after the first launch. If you need to bring in history from another machine, from a backup, or just force a rescan, use Settings → Import History in the UI — it's a guided, drag-and-drop experience with live progress.

Pick the right mode

flowchart TD
    Q["Where is the history?"] --> Q1{Is it on this machine<br/>under ~/.claude/projects?}
    Q1 -->|yes, and I just want<br/>to re-scan| M1["Mode: Rescan default folder<br/>one click"]
    Q1 -->|yes, but in another folder<br/>on this machine| M2["Mode: Scan a folder<br/>paste the absolute path"]
    Q1 -->|no — it's on another machine<br/>or in an archive file| M3["Mode: Upload files<br/>drag-drop JSONL or archive"]

    M3 --> PREP["Archive source:<br/>tar -czf claude-history.tar.gz<br/>-C ~/.claude projects"]

    style M1 fill:#10b981,stroke:#34d399,color:#fff
    style M2 fill:#f59e0b,stroke:#fbbf24,color:#000
    style M3 fill:#a855f7,stroke:#c084fc,color:#fff

Step-by-step: moving history from one machine to another

On the source machine, bundle the projects folder:

# macOS / Linux
tar -czf claude-history.tar.gz -C ~/.claude projects

# Windows (PowerShell, via built-in tar)
tar -czf claude-history.tar.gz -C "$env:USERPROFILE\.claude" projects

Transfer the resulting claude-history.tar.gz to the destination machine however you like — AirDrop, scp, USB, cloud storage.

On the destination machine, in the dashboard:

  1. Open Settings → Import History.
  2. Pick Upload files (the third tab).
  3. Drag the archive onto the drop zone.
  4. Click Upload & Import and watch the progress.
  5. When the green result card appears, open Analytics → Cost to confirm per-model token totals and estimated cost.

Supported inputs

Any of the following can be dropped onto the upload zone or found inside a folder given to Scan a folder:

  • .jsonl — session transcripts
  • .meta.json — subagent metadata sidecars
  • .zip — extracted with path-traversal protection
  • .tar, .tar.gz, .tgz — extracted via the tar package
  • .gz — single gzipped JSONL (streaming-decompressed)

Accuracy guarantees

  • Idempotent — re-importing never double-counts. Sessions are deduplicated by UUID.
  • Cost-preserving — the token_usage table uses baseline_* columns to preserve pre-compaction token totals, so re-ingesting a compacted transcript never erases historical cost.
  • Same parser as liveparseSessionFile + importSession is the single source of truth for both hook-driven ingestion and manual import, so imported numbers match captured numbers exactly.

Safety

Archive extraction is hardened against path traversal and archive bombs. The defaults are generous for real-world transcripts but tight enough to stop obvious attacks; see the env vars table above for CCAM_IMPORT_MAX_BYTES, CCAM_IMPORT_MAX_FILES, and CCAM_IMPORT_MAX_EXTRACT_BYTES.

CLI alternative

For scripts and automation, the same logic runs from the terminal:

# Import (or re-import) everything under ~/.claude/projects
npm run import-history

# Dry run — show what would be imported without writing
node scripts/import-history.js --dry-run

# Scope to a single project dir
node scripts/import-history.js --project my-project

Scripts reference

Script Command Description
setup npm run setup Install all dependencies (server + client)
dev npm run dev Start server + client in development mode
start npm start Start server in production mode
build npm run build Build the React client to client/dist/
install-hooks npm run install-hooks Write Claude Code hooks to ~/.claude/settings.json
clear-data npm run clear-data Delete all data from the database
seed npm run seed Insert demo sessions/agents/events
import-history npm run import-history Import legacy sessions from ~/.claude/ (also runs on startup)
mcp:install npm run mcp:install Install MCP package dependencies
mcp:build npm run mcp:build Build MCP server into mcp/build/
mcp:start npm run mcp:start Start MCP server (stdio, for MCP hosts)
mcp:start:http npm run mcp:start:http Start MCP HTTP+SSE server on port 8819
mcp:start:repl npm run mcp:start:repl Start interactive MCP REPL
mcp:dev npm run mcp:dev Start MCP server in dev mode (stdio)
mcp:dev:http npm run mcp:dev:http Start MCP HTTP server in dev mode
mcp:dev:repl npm run mcp:dev:repl Start MCP REPL in dev mode
mcp:typecheck npm run mcp:typecheck Type-check MCP source
mcp:docker:build npm run mcp:docker:build Build MCP container image with Docker
mcp:podman:build npm run mcp:podman:build Build MCP container image with Podman
test:mcp npm run test:mcp Run MCP server unit tests
claude Claude CLI Uses CLAUDE.md, .claude/rules, and .claude/skills automatically
test npm test Run all server and client tests
test:server npm run test:server Run server integration tests only
test:client npm run test:client Run client unit tests only
format npm run format Format all files with Prettier
format:check npm run format:check Check formatting without writing

Makefile targets

All npm scripts are mirrored as make targets for convenience. Run make help to list them:

make help

Commonly used targets:

Make target Equivalent npm command Description
make setup npm run setup + MCP install Install all dependencies (root + client + MCP)
make dev npm run dev Start server + client in watch mode
make build npm run build Build the React client for production
make start npm start Start the production server
make prod npm run build && npm start Build then start in one step
make test npm test Run all tests (server + client)
make test-server npm run test:server Run server tests only
make test-client npm run test:client Run client tests only
make format npm run format Format all files with Prettier
make format-check npm run format:check Check formatting without writing
make mcp-build npm run mcp:build Compile MCP TypeScript
make mcp-typecheck npm run mcp:typecheck Type-check MCP source
make seed npm run seed Load demo data
make clear-data npm run clear-data Delete all data rows
make docker-up docker compose up -d Start via docker-compose
make docker-down docker compose down Stop docker-compose stack

Statusline (optional)

The statusline/ directory contains a standalone terminal statusline for Claude Code showing model, working directory, git branch, context window usage, and token counts. It is independent of the web dashboard.

See statusline/README.md for installation instructions.


Troubleshooting

better-sqlite3 errors during npm install / npm run setup

These warnings are harmless. better-sqlite3 is an optional dependency — if it cannot compile, npm skips it and the server falls back to Node.js built-in node:sqlite (available on Node 22+).

You do not need Python, Visual Studio Build Tools, or any C++ compiler to run this project on Node 22+.

If you are on Node 20 or 21 and better-sqlite3 prebuilds are not available for your platform (there is no node:sqlite fallback below Node 22), you have two options:

  1. Upgrade to Node.js 22+ — the built-in node:sqlite fallback requires no native compilation at all
  2. Install build tools and run npm rebuild better-sqlite3:
    • Windows: install Visual Studio Build Tools with the C++ workload
    • macOS: xcode-select --install
    • Linux: sudo apt install python3 make g++ (Debian/Ubuntu)

"SQLite backend not available" error on startup

This means neither better-sqlite3 nor node:sqlite could be loaded. The most common cause is running Node.js < 22 without better-sqlite3 prebuilds. Upgrade to Node.js 22+ to resolve this.

Database is locked / busy errors

The SQLite database uses WAL mode with a 5-second busy timeout. If you see lock errors:

  • Ensure only one dashboard server instance is running
  • Check for zombie node server/index.js processes: ps aux | grep server/index
  • Delete data/dashboard.db-wal and data/dashboard.db-shm if the server was killed uncleanly, then restart

No sessions appearing after starting Claude Code

Check 1 — Is the server running?

curl http://localhost:4820/api/health
# Expected: {"status":"ok","timestamp":"..."}

Check 2 — Are hooks installed?

Open ~/.claude/settings.json and confirm it contains a hooks section with entries referencing hook-handler.js. If not, run:

npm run install-hooks

Check 3 — Did you start a new Claude Code session after the server started?

Hooks only apply to sessions started after installation. Restart Claude Code.

Check 4 — Is Node.js in PATH when Claude Code runs hooks?

On some systems, the shell environment when Claude Code fires hooks may not include the full PATH. Test with:

node --version

If Node.js is not found, use the full path to node in the hook command. Edit scripts/install-hooks.js, replace node with the absolute path (e.g. /usr/local/bin/node), and re-run npm run install-hooks.


Dashboard shows "Disconnected" in the sidebar

The WebSocket connection to the server failed. Ensure the server is running:

npm run dev

The client will automatically reconnect every 2 seconds once the server is available.


Events Today shows 0 despite recent activity

This was a known timezone bug (fixed in current version). If you are still seeing this, ensure you are running the latest code and restart the server.


Port 4820 already in use

DASHBOARD_PORT=4821 npm run dev

Then update the Vite proxy in client/vite.config.ts:

proxy: {
  "/api": "http://localhost:4821",
  "/ws":  { target: "ws://localhost:4821", ws: true }
}

And make sure Claude Code posts hooks to the new port:

CLAUDE_DASHBOARD_PORT=4821 claude
# or edit scripts/hook-handler.js and change the default port

Docker / Podman container starts but no sessions appear

Check 1 — Is the container healthy?

curl http://localhost:4820/api/health
# Expected: {"status":"ok","timestamp":"..."}

Check 2 — Did you install hooks on the host?

Hooks run on the host machine, not inside the container. After the container is up:

npm run install-hooks

Check 3 — Are hooks pointing to the right port?

Open ~/.claude/settings.json and verify the hook commands reference localhost:4820 (or whatever port the container is mapped to). If you changed the port mapping, update hooks accordingly.


Docker build fails during npm ci

If the build fails in Stage 1 with better-sqlite3 errors, this is expected and should not block the build — better-sqlite3 is an optional dependency. If the build still fails:

  • Ensure you are using the latest Dockerfile (it should use node:22-alpine and not install python3, make, or g++)
  • Run docker build --no-cache -t agent-monitor . to force a clean rebuild
  • Check that package.json has better-sqlite3 under optionalDependencies, not dependencies