- Request ID:
- c3c0dfb3-64fe-4c1e-add7-f027672274ca
- Conversation ID:
- e89f2c45-d5db-4248-945f-8b2a9928dbfa
- Parent Request:
- 17323780-d5f8-4d8e-85de-9e6911c49a33
- Branch:
- subtask_2
- Domain:
- localhost:3000
- Model:
- claude-opus-4-20250514
- Timestamp:
- 7/23/2025, 7:40:03 PM
- Tokens:
- Input: 7 Output: 119 Total: 126
- Cost:
- $0.0090
- Duration:
- 5s
- Status:
- 200
Now let me check the table of contents structure in the README:
Tool Use: Read (ID: toolu_01PGXozwY4fSk5EYf7jw9ura)
{
"limit": 200,
"offset": 300,
"file_path": "/home/crystalin/projects/claude-nexus-proxy/README.md"
}
Tool Result (ID: toolu_014qCBCPsWtgSMNBr6u4eVv3)
- π³ **Docker Ready** - Separate optimized images for each service
#### Using Pre-built Images (Default)
# Run with docker-compose using images from registry
#### Using Locally Built Images
# Build and run with locally built images
#### Build...
Show more (3 lines)
Tool Result (ID: toolu_014qCBCPsWtgSMNBr6u4eVv3)
- π³ **Docker Ready** - Separate optimized images for each service
#### Using Pre-built Images (Default)
# Run with docker-compose using images from registry
#### Using Locally Built Images
# Build and run with locally built images
#### Building Images Separately
# Build images individually
Show less
Let me check for any existing screenshots section in the README:
Tool Use: Grep (ID: toolu_014qCBCPsWtgSMNBr6u4eVv3)
{
"-i": true,
"path": "/home/crystalin/projects/claude-nexus-proxy/README.md",
"pattern": "screenshot|image|png|jpg|gif",
"output_mode": "content"
}
Tool Result (ID: toolu_01TEMRF5qsFs6ChmpcTTcLnz)
1β# ADR-017: MCP Prompt Sharing Implementation
2β
3β## Status
4β
5βAccepted
6β
7β## Context
8β
9βClaude Nexus Proxy needed a way to share and manage prompts across different Claude instances and te...
Show more (48 lines)
Tool Result (ID: toolu_01TEMRF5qsFs6ChmpcTTcLnz)
1β# ADR-017: MCP Prompt Sharing Implementation
2β
3β## Status
4β
5βAccepted
6β
7β## Context
8β
9βClaude Nexus Proxy needed a way to share and manage prompts across different Claude instances and teams. The Model Context Protocol (MCP) provides a standardized way to serve prompts that can be consumed by Claude Desktop and other MCP-compatible clients.
10β
11β## Decision
12β
13βWe implemented an MCP server within the existing proxy service that:
14β
15β1. **Serves prompts via JSON-RPC 2.0 protocol** following the MCP specification
16β2. **Uses a hybrid storage approach**: local YAML files with optional GitHub synchronization
17β3. **Integrates with Claude Desktop** via `mcp-remote` HTTP transport
18β4. **Provides dashboard UI** for prompt management and sync status
19β
20β### Architecture
21β
22βThe implementation consists of three main components:
23β
24β```
25ββββββββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
26ββ Claude Desktop ββββββΆβ Proxy Service βββββββ GitHub β
27ββ (MCP Client) β β (MCP Server) β β (Optional) β
28ββββββββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
29β β
30β βΌ
31β ββββββββββββββββββββ
32β β Local YAML β
33β β Files β
34β ββββββββββββββββββββ
35β```
36β
37β### Key Design Decisions
38β
39β1. **File-Based Storage**: Prompts are stored as YAML files in the `prompts/` directory
40β - Simple format: `name`, `description`, `template`
41β - Handlebars templating for variable substitution
42β - Hot-reloading for development
43β
44β2. **Optional GitHub Sync**: When configured, syncs prompts from a GitHub repository
45β - Non-destructive sync (preserves local-only files)
46β - Security measures against path traversal
47β - Periodic sync with configurable interval
48β
49β3. **Authentication**: Uses existing proxy authentication
50β - Bearer token required for MCP endpoint access
<system-reminder>
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
</system-reminder>
Show less
Tool Use: Read (ID: toolu_01TEMRF5qsFs6ChmpcTTcLnz)
{
"limit": 50,
"file_path": "/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/adr-017-mcp-prompt-sharing.md"
}
Tool Result (ID: toolu_01UAaMGMKNJihhXpzUQzci98)
Found 5 files
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/adr-016-mcp-server-implementation.md
/home/crystalin/projects/claude-nexus-pro...
Show more (4 lines)
Tool Result (ID: toolu_01UAaMGMKNJihhXpzUQzci98)
Found 5 files
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/adr-016-mcp-server-implementation.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/adr-017-mcp-prompt-sharing.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/mcp-server-actual-implementation.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/mcp-server-original-plan.md
Show less
Now let me check the MCP Prompts documentation:
Tool Use: Grep (ID: toolu_01UAaMGMKNJihhXpzUQzci98)
{
"path": "/home/crystalin/projects/claude-nexus-proxy/docs",
"pattern": "MCP.*Prompt|Model Context Protocol",
"output_mode": "files_with_matches"
}
Tool Result (ID: toolu_01BCJyq4WR2SVK4pyDVKmAEK)
1β# AI Analysis Feature Setup Guide
2β
3βThis guide will help you set up the AI-powered conversation analysis feature introduced in PR #80.
4β
5β## Prerequisites
6β
7β- PostgreSQL database
8β- Gemini AP...
Show more (49 lines)
Tool Result (ID: toolu_01BCJyq4WR2SVK4pyDVKmAEK)
1β# AI Analysis Feature Setup Guide
2β
3βThis guide will help you set up the AI-powered conversation analysis feature introduced in PR #80.
4β
5β## Prerequisites
6β
7β- PostgreSQL database
8β- Gemini API key (for AI analysis)
9β- Bun runtime installed
10β
11β## Setup Steps
12β
13β### 1. Database Migrations
14β
15βYou need to run two migrations to create the required database tables:
16β
17β```bash
18β# Migration 011: Creates conversation_analyses table
19βbun run scripts/db/migrations/011-add-conversation-analyses.ts
20β
21β# Migration 012: Creates analysis_audit_log table
22βbun run scripts/db/migrations/012-add-analysis-audit-log.ts
23β```
24β
25βThese migrations will create:
26β
27β- `conversation_analyses` table - Stores AI analysis results
28β- `conversation_analysis_status` ENUM type
29β- `analysis_audit_log` table - Tracks all analysis operations
30β- Required indexes for performance
31β
32β### 2. Environment Variables
33β
34βAdd the following to your `.env` file:
35β
36β```bash
37β# ===================
38β# AI Analysis Configuration
39β# ===================
40β
41β# Enable the background worker (set to true to activate)
42βAI_WORKER_ENABLED=true
43β
44β# Worker polling settings
45βAI_WORKER_POLL_INTERVAL_MS=5000 # How often to check for new jobs
46βAI_WORKER_MAX_CONCURRENT_JOBS=3 # Max parallel analysis jobs
47βAI_WORKER_JOB_TIMEOUT_MINUTES=5 # Timeout for stuck jobs
48β
49β# Retry configuration
50βAI_ANALYSIS_MAX_RETRIES=3 # Max retry attempts for failed analyses
<system-reminder>
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
</system-reminder>
Show less
Tool Use: Read (ID: toolu_01BCJyq4WR2SVK4pyDVKmAEK)
{
"limit": 50,
"file_path": "/home/crystalin/projects/claude-nexus-proxy/docs/02-User-Guide/ai-analysis.md"
}
Tool Result (ID: toolu_018paMb8zzpnrEf2jaSTxerd)
Found 11 files
/home/crystalin/projects/claude-nexus-proxy/docs/02-User-Guide/ai-analysis.md
/home/crystalin/projects/claude-nexus-proxy/docs/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/README.md
/home/crys...
Show more (9 lines)
Tool Result (ID: toolu_018paMb8zzpnrEf2jaSTxerd)
Found 11 files
/home/crystalin/projects/claude-nexus-proxy/docs/02-User-Guide/ai-analysis.md
/home/crystalin/projects/claude-nexus-proxy/docs/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/ADRs/adr-018-ai-powered-conversation-analysis.md
/home/crystalin/projects/claude-nexus-proxy/docs/04-Architecture/feature-plan-ai-analysis.md
/home/crystalin/projects/claude-nexus-proxy/docs/06-Reference/environment-vars.md
/home/crystalin/projects/claude-nexus-proxy/docs/api/openapi-analysis.yaml
/home/crystalin/projects/claude-nexus-proxy/docs/api/README.md
/home/crystalin/projects/claude-nexus-proxy/docs/00-Overview/features.md
/home/crystalin/projects/claude-nexus-proxy/docs/03-Operations/ai-analysis-security.md
/home/crystalin/projects/claude-nexus-proxy/docs/03-Operations/database.md
Show less
Let me also check for any existing AI Analysis documentation:
Tool Use: Grep (ID: toolu_018paMb8zzpnrEf2jaSTxerd)
{
"path": "/home/crystalin/projects/claude-nexus-proxy/docs",
"pattern": "AI.*Analysis|ai-analysis",
"output_mode": "files_with_matches"
}
Tool Result (ID: toolu_013VVhrJrUAKZmTWWSHdeCea)
1β# Claude Nexus Proxy
2β
3βA high-performance proxy for Claude API with comprehensive monitoring, conversation tracking, and dashboard visualization.
4β
5β## Features
6β
7β- π **High-Performance Proxy** - ...
Show more (100 lines)
Tool Result (ID: toolu_013VVhrJrUAKZmTWWSHdeCea)
1β# Claude Nexus Proxy
2β
3βA high-performance proxy for Claude API with comprehensive monitoring, conversation tracking, and dashboard visualization.
4β
5β## Features
6β
7β- π **High-Performance Proxy** - Built with Bun and Hono for minimal latency
8β- π **Conversation Tracking** - Automatic message threading with branch support
9β- π **Real-time Dashboard** - Monitor usage, view conversations, and analyze patterns
10β- π **Multi-Auth Support** - API keys and OAuth with auto-refresh
11β- π **Token Tracking** - Detailed usage statistics per domain and account
12β- π **Streaming Support** - Full SSE streaming with chunk storage
13β- π³ **Docker Ready** - Separate optimized images for each service
14β- π€ **Claude CLI Integration** - Run Claude CLI connected to the proxy
15β- π§ **AI-Powered Analysis** - Automated conversation insights using Gemini Pro
16β
17β## Quick Start
18β
19β### Prerequisites
20β
21β- [Bun](https://bun.sh) runtime (v1.0+)
22β- PostgreSQL database
23β- Claude API key
24β
25β### Installation
26β
27β```bash
28β# Clone the repository
29βgit clone https://github.com/yourusername/claude-nexus-proxy.git
30βcd claude-nexus-proxy
31β
32β# Install dependencies
33βbun install
34β
35β# Set up environment variables
36βcp .env.example .env
37β# Edit .env with your settings
38β
39β# Initialize database
40βbun run db:migrate:token-usage
41β
42β# Start development servers
43βbun run dev
44β```
45β
46βThe proxy runs on `http://localhost:3000` and dashboard on `http://localhost:3001`.
47β
48β### Using Claude CLI with the Proxy
49β
50βRun Claude CLI connected to your local proxy:
51β
52β```bash
53β# Start the proxy and Claude CLI
54βdocker compose --profile dev --profile claude up -d
55β
56β# Access Claude CLI
57βdocker compose exec claude-cli claude
58β
59β# Or run a single command
60βdocker compose exec claude-cli claude "What is 2+2?"
61β```
62β
63βThe Claude CLI will use Bearer token authentication to connect through the proxy.
64β
65β### Viewing Proxy Logs
66β
67βAfter running Claude queries, you can view the proxy logs to debug issues:
68β
69β```bash
70β# View recent logs
71βdocker compose logs proxy
72β
73β# Follow logs in real-time
74βdocker compose logs -f proxy
75β
76β# Use the helper script for filtered views
77β./scripts/view-claude-logs.sh --help
78β
79β# Examples:
80β./scripts/view-claude-logs.sh -f # Follow logs
81β./scripts/view-claude-logs.sh -e -n 100 # Show last 100 errors
82β./scripts/view-claude-logs.sh -r # Show API requests
83β```
84β
85β## Configuration
86β
87β### Environment Variables
88β
89βEssential configuration:
90β
91β```bash
92β# Database
93βDATABASE_URL=postgresql://user:password@localhost:5432/claude_nexus
94β
95β# Dashboard Authentication
96β# β οΈ CRITICAL SECURITY WARNING: Without this key, the dashboard runs in read-only mode
97β# with NO authentication, exposing ALL conversation data to anyone with network access!
98β# NEVER deploy to production without setting this!
99βDASHBOARD_API_KEY=your-secure-key
100β
<system-reminder>
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
</system-reminder>
Show less
Now let me check the main README.md to understand its current structure and style:
Tool Use: Read (ID: toolu_013VVhrJrUAKZmTWWSHdeCea)
{
"limit": 100,
"file_path": "/home/crystalin/projects/claude-nexus-proxy/README.md"
}
Tool Result (ID: toolu_01S1CoHYE5qRCQMN2qbZPYey)
1β# Dashboard Guide
2β
3βThe Claude Nexus Proxy Dashboard provides real-time monitoring and analytics for your Claude API usage.
4β
5β## Accessing the Dashboard
6β
7β### Default Access
8β
9βThe das...
Show more (366 lines)
Tool Result (ID: toolu_01S1CoHYE5qRCQMN2qbZPYey)
1β# Dashboard Guide
2β
3βThe Claude Nexus Proxy Dashboard provides real-time monitoring and analytics for your Claude API usage.
4β
5β## Accessing the Dashboard
6β
7β### Default Access
8β
9βThe dashboard runs on port 3001 by default:
10β
11β```
12βhttp://localhost:3001
13β```
14β
15β### Authentication
16β
17βEnter your dashboard API key on the login page. This key is configured in your `.env` file:
18β
19β```bash
20βDASHBOARD_API_KEY=your-secure-dashboard-key
21β```
22β
23βThe authentication is stored as a cookie for the session.
24β
25β## Dashboard Features
26β
27β### Overview Page
28β
29βThe main dashboard displays:
30β
31β- **Total Requests**: Cumulative request count
32β- **Total Tokens**: Combined input/output token usage
33β- **Active Domains**: Number of domains using the proxy
34β- **Total Sub-tasks**: Count of Task tool invocations
35β- **Success Rate**: Percentage of successful requests
36β- **Average Latency**: Mean response time
37β
38β### Real-time Metrics
39β
40βLive updates via Server-Sent Events (SSE) show:
41β
42β- Current request activity
43β- Token usage trends
44β- Error rates
45β- Response time distribution
46β
47β### Token Usage Analytics
48β
49β#### Current Window (5-hour)
50β
51βMonitor Claude API rate limits:
52β
53β- Token consumption by account
54β- Usage percentage of 5-hour limit
55β- Time until window reset
56β- Projected usage trends
57β
58β#### Historical Usage
59β
60βView daily token usage:
61β
62β- Daily breakdown by account/domain
63β- Cost estimation
64β- Usage patterns and trends
65β- Export data for analysis
66β
67β### Conversation Tracking
68β
69β#### Conversation List
70β
71β- Grouped by conversation ID
72β- Shows message count per conversation
73β- Branch visualization
74β- Sub-task indicators
75β
76β#### Conversation Timeline
77β
78βInteractive visualization showing:
79β
80β- Message flow with timestamps
81β- Branch points (blue nodes)
82β- Sub-tasks (gray boxes)
83β- Token usage per message
84β
85β#### Sub-task Visualization
86β
87β- Spawned tasks appear as separate nodes
88β- Click to navigate to sub-task conversation
89β- Hover for task prompt preview
90β- Shows task completion status
91β
92β### Request History
93β
94βBrowse individual requests with:
95β
96β- Request/response details
97β- Token counts
98β- Latency metrics
99β- Error messages
100β- Full JSON payloads
101β- Image display for tool_result content (PNG, JPEG, GIF, WebP)
102β
103βFilter by:
104β
105β- Domain
106β- Time range
107β- Request type
108β- Status (success/error)
109β
110β### Account Management
111β
112βView per-account statistics:
113β
114β- Token usage by account ID
115β- Domain associations
116β- Authentication methods
117β- Usage limits and quotas
118β
119β## Navigation
120β
121β### URL Parameters
122β
123βMany dashboard views support URL parameters:
124β
125β```
126β# Filter by domain
127β/requests?domain=example.com
128β
129β# Filter by account
130β/token-usage?accountId=acc_12345
131β
132β# View specific conversation
133β/conversations?id=conv_uuid
134β
135β# Time range selection
136β/token-usage/daily?days=7
137β```
138β
139β### Keyboard Shortcuts
140β
141β- `r` - Refresh current view
142β- `f` - Toggle filters
143β- `esc` - Close modals
144β- `/` - Focus search
145β
146β## Charts and Visualizations
147β
148β### Token Usage Chart
149β
150β- Line chart showing usage over time
151β- Stacked by domain or account
152β- Zoom and pan capabilities
153β- Export as PNG/SVG
154β
155β### Latency Distribution
156β
157β- Histogram of response times
158β- P50, P95, P99 percentiles
159β- Identify performance outliers
160β
161β### Error Rate Trends
162β
163β- Error frequency over time
164β- Error type breakdown
165β- Correlation with usage spikes
166β
167β## Advanced Features
168β
169β### Caching
170β
171βDashboard responses are cached for performance:
172β
173β- Default TTL: 30 seconds
174β- Disable: `DASHBOARD_CACHE_TTL=0`
175β- Force refresh: Add `?refresh=true`
176β
177β### Export Data
178β
179βExport functionality for:
180β
181β- Token usage reports (CSV)
182β- Conversation histories (JSON)
183β- Request logs (JSON)
184β- Analytics summaries (PDF)
185β
186β### Real-time Notifications
187β
188βConfigure alerts for:
189β
190β- High error rates
191β- Token limit approaching
192β- Slow response times
193β- Failed authentications
194β
195β### Image Display in Tool Results
196β
197βThe dashboard supports displaying images from tool_result content:
198β
199β- **Supported formats**: PNG, JPEG, GIF, WebP
200β- **Maximum size**: 10MB per image
201β- **Display constraints**: Images are automatically resized to fit within the conversation view
202β- **Security**: Base64 data URIs are validated and sanitized
203β- **Performance**: Images use lazy loading for better page performance
204β
205β## Performance Monitoring
206β
207β### Slow Query Detection
208β
209βQueries exceeding threshold are logged:
210β
211β```bash
212βSLOW_QUERY_THRESHOLD_MS=5000
213β```
214β
215βView slow queries in:
216β
217β- Dashboard logs
218β- Performance tab
219β- Database metrics
220β
221β### Database Statistics
222β
223βMonitor PostgreSQL performance:
224β
225β- Active connections
226β- Query execution time
227β- Index usage
228β- Table sizes
229β
230β## Troubleshooting Dashboard Issues
231β
232β### Dashboard Won't Load
233β
234β1. Check service is running:
235β
236β ```bash
237β curl http://localhost:3001/health
238β ```
239β
240β2. Verify database connection:
241β
242β ```bash
243β psql $DATABASE_URL -c "SELECT 1"
244β ```
245β
246β3. Check logs:
247β ```bash
248β docker compose logs dashboard
249β ```
250β
251β### Authentication Issues
252β
253β1. Verify API key in .env:
254β
255β ```bash
256β echo $DASHBOARD_API_KEY
257β ```
258β
259β2. Clear browser cookies
260β
261β3. Try incognito/private mode
262β
263β### Missing Data
264β
265β1. Ensure storage is enabled:
266β
267β ```bash
268β STORAGE_ENABLED=true
269β ```
270β
271β2. Check request processing:
272β
273β ```bash
274β SELECT COUNT(*) FROM api_requests;
275β ```
276β
277β3. Verify streaming chunks:
278β ```bash
279β SELECT COUNT(*) FROM streaming_chunks;
280β ```
281β
282β### Performance Issues
283β
284β1. Enable query logging:
285β
286β ```bash
287β SLOW_QUERY_THRESHOLD_MS=1000
288β ```
289β
290β2. Check database indexes:
291β
292β ```sql
293β SELECT * FROM pg_indexes WHERE tablename = 'api_requests';
294β ```
295β
296β3. Monitor connection pool:
297β ```bash
298β SELECT count(*) FROM pg_stat_activity;
299β ```
300β
301β## Dashboard API
302β
303βThe dashboard exposes APIs for integration:
304β
305β### Get Current Stats
306β
307β```bash
308βcurl http://localhost:3001/api/stats \
309β -H "X-Dashboard-Key: $DASHBOARD_API_KEY"
310β```
311β
312β### Get Token Usage
313β
314β```bash
315βcurl "http://localhost:3001/api/token-usage/current?window=300" \
316β -H "X-Dashboard-Key: $DASHBOARD_API_KEY"
317β```
318β
319β### Get Conversations
320β
321β```bash
322βcurl "http://localhost:3001/api/conversations?limit=10" \
323β -H "X-Dashboard-Key: $DASHBOARD_API_KEY"
324β```
325β
326β## Customization
327β
328β### Environment Variables
329β
330β```bash
331β# Dashboard port
332βDASHBOARD_PORT=3001
333β
334β# Cache settings
335βDASHBOARD_CACHE_TTL=30
336β
337β# Display settings
338βDASHBOARD_TIMEZONE=UTC
339βDASHBOARD_DATE_FORMAT=ISO
340β
341β# Feature flags
342βDASHBOARD_ENABLE_EXPORT=true
343βDASHBOARD_ENABLE_REALTIME=true
344β```
345β
346β### Custom Themes
347β
348βPlace custom CSS in:
349β
350β```
351βservices/dashboard/public/custom.css
352β```
353β
354β## Best Practices
355β
356β1. **Regular Monitoring**: Check dashboard daily for anomalies
357β2. **Set Up Alerts**: Configure notifications for critical metrics
358β3. **Archive Old Data**: Export and archive historical data monthly
359β4. **Monitor Costs**: Track token usage against budget
360β5. **Review Errors**: Investigate error patterns weekly
361β
362β## Next Steps
363β
364β- [Configure alerts](../03-Operations/monitoring.md)
365β- [Optimize performance](../05-Troubleshooting/performance.md)
366β- [Set up backups](../03-Operations/backup-recovery.md)
367β- [Review security](../03-Operations/security.md)
368β
<system-reminder>
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
</system-reminder>
Show less
I'll help you analyze the documentation to determine the best approach for adding screenshots to the README. Let me examine the relevant documentation files.
Tool Use: Read (ID: toolu_01S1CoHYE5qRCQMN2qbZPYey)
{
"file_path": "/home/crystalin/projects/claude-nexus-proxy/docs/02-U...
Show more (3 lines)
I'll help you analyze the documentation to determine the best approach for adding screenshots to the README. Let me examine the relevant documentation files.
Tool Use: Read (ID: toolu_01S1CoHYE5qRCQMN2qbZPYey)
{
"file_path": "/home/crystalin/projects/claude-nexus-proxy/docs/02-User-Guide/dashboard-guide.md"
}
Show less
Conte...
Show more (858 lines)Contents of /home/crystalin/projects/claude-nexus-proxy/CLAUDE.md (project instructions, checked into the codebase):
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with this repository.
Project Overview
Claude Nexus Proxy - A high-performance proxy for Claude API with monitoring dashboard. Built with Bun and Hono framework, deployed as separate Docker images for each service.
Architectural Decision Records (ADRs)
Technical decisions are documented in docs/ADRs/
. Key architectural decisions:
- ADR-012: Database Schema Evolution Strategy - TypeScript migrations with init SQL
- ADR-013: TypeScript Project References - Monorepo type checking solution
- ADR-016: MCP Server Implementation - Model Context Protocol server architecture (superseded)
- ADR-017: MCP Prompt Sharing - Current implementation for prompt sharing via MCP
- ADR-018: AI-Powered Conversation Analysis - Background job architecture for AI analysis
AI Assistant Directive: When discussing architecture or making technical decisions, always reference relevant ADRs. If a new architectural decision is made during development, create or update an ADR to document it. This ensures all technical decisions have clear rationale and can be revisited if needed.
Architecture
Monorepo Structure
claude-nexus-proxy/
βββ packages/shared/ # Shared types and configurations
βββ services/
β βββ proxy/ # Proxy API service (Port 3000)
β βββ dashboard/ # Dashboard web service (Port 3001)
βββ scripts/ # Utility scripts
βββ docker/ # Docker configurations
β βββ proxy/ # Proxy Dockerfile
β βββ dashboard/ # Dashboard Dockerfile
βββ docker-compose.yml # Container orchestration
βββ .env # Proxy/Dashboard configuration
βββ credentials/ # Domain credentials (Claude Auth, Slack, ...)
Key Services
Proxy Service (services/proxy/
)
- Direct API forwarding to Claude
- Multi-auth support (API keys, OAuth with auto-refresh)
- Token tracking and telemetry
- Request/response storage
- Slack notifications
- AI-powered conversation analysis (Phase 2 - Prompt Engineering with full env var support)
Dashboard Service (services/dashboard/
)
- Monitoring UI
- Analytics and usage charts
- Request history browser
- SSE for live updates
- β οΈ SECURITY WARNING: Read-only mode (when
DASHBOARD_API_KEY
is not set) exposes all data without authentication. See ADR-019
Development
# Install dependencies
bun install
# Run both services
bun run dev
# Run individually
bun run dev:proxy # Port 3000
bun run dev:dashboard # Port 3001
# Build
bun run build
Git Pre-commit Hooks
The project uses Husky and lint-staged for automated code quality checks:
# Pre-commit hooks are automatically installed via postinstall script
bun install
# Manual hook installation (if needed)
bunx husky init
Pre-commit checks:
- ESLint fixes for TypeScript/JavaScript files
- Prettier formatting for all supported file types
- Automatic fixes are applied when possible
Note: TypeScript type checking is not included in pre-commit hooks for performance reasons. Type checking runs in CI/CD pipeline.
Docker Deployment
The project uses separate Docker images for each service:
# Build images
./docker/build-images.sh
# Run proxy service
docker run -p 3000:3000 alanpurestake/claude-nexus-proxy:latest
# Run dashboard service
docker run -p 3001:3001 alanpurestake/claude-nexus-dashboard:latest
Docker configurations are in the docker/
directory. Each service has its own optimized image for better security, scaling, and maintainability.
Docker Compose Environment
docker/docker-compose.yml: Postgres + Proxy + Dashboard + Claude CLI (with ccusage and token monitoring). ./docker-up.sh
script is used instead of docker compose -f ...
to ensure .env
is loaded properly.
# Build the local images
./docker-up.sh build
# Run the full environment (requires real Claude account in )
./docker-up.sh up -d
# Run a claude query
./docker-up.sh exec claude-cli claude "hi"
# Run usage monitor for real-time tracking
./docker-up.sh exec claude-cli monitor
# Check daily usage stats
./docker-up.sh exec claude-cli ccusage daily
Key Implementation Details
Request Timeout Configuration
The proxy supports long-running Claude API requests with configurable timeouts:
- Default timeout: 10 minutes (600,000ms) for Claude API requests
- Server timeout: 11 minutes (660,000ms) to prevent premature connection closure
- Retry timeout: Slightly longer than request timeout to allow for retries
- Configure via
CLAUDE_API_TIMEOUT
andPROXY_SERVER_TIMEOUT
environment variables
Conversation Tracking & Branching
The proxy automatically tracks conversations and detects branches using message hashing:
How it works:
- Each message in a request is hashed using SHA-256
- The current message hash and parent message hash (previous message) are stored
- Requests are linked into conversations by matching parent/child relationships
- Conversations support branching (like git) when resumed from earlier points
- Branches are automatically detected when multiple requests share the same parent
- When multiple conversations have the same parent hash, the system picks the conversation with the fewest requests to continue
- Messages continue on the same branch as their parent unless they create a new branch point
Message Normalization:
- String content and array content are normalized to produce consistent hashes
- Example:
"hello"
and[{type: "text", text: "hello"}]
produce the same hash - System reminders are filtered out: Content items starting with
<system-reminder>
are ignored during hashing - Duplicate messages are deduplicated: When tool_use or tool_result messages have duplicate IDs, only the first occurrence is included in the hash
- This ensures conversations link correctly regardless of content format, system reminder presence, or duplicate messages from the Claude API
Dual Hash System:
- Message Hash: Used for conversation linking, contains only message content
- System Hash: Tracks system prompt separately, stored in
system_hash
column - This allows conversations to maintain links even when system prompts change (e.g., git status updates, context compaction)
- Backward compatible: Old conversations continue to work without modification
Special Conversation Handling:
- Conversation Summarization: When Claude summarizes a conversation (detected by system prompt "You are a helpful AI assistant tasked with summarizing conversations"), the system links to the previous conversation ignoring system prompt differences
- Compact Conversations: When a conversation is continued from a previous one due to context overflow (first message starts with "This session is being continued from a previous conversation..."), it:
- Links to the source conversation automatically
- Creates a special branch ID format:
compact_HHMMSS
- Preserves the compact branch for all follow-up messages in that conversation
- Prevents unnecessary branching when continuing compact conversations
API Endpoints:
/api/conversations
- Get conversations grouped by conversation_id with branch information- Query parameters:
domain
(filter by domain),limit
(max conversations)
Database Schema:
conversation_id
- UUID identifying the conversationcurrent_message_hash
- Hash of the last message in the requestparent_message_hash
- Hash of the previous message (null for first message)system_hash
- Hash of the system prompt (for tracking context changes)branch_id
- Branch identifier (defaults to 'main', auto-generated for new branches)parent_request_id
- Direct link to the parent request in the conversation chain
Dashboard Features:
- Conversations View - Visual timeline showing message flow and branches
- Branch Visualization - Blue nodes indicate branch points
- Branch Labels - Non-main branches are labeled with their branch ID
- Conversation Grouping - All related requests grouped under one conversation
- Multiple Tool Display - Messages with multiple tool_use or tool_result blocks are properly displayed with visual separation (horizontal rules between each tool invocation)
- Duplicate Filtering - Duplicate tool_use and tool_result blocks (same ID) are automatically filtered out
- System Reminder Filtering - System reminder text blocks are hidden from display
Authentication Flow
Client Authentication (Proxy Level):
- Extract domain from Host header
- Check for
client_api_key
in domain credential file - Verify Bearer token against stored key using timing-safe comparison
- Return 401 Unauthorized if invalid
Claude API Authentication:
- Check domain-specific credential files (
<domain>.credentials.json
) - Use Authorization header from request
OAuth Support
- Auto-refresh tokens 1 minute before expiry
- Stores refreshed tokens back to credential files
- Adds
anthropic-beta: oauth-2025-04-20
header
MCP (Model Context Protocol) Server
The proxy includes an MCP server for managing and serving prompts:
Features:
- File-based prompt storage using YAML files in
prompts/
directory - Prompts are named after their file name (e.g.,
feature.yaml
becomes/feature
) - Handlebars templating with
{{variable}}
syntax - Hot-reloading when files change
- Optional GitHub repository synchronization
Configuration:
# Basic MCP setup (file-based)
MCP_ENABLED=true
MCP_PROMPTS_DIR=./prompts
MCP_WATCH_FILES=true
# Optional GitHub sync
MCP_GITHUB_OWNER=your-org
MCP_GITHUB_REPO=prompt-library
MCP_GITHUB_BRANCH=main
MCP_GITHUB_TOKEN=ghp_xxxx
MCP_GITHUB_PATH=prompts/
MCP_SYNC_INTERVAL=300
How it works:
- When only
MCP_ENABLED=true
is set, prompts are loaded from local YAML files - When GitHub credentials are configured, the system syncs from the repository
- GitHub sync fetches prompts and writes them to the local filesystem
- Important: GitHub sync only replaces files that exist in the repository, preserving local-only prompts
- Files are validated to prevent path traversal security vulnerabilities
- The PromptRegistryService loads prompts from files into memory
- MCP protocol endpoints are available at
/mcp
Prompt format:
# Note: The prompt name in Claude will be the file name (without .yaml extension)
# For example, this file saved as 'my-feature.yaml' will be available as '/my-feature'
name: My Prompt # This field is ignored - file name is used instead
description: Description of the prompt
template: |
You are {{role}}.
{{#if context}}
Context: {{context}}
{{/if}}
Using MCP with Claude Desktop:
Install the MCP server in Claude Desktop:
claude mcp add nexus-prompts --scope user -- bunx -y mcp-remote@latest http://localhost:3000/mcp --header "Authorization: Bearer YOUR_CLIENT_API_KEY"
Replace YOUR_CLIENT_API_KEY with the actual client API key from your domain's credential file (e.g.,
cnp_live_...
)Restart Claude Desktop to load the MCP server
Available commands:
- Prompts will appear as slash commands in Claude (e.g.,
/feature
for a prompt namedfeature.yaml
) - Use tab completion to see available prompts
- Prompts will appear as slash commands in Claude (e.g.,
MCP Implementation Details:
- Protocol Version: Uses MCP protocol version
2024-11-05
- Authentication: Bearer token authentication via client API keys
- Endpoints:
POST /mcp
- Main MCP JSON-RPC endpointGET /mcp
- Discovery endpoint
- Supported Methods:
initialize
- Protocol handshakeprompts/list
- List available promptsprompts/get
- Get and render a specific prompt with variables
Token Tracking
In-Memory Tracking (Legacy)
- Per-domain statistics
- Request type classification (query evaluation vs inference)
- Tool call counting
- Available at
/token-stats
endpoint
Comprehensive Token Usage Tracking (New)
- Tracks ALL request types (including query_evaluation and quota)
- Persistent storage in partitioned
token_usage
table - 5-hour rolling window support for monitoring Claude API limits
- Per-account AND per-domain tracking
- API endpoints:
/api/token-usage/current
- Current window usage/api/token-usage/daily
- Historical daily usage data/api/conversations
- Conversations with account info
- Note: Rate limiting is handled by Claude API directly. The proxy only tracks and displays usage statistics.
Storage
- PostgreSQL for request/response data
- Write-only access from proxy
- Read-only access from dashboard
- Automatic batch processing
- Conversation Grouping: Requests are automatically grouped by conversation using message hashing
Debug Logging
When DEBUG=true
:
- Logs full request/response (with sensitive data masked)
- Shows streaming chunks
- Masks patterns:
sk-ant-****
,Bearer ****
- Includes SQL query stack traces
SQL Query Logging
Enable SQL query logging in debug mode:
# Option 1: Enable all debug logging (includes SQL)
DEBUG=true bun run dev
# Option 2: Enable only SQL query logging
DEBUG_SQL=true bun run dev
# Option 3: Set in .env file
DEBUG_SQL=true
SQL logging features:
- All queries with parameters
- Query execution time
- Row counts
- Slow query warnings (default: >5 seconds)
- Failed query errors with details
Environment Variables
Essential:
DATABASE_URL
- PostgreSQL connectionDASHBOARD_API_KEY
- Dashboard authentication (β οΈ CRITICAL: Without this, dashboard runs in read-only mode with NO authentication)
Optional:
DEBUG
- Enable debug loggingDEBUG_SQL
- Enable SQL query logging (default: false)STORAGE_ENABLED
- Enable storage (default: false)SLACK_WEBHOOK_URL
- Slack notificationsCREDENTIALS_DIR
- Domain credential directoryCOLLECT_TEST_SAMPLES
- Collect request samples for testing (default: false)TEST_SAMPLES_DIR
- Directory for test samples (default: test-samples)ENABLE_CLIENT_AUTH
- Enable client API key authentication (default: true). Set to false to allow anyone to use the proxy without authenticationDASHBOARD_CACHE_TTL
- Dashboard cache TTL in seconds (default: 30). Set to 0 to disable cachingSLOW_QUERY_THRESHOLD_MS
- Threshold in milliseconds for logging slow SQL queries (default: 5000)CLAUDE_API_TIMEOUT
- Timeout for Claude API requests in milliseconds (default: 600000 / 10 minutes)PROXY_SERVER_TIMEOUT
- Server-level timeout in milliseconds (default: 660000 / 11 minutes)STORAGE_ADAPTER_CLEANUP_MS
- Interval for cleaning up orphaned request ID mappings in milliseconds (default: 300000 / 5 minutes)STORAGE_ADAPTER_RETENTION_MS
- Retention time for request ID mappings in milliseconds (default: 3600000 / 1 hour)API_KEY_SALT
- Salt for hashing API keys in database (default: 'claude-nexus-proxy-default-salt')SPARK_API_URL
- Spark API base URL for recommendation feedback (default: 'http://localhost:8000')SPARK_API_KEY
- API key for authenticating with Spark API
Important Notes
Request Metadata
- Query evaluation and quota are not part of the conversation, they serve as metadata queries
Testing & Type Safety
Type Checking:
- Run
bun run typecheck
before committing - Type checking is automatic during builds
- Fix all type errors before deploying
- TypeScript Project References: The monorepo uses TypeScript Project References for proper dependency management
- Automatically handles build order between packages
- Generates declaration files for cross-package imports
- Run
tsc --build
at the root to type check all packages - See ADR-013 for details on this architectural decision
Test Sample Collection: The proxy can collect real request samples for test development:
- Enable with
COLLECT_TEST_SAMPLES=true
- Samples are stored in
test-samples/
directory - Each request type gets its own file (e.g.,
inference_streaming_opus.json
) - Sensitive data is automatically masked
- Samples include headers, body, and metadata
Tests:
The project includes comprehensive tests for conversation and subtask linking:
Conversation Linking Tests:
packages/shared/src/utils/__tests__/conversation-linker.test.ts
- Tests message hashing, branch detection, and conversation linking
- Includes JSON fixture tests for real-world scenarios
- Tests integrated subtask detection within ConversationLinker
Subtask Detection Tests:
packages/shared/src/utils/__tests__/subtask-detection.test.ts
- Tests complete subtask detection logic in ConversationLinker
- Validates TaskContext handling and invocation matching
- Tests conversation inheritance and branch naming
- Covers edge cases like multi-message conversations
Subtask Linking Simulation:
packages/shared/src/utils/__tests__/subtask-linker.test.ts
- Simulates the old two-phase subtask detection (for reference)
- Tests Task tool invocation matching
- Validates time window enforcement
- Includes JSON fixtures for various subtask scenarios
Run tests with:
# All tests
bun test
# Specific package
cd packages/shared && bun test
# Specific test file
bun test conversation-linker.test.ts
Important Notes
- Uses Bun runtime exclusively (no Node.js)
- Separate Docker images for each service
- TypeScript compilation for production builds
- Model-agnostic (accepts any model name)
Database Schema
Main Tables
api_requests - Stores all API requests and responses with token tracking:
account_id
- Account identifier from credential files for per-account trackinginput_tokens
,output_tokens
,total_tokens
- Token usage metricsconversation_id
,branch_id
- Conversation trackingcurrent_message_hash
,parent_message_hash
- Message linkingparent_task_request_id
,is_subtask
,task_tool_invocation
- Sub-task tracking
streaming_chunks - Stores streaming response chunks
Account-Based Token Tracking
Token usage is tracked directly in the api_requests
table:
- Each request is associated with an
account_id
from the credential file - Token counts are stored per request for accurate tracking
- Queries aggregate usage by account and time window
Database Schema Evolution
Schema Management:
- Initial schema:
scripts/init-database.sql
- Migrations:
scripts/db/migrations/
(TypeScript files) - Auto-initialization:
writer.ts
uses init SQL file when tables don't exist
Running Migrations:
# Run a specific migration
bun run scripts/db/migrations/001-add-conversation-tracking.ts
# Run all migrations in order
for file in scripts/db/migrations/*.ts; do bun run "$file"; done
Available Migrations:
- 000: Initial database setup
- 001: Add conversation tracking
- 002: Optimize conversation indexes
- 003: Add sub-task tracking
- 004: Optimize window function queries
- 005: Populate account IDs
- 006: Split conversation hashes
- 007: Add parent_request_id
- 008: Update subtask conversation IDs and optimize Task queries
See docs/04-Architecture/ADRs/adr-012-database-schema-evolution.md
for details.
Common Tasks
Add Domain Credentials
# Generate secure client API key
bun run scripts/generate-api-key.ts
# Create credential file
cat > credentials/domain.com.credentials.json << EOF
{
"type": "api_key",
"accountId": "acc_f9e1c2d3b4a5", # Unique account identifier
"api_key": "sk-ant-...",
"client_api_key": "cnp_live_..."
}
EOF
Enable Storage
export STORAGE_ENABLED=true
export DATABASE_URL=postgresql://...
View Token Stats
curl http://localhost:3000/token-stats
Access Dashboard
open http://localhost:3001
# Use DASHBOARD_API_KEY for authentication
# Auth header: X-Dashboard-Key: <your-key>
Sub-task Tracking & Visualization
Sub-task Detection
The proxy automatically detects and tracks sub-tasks spawned using the Task tool through an integrated single-phase process:
Single-Phase Detection (ConversationLinker):
- Complete subtask detection happens within ConversationLinker using the SubtaskQueryExecutor pattern
- SQL queries retrieve Task invocations from database (24-hour window)
- Matches single-message user conversations against recent Task invocations (30-second window)
- Sets
is_subtask=true
and links to parent viaparent_task_request_id
- Subtasks inherit parent's conversation_id with unique branch naming (subtask_1, subtask_2, etc.)
Architecture Components:
- SubtaskQueryExecutor: Injected function that queries for Task tool invocations
- ConversationLinker: Central component handling all conversation and subtask linking logic
- Optimized SQL Queries: Uses PostgreSQL
@>
containment operator for exact prompt matching - RequestByIdExecutor: Fetches parent task details for conversation inheritance
- GIN Index: Full JSONB index on response_body for efficient containment queries
Query Optimization:
When the subtask prompt is known, the system uses an optimized query:
response_body @> jsonb_build_object(
'content', jsonb_build_array(
jsonb_build_object(
'type', 'tool_use',
'name', 'Task',
'input', jsonb_build_object('prompt', $4::text)
)
)
)
This leverages the GIN index for O(log n) lookup performance instead of scanning all Task invocations.
Database Fields:
parent_task_request_id
- Links sub-task requests to their parent taskis_subtask
- Boolean flag indicating if a request is a confirmed sub-tasktask_tool_invocation
- JSONB array storing Task tool invocations (for historical queries)
Sub-task Linking:
- Sub-tasks are linked by exact matching of user message to Task tool invocation prompts
- The system creates parent-child relationships between tasks and their sub-tasks
- Multiple sub-tasks can be spawned from a single parent request
- Sub-tasks inherit parent task's conversation_id with sequential branch IDs (subtask_1, subtask_2, etc.)
Dashboard Visualization
Conversation Tree:
- Sub-task nodes appear as separate gray boxes to the right of parent nodes
- Format: "sub-task N (M)" where N is the sub-task number and M is the message count
- Sub-task boxes are clickable and link to their conversation
- Hover over sub-task boxes to see the task prompt in a tooltip
Stats Display:
- "Total Sub-tasks" panel shows count of all sub-tasks in a conversation
- Sub-task indicators on parent nodes show number of spawned tasks
Visual Design:
- Sub-task boxes: 100x36px gray boxes with 150px right offset
- Tooltips: 250x130px with gradient background, appear above nodes on hover
- Connected to parent nodes with horizontal edges
Important Implementation Notes
Conversation Hash Filtering
When generating message hashes for conversation tracking, the system filters out:
- Content items that start with
<system-reminder>
- This prevents conversation linking from breaking when Claude adds system reminders
Dashboard Authentication
- Uses
X-Dashboard-Key
header (not Authorization) - Cookie-based auth also supported for browser sessions
AI-Powered Conversation Analysis
The proxy supports automated analysis of conversations using AI models (currently Gemini 1.5 Flash or 2.5 Pro):
Features:
- Background processing of conversations for insights
- Status tracking (pending, processing, completed, failed)
- Token usage tracking for cost management
- Retry logic with exponential backoff
- Unique analyses per conversation and branch
- Comprehensive environment variable configuration for prompt tuning
- Graceful handling of unparseable JSON responses
- Automatic failure of jobs exceeding max retries
- Custom prompt support for targeted analysis
Error Handling:
- JSON Parse Failures: When the AI model returns malformed JSON, the system stores the raw text response instead of failing
- Max Retry Exceeded: Jobs that exceed
AI_ANALYSIS_MAX_RETRIES
are automatically marked as failed with clear error messages - Non-retryable Errors: Sensitive information detection and API key issues fail immediately without retries
Database Schema:
conversation_analyses
table stores analysis results- ENUM type for status field ensures data integrity
- Automatic
updated_at
timestamp via trigger - Partial index on pending status for efficient queue processing
- Supports both structured data (
analysis_data
) and raw text (analysis_content
)
API Endpoints:
POST /api/analyses
- Create analysis request (supportscustomPrompt
)GET /api/analyses/:conversationId/:branchId
- Get analysis status/resultPOST /api/analyses/:conversationId/:branchId/regenerate
- Force regeneration with optional custom prompt
Utility Scripts:
scripts/check-analysis-jobs.ts
- Check status of analysis jobsscripts/check-ai-worker-config.ts
- Verify AI worker configurationscripts/reset-stuck-analysis-jobs.ts
- Reset jobs stuck with high retry countsscripts/fail-exceeded-retry-jobs.ts
- Manually fail jobs exceeding max retriesscripts/check-analysis-content.ts
- Inspect analysis content for a conversation
Implementation Status:
- β Database schema (Migration 011, 012)
- β API endpoints with custom prompt support
- β Prompt engineering with actionable feedback
- β Background worker with resilient error handling
- β Dashboard UI with analysis panel
- β Graceful JSON parse failure handling
- β Automatic max retry failure
See ADR-016 for architectural decisions.
Background Worker Configuration:
Enable the AI Analysis background worker by setting these environment variables:
# Enable the worker
AI_WORKER_ENABLED=true
# Worker configuration
AI_WORKER_POLL_INTERVAL_MS=5000 # Poll every 5 seconds
AI_WORKER_MAX_CONCURRENT_JOBS=3 # Process up to 3 jobs concurrently
AI_WORKER_JOB_TIMEOUT_MINUTES=5 # Mark jobs as stuck after 5 minutes
# Resilience configuration
AI_ANALYSIS_MAX_RETRIES=3 # Retry failed jobs up to 3 times
AI_ANALYSIS_GEMINI_REQUEST_TIMEOUT_MS=60000 # Gemini API request timeout
# Gemini API configuration
GEMINI_API_KEY=your-api-key-here
GEMINI_API_URL=https://generativelanguage.googleapis.com/v1beta/models
GEMINI_MODEL_NAME=gemini-2.0-flash-exp
# Prompt engineering configuration (optional)
AI_MAX_PROMPT_TOKENS=855000 # Override calculated token limit
AI_HEAD_MESSAGES=10 # Messages to keep from start
AI_TAIL_MESSAGES=30 # Messages to keep from end
# Analysis token limits
AI_ANALYSIS_INPUT_TRUNCATION_TARGET_TOKENS=8192 # Target token count for input message truncation
AI_ANALYSIS_TRUNCATE_FIRST_N_TOKENS=1000 # Tokens from conversation start
AI_ANALYSIS_TRUNCATE_LAST_M_TOKENS=4000 # Tokens from conversation end
The worker runs in-process with the proxy service and uses PostgreSQL row-level locking to safely process jobs across multiple instances.
Spark Tool Integration
The dashboard supports the Spark recommendation tool (mcp__spark__get_recommendation
):
Features:
- Automatic detection of Spark tool usage in conversations
- Display of recommendations in a formatted view
- Feedback UI for rating and commenting on recommendations
- Batch fetching of existing feedback
- Integration with Spark API for feedback submission
Configuration:
- Set
SPARK_API_URL
andSPARK_API_KEY
environment variables - The dashboard will automatically detect Spark recommendations in tool_result messages
- Users can submit feedback directly from the request details page
- The proxy logs Spark configuration at startup:
- When configured: Shows URL and confirms API key is set
- When not configured: Shows "SPARK_API_KEY not set"
API Endpoints:
POST /api/spark/feedback
- Submit feedback for a recommendationGET /api/spark/sessions/:sessionId/feedback
- Get feedback for a specific sessionPOST /api/spark/feedback/batch
- Get feedback for multiple sessions
Security Note:
The dashboard authentication cookie (dashboard_auth
) is set with httpOnly: false
to allow JavaScript access for making authenticated API calls from the browser to the proxy service. This is a security trade-off that enables the inline feedback component to work. Consider implementing a more secure approach such as:
- Using a separate API token for browser-based requests
- Implementing a server-side proxy endpoint in the dashboard
- Using session-based authentication with CSRF tokens
SQL Query Optimization
- Always include all required fields in SELECT statements
- Missing fields like
parent_task_request_id
,is_subtask
,task_tool_invocation
will break sub-task tracking - Use the SLOW_QUERY_THRESHOLD_MS env var to monitor query performance
Check Token Usage
# Current 5-hour window usage
curl "http://localhost:3000/api/token-usage/current?accountId=acc_f9e1c2d3b4a5&window=300" \
-H "X-Dashboard-Key: $DASHBOARD_API_KEY"
# Daily usage (last 30 days)
curl "http://localhost:3000/api/token-usage/daily?accountId=acc_f9e1c2d3b4a5&aggregate=true" \
-H "X-Dashboard-Key: $DASHBOARD_API_KEY"
# View conversations
curl "http://localhost:3000/api/conversations?accountId=acc_f9e1c2d3b4a5" \
-H "X-Dashboard-Key: $DASHBOARD_API_KEY"
Copy Conversation Between Databases
# Copy a conversation from one database to another
bun run db:copy-conversation --conversation-id <uuid> --dest-db <url> [options]
# Example: Copy to staging database (same table names)
bun run db:copy-conversation --conversation-id 123e4567-e89b-12d3-a456-426614174000 \
--dest-db "postgresql://user:pass@staging-host:5432/staging_db"
# Dry run to preview what would be copied
bun run db:copy-conversation --conversation-id 123e4567-e89b-12d3-a456-426614174000 \
--dest-db "postgresql://user:pass@staging-host:5432/staging_db" --dry-run
# Copy with streaming chunks
bun run db:copy-conversation --conversation-id 123e4567-e89b-12d3-a456-426614174000 \
--dest-db "postgresql://user:pass@staging-host:5432/staging_db" --include-chunks
# Use custom table names (e.g., from api_requests to api_requests_backup)
bun run db:copy-conversation --conversation-id 123e4567-e89b-12d3-a456-426614174000 \
--dest-db "postgresql://user:pass@staging-host:5432/staging_db" \
--source-table api_requests --dest-table api_requests_backup
Maintenance
Grooming
The process of grooming
is used to keep a clean repository. It should be performed regularly and rely on GROOMING.md
important-instruction-reminders
Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context or otherwise consider it in your response unless it is highly relevant to your task. Most of the time, it is not relevant.
</system-reminder>
I'm about to implement adding screenshots to the README.md. I've examined all the images and here's what they contain:
Capture d'Γ©cran 2025-07-19 224058.png
- Dashboard showing hourly request statistics with colorful bar chartsCapture d'Γ©cran 2025-07-19 231711.png
- Conversation tree visualization showing branching conversationsCapture d'Γ©cran 2025-07-23 212603.png
- Conversation details timeline view with branch filters and statsCapture d'Γ©cran 2025-07-23 213108.png
- MCP Prompts interface showing GitHub-synced promptsCapture d'Γ©cran 2025-07-23 213201.png
- Request details view showing tool results and conversation messagesCapture d'Γ©cran 2025-07-23 213210.png
- Raw JSON view of a request/responseai-analysis.png
- AI Analysis panel showing comprehensive conversation analysis
Please read through the documentation files and extract meaningful context (limited to 10 paragraphs) for:
- The best order to present these features
- How to write compelling captions that highlight the value
- Any specific naming conventions or style guidelines
- Whether the MCP Prompts feature should be included (it seems like a newer feature)
- Best practices for image alt text and accessibility
Focus on docs/02-User-Guide/dashboard-guide.md and the feature documentation.
Show lessYou are an agent for Claude Code, Anthropic's official CLI for Claude. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
Notes:
- NEVER create file...
You are an agent for Claude Code, Anthropic's official CLI for Claude. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
Notes:
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
- For clear communication with the user the assistant MUST avoid using emojis.
Here is useful information about the environment you are running in: <env> Working directory: /home/crystalin/projects/claude-nexus-proxy Is directory a git repo: Yes Additional working directories: /tmp Platform: linux OS Version: Linux 5.15.167.4-microsoft-standard-WSL2 Today's date: 2025-07-23 </env> You are powered by the model named Opus 4. The exact model ID is claude-opus-4-20250514.
Assistant knowledge cutoff is January 2025.
gitStatus: This is the git status at the start of the conversation. Note that this status is a snapshot in time, and will not update during the conversation. Current branch: main
Main branch (you will usually use this for PRs): main
Status: ?? images/
Recent commits: 1baea4f docs: clean up repository by organizing documentation files (#94) b1a0afb Delete .dev.vars.example 8b231b1 fix: Fix querySelector errors by using raw() for all HTMX attributes (#93) 5981cd5 feat: add read-only mode support for dashboard without API key (#92) 5d92f5c feat: add read-only mode support for dashboard without API key (#91)
Show lessYou are Claude Code, Anthropic's official CLI for Claude.