← Back to Plugins
Tools

ContextScope

tjdxwwj By tjdxwwj ⭐ 1 stars 👁 1 views ▲ 0 votes

Request Analyzer Plugin for OpenClaw

GitHub

Install

npm install
npm

Configuration Example

{
  "plugins": {
    "entries": {
      "openclaw-contextscope": {
        "enabled": true,
        "config": {
          "storage": {
            "maxRequests": 10000,
            "retentionDays": 7,
            "compression": true
          },
          "visualization": {
            "theme": "dark",
            "autoRefresh": true,
            "refreshInterval": 5000
          },
          "capture": {
            "includeSystemPrompts": true,
            "includeMessageHistory": true,
            "anonymizeContent": false
          },
          "alerts": {
            "enabled": true,
            "tokenThreshold": 50000,
            "costThreshold": 10.0
          }
        }
      }
    }
  }
}

README

# ContextScope for OpenClaw

> **Know exactly where your AI budget goes** โ€” Visualize token usage and costs for every LLM request, like Chrome DevTools for AI applications

[![npm version](https://img.shields.io/npm/v/openclaw-contextscope.svg)](https://www.npmjs.com/package/openclaw-contextscope)
[![OpenClaw Plugin](https://img.shields.io/badge/OpenClaw-Plugin-blue.svg)](https://openclaw.ai)

English | [็ฎ€ไฝ“ไธญๆ–‡](README.zh-CN.md)

## ๐Ÿš€ What Makes ContextScope Different

**The problem**: You're spending money on openclaw but have no idea where it goes. Which requests cost the most? What's driving up your token usage?

**The solution**: ContextScope shows you exactly where every dollar goes โ€” per request, per model, per conversation.

Unlike OpenClaw's built-in observability tools, **ContextScope** provides:

| Feature | ContextScope (This Plugin) | OpenClaw Native |
|---------|---------------------------|-----------------|
| **Visual Dashboard** | โœ… Full React-based UI with real-time charts | โŒ CLI-only logs |
| **Token Breakdown** | โœ… Per-request token analysis (system/history/tools/output) | โš ๏ธ Basic usage stats |
| **Context Treemap** | โœ… Visual treemap of message importance | โŒ Not available |
| **Timeline View** | โœ… Interactive timeline with zoom/filter | โŒ Text-only logs |
| **Subagent Tracing** | โœ… Full parent-child run visualization | โš ๏ธ Limited tracing |
| **Cost Analytics** | โœ… Model-based cost estimation | โŒ Not available |
| **Data Export** | โœ… JSON/CSV export with filters | โŒ Not available |
| **Auto Browser Launch** | โœ… Opens dashboard on gateway start | โŒ Manual access |

## ๐Ÿ“ธ Screenshots

> **Note**: Place your screenshots in the `screenshots/` directory

### Dashboard Overview
![Dashboard Overview](screenshots/dashboard.png)
*Real-time overview of all your AI requests and costs*

### Token Breakdown - Know Where Your Money Goes
![Token Breakdown](screenshots/token-breakdown.png)
*Detailed token usage breakdown per request*

### Timeline View
![Timeline View](screenshots/timeline.png)
*Interactive timeline with zoom and filter capabilities*

### Cost Analysis
![Cost Analysis](screenshots/cost-analysis.png)
*Track spending by model and time period*

### Context Treemap
![Context Treemap](screenshots/context-treemap.png)
*Visualize message importance and token distribution*

## โœจ Key Features

### 1. Cost Transparency โ€” Know Where Your Money Goes
- **Per-request cost breakdown** โ€” See the exact cost of every single API call
- **Token-to-dollar mapping** โ€” Understand which parts of your prompts drive costs
- **Budget tracking** โ€” Monitor spending in real-time with configurable alerts
- **Export spending reports** โ€” Analyze costs by model, time period, or conversation

### 2. Real-Time Request Monitoring
- **Chrome DevTools-like interface** for AI agent requests
- Live request/response capture with zero configuration
- WebSocket-free polling with configurable refresh intervals

### 2. Token-Level Context Analysis
```
System Prompt:  1,234 tokens (12%)
History:        5,678 tokens (56%)
Tool Results:   2,345 tokens (23%)
Output:          901 tokens (9%)
```
- Understand exactly where your tokens go
- Identify context bloat and optimization opportunities

### 3. Context Treemap Visualization
- Visual representation of message impact scores
- Quickly identify which historical messages matter most
- Optimize context window usage

### 4. Subagent & Tool Call Tracing
- Complete parent-child run hierarchy
- Tool call dependency graph
- Subagent spawn/send/ended lifecycle tracking

### 5. Cost Analytics & Alerts
- Model-based cost estimation (OpenAI, Anthropic, etc.)
- Configurable token and cost thresholds
- Real-time alerting for expensive operations

## ๐Ÿ“ฆ Installation

```bash
# Install via OpenClaw CLI
openclaw plugins install openclaw-contextscope

# Or install specific version
openclaw plugins install openclaw-contextscope@latest
```

## ๐ŸŽฏ Quick Start

### 1. Automatic (Recommended)
Simply restart OpenClaw gateway:
```bash
openclaw gateway restart
```

ContextScope will:
- โœ… Print a prominent dashboard URL in terminal
- โœ… Automatically open your browser
- โœ… Start capturing requests immediately

### 2. Manual Access
Visit: `http://localhost:18789/plugins/contextscope`

### 3. Chat Commands
In any OpenClaw conversation:
```
/analyzer         # Show plugin status
/analyzer stats   # View detailed statistics
/analyzer open    # Open dashboard in browser
/analyzer help    # Show all commands
```

## โš™๏ธ Configuration

Edit your `~/.openclaw/openclaw.json`:

```json
{
  "plugins": {
    "entries": {
      "openclaw-contextscope": {
        "enabled": true,
        "config": {
          "storage": {
            "maxRequests": 10000,
            "retentionDays": 7,
            "compression": true
          },
          "visualization": {
            "theme": "dark",
            "autoRefresh": true,
            "refreshInterval": 5000
          },
          "capture": {
            "includeSystemPrompts": true,
            "includeMessageHistory": true,
            "anonymizeContent": false
          },
          "alerts": {
            "enabled": true,
            "tokenThreshold": 50000,
            "costThreshold": 10.0
          }
        }
      }
    }
  }
}
```

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    OpenClaw Gateway                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  ContextScope   โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   React Dashboard    โ”‚  โ”‚
โ”‚  โ”‚  Plugin Core    โ”‚  HTTP   โ”‚   (Vite + Tailwind)  โ”‚  โ”‚
โ”‚  โ”‚                 โ”‚         โ”‚                      โ”‚  โ”‚
โ”‚  โ”‚ โ€ข LLM Hooks     โ”‚         โ”‚ โ€ข Real-time Charts   โ”‚  โ”‚
โ”‚  โ”‚ โ€ข Task Tracker  โ”‚         โ”‚ โ€ข Interactive Tables โ”‚  โ”‚
โ”‚  โ”‚ โ€ข Token Counter โ”‚         โ”‚ โ€ข Export Tools       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚           โ”‚                                              โ”‚
โ”‚           โ–ผ                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                    โ”‚
โ”‚  โ”‚  JSONL Storage  โ”‚  ~/.openclaw/contextscope/         โ”‚
โ”‚  โ”‚  (Compressed)   โ”‚                                    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## ๐Ÿ“Š API Endpoints

| Endpoint | Description |
|----------|-------------|
| `GET /api/stats` | Overall statistics & aggregations |
| `GET /api/requests` | Paginated request list with filters |
| `GET /api/analysis?runId=xxx` | Detailed run analysis |
| `GET /api/session?sessionId=xxx` | Session-level insights |
| `GET /api/export?format=json\|csv` | Data export |
| `GET /api/timeline` | Timeline data for visualization |
| `GET /api/chains` | Request chain relationships |

## ๐Ÿ”ง Development

### Prerequisites
- Node.js 18+
- OpenClaw CLI installed

### Backend (Plugin)
```bash
cd openclaw-contextscope
npm install
npm run build:backend
```

### Frontend (Dashboard)
```bash
cd openclaw-contextscope/frontend
npm install
npm run dev        # Development server
npm run build      # Production build
```

### Full Build
```bash
npm run build:all  # Builds both frontend and backend
```

## ๐Ÿ†š Comparison with Alternatives

| Tool | Type | Real-time | Visual UI | Token Analysis | Cost Tracking | OpenClaw Integration |
|------|------|-----------|-----------|----------------|---------------|---------------------|
| **ContextScope** | Plugin | โœ… | โœ… Full Dashboard | โœ… Detailed | โœ… | โœ… Native |
| OpenClaw Native | Built-in | โš ๏ธ Logs only | โŒ CLI | โš ๏ธ Basic | โŒ | โœ… |
| LangSmith | External | โœ… | โœ… | โœ… | โœ… | โŒ Manual setup |
| Langfuse | External | โœ… | โœ… | โœ… | โœ… | โŒ Manual setup |
| Helicone | Proxy | โœ… | โœ… | โœ… | โœ… | โŒ Requires API key |

**ContextScope Advantage**: Zero configuration, native OpenClaw integration, no external services or API keys required.

## ๐Ÿ“ License

MIT License โ€” Free for personal and commercial use.

---

<p align="center">
  <b>Made for OpenClaw</b> โ€” Visualize your AI agents like never before.
</p>
tools

Comments

Sign in to leave a comment

Loading comments...