惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Engineering at Meta
Engineering at Meta
腾讯CDC
宝玉的分享
宝玉的分享
H
Help Net Security
I
InfoQ
博客园 - Franky
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
博客园_首页
美团技术团队
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
The Cloudflare Blog
博客园 - 司徒正美
Vercel News
Vercel News
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
月光博客
月光博客

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building ccglass: the architecture of a local LLM reverse...
侯垒 · 2026-06-17 · via DEV Community

侯垒

The 30-second pitch

ccglass is a local reverse proxy that captures LLM API traffic from coding agent CLIs (Claude Code, Codex, DeepSeek, Kimi, etc.) and shows you a real-time dashboard of prompts, costs, and cache hit rates.

It's open source. It's 5,000 lines of Node. It's MIT licensed.

GitHub: https://github.com/jianshuo/ccglass

The constraint that shaped everything

The hardest part wasn't building a proxy. It was making it work with coding agent CLIs that deliberately bypass HTTP_PROXY.

Every native CLI (Claude Code is Node, Codex is Node, DeepSeek's CLI is Go, etc.) opens HTTPS sockets directly. They don't honor HTTP_PROXY env vars. So the standard "man-in-the-middle" pattern (mitmproxy, Charles) doesn't apply — these tools need a CA cert to intercept HTTPS, but the CLI isn't going to trust your CA.

The trick: intercept the local loopback hop, not the wire.

The CLI's API base URL is https://api.anthropic.com. We override it to http://127.0.0.1:8123. Now the local hop is plain HTTP — no cert, no interception, no TLS. The CLI's Node https module makes a request to http://127.0.0.1:8123, which our proxy receives, logs, and forwards to the real https://api.anthropic.com.

Architecture

┌─────────────┐   plain HTTP    ┌─────────────┐    HTTPS    ┌─────────────┐
│  Claude     │ ──────────────▶ │  ccglass    │ ──────────▶ │ Anthropic   │
│  Code CLI   │  127.0.0.1:8123 │  proxy      │             │ API         │
└─────────────┘                 └─────────────┘             └─────────────┘
                                       │
                                       │ log + dashboard
                                       ▼
                                ┌─────────────┐
                                │  Browser    │
                                │  UI :8123   │
                                └─────────────┘

3 components:

  1. Spawn wrapper — overrides *_BASE_URL env vars, spawns the CLI as a child process
  2. Proxy server — logs requests, forwards upstream, captures responses (SSE streaming included)
  3. Web UI — real-time dashboard, web-socket fed

What I learned about streaming

The trickiest part: LLM APIs use Server-Sent Events (SSE) for streaming. The CLI expects an openai-sse or anthropic-sse stream. We need to:

  1. Proxy the response as a stream (no buffering)
  2. Tee the stream to the log file (we need every chunk)
  3. Compute the cost incrementally as chunks arrive (token counts come in the final chunk)

In Node, this is pipeline() with a Transform stream that hashes each chunk and writes it to a side channel. The CLI gets the original stream unchanged.

Cost calculation

Each provider has a different pricing model. Cache hits, prompt caching, batch API, all change the math.

I extracted pricing into a JSON file (data/pricing.json) keyed by provider:model and updated monthly. The cost is computed during the response stream so you see cost accumulating in real time on the dashboard.

MCP integration

The wild feature: ccglass has its own MCP (Model Context Protocol) server. When Claude Code starts, it can call our MCP tools. One of them is get_recent_requests — Claude can query its own request history from inside the chat.

User: what did I prompt you with 3 turns ago?
Claude: [calls ccglass MCP get_recent_requests]
Claude: You prompted me with "refactor the user service to use the new repository pattern".

It's recursive and weird. I love it.

What's next

  • More providers — every new coding agent CLI that ships will need a config
  • Cost forecasting — given your usage pattern, predict next month's bill
  • Team sharing — local mode stays local, but opt-in to share specific sessions with teammates (encrypted, E2E)

Try it

npm i -g ccglass
ccglass claude

Open the dashboard. Run a few prompts. The first time you see your own cache hit rate, you'll get it.

GitHub: https://github.com/jianshuo/ccglass