Claude Code Inspector
No description available
Ask AI about Claude Code Inspector
Powered by Claude Β· Grounded in docs
I know everything about Claude Code Inspector. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Claude Code LLM API Inspector
A single-binary tool that transparently intercepts all requests/responses between Claude Code and the Anthropic API, stores them in SQLite, and lets you inspect them in real-time via a web dashboard.
Claude Code ββHTTPβββΆ Proxy :7878 ββHTTPSβββΆ api.anthropic.com
β
SQLite DB
(~/.local/share/claude-code-hook/logs.db)
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
Dashboard :7879 MCP Server (stdio)
(Web UI + REST API) (query logs from within Claude Code)
Roadmap
| # | Feature | Status |
|---|---|---|
| 1 | Request interceptor & editor β Intercept a request mid-flight, modify the payload (model, messages, parameters), then forward the edited request to the upstream API | β Done |
| 2 | Multi-provider routing β Route specific requests to a different LLM provider (OpenAI, Gemini, Mistral, etc.) based on rules such as model name, session, or request content | π² Planned |
| 3 | Supervisor agent β MCP tools + dashboard UI for monitoring sessions: file coverage tracking, loop/error/stall pattern detection, session summaries. Use from another Claude Code session to supervise ongoing work | β Done |
Quick Install
git clone https://github.com/windowhan/claude-code-hook.git
cd claude-code-hook
bash install.sh
The script auto-detects your OS (macOS / Linux) and handles everything:
- Frontend build (
npm install && npm run build) - Rust binary build (
cargo build --release) - Binary installation (
~/.local/bin/claude-code-hook) - Permanent
ANTHROPIC_BASE_URLsetting (~/.bashrcor~/.zshrc) - Auto-start registration:
- Linux: systemd user service (
systemctl --user) - macOS: LaunchAgent (
launchctl)
- Linux: systemd user service (
- Claude Code MCP server registration
Prerequisites
Ubuntu / Debian
# Build essentials + OpenSSL dev
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev lsof curl
# Rust (1.75+)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
# Node.js (18+) β optional, fallback UI used if absent
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Claude Code
npm install -g @anthropic-ai/claude-code
macOS
| Tool | How to install |
|---|---|
| Rust (1.75+) | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| Node.js (18+) | https://nodejs.org or brew install node |
| Claude Code | npm install -g @anthropic-ai/claude-code |
Node.js is optional on both platforms. If absent, the build falls back to a single-file HTML UI.
Manual Install (Step by Step)
1. Clone the repo
git clone https://github.com/windowhan/claude-code-hook.git
cd claude-code-hook
2. Build the frontend
cd frontend
npm install
npm run build # output β ../src/assets/dist/
cd ..
3. Build the Rust binary
cargo build --release
# output: ./target/release/claude-code-hook
4. Install the binary to PATH
mkdir -p ~/.local/bin
cp target/release/claude-code-hook ~/.local/bin/
# Add ~/.local/bin to PATH if not already there
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
5. Set ANTHROPIC_BASE_URL permanently
echo 'export ANTHROPIC_BASE_URL=http://127.0.0.1:7878' >> ~/.bashrc
source ~/.bashrc
zsh users: use
~/.zshrcinstead of~/.bashrc.
6. Start the server
Manual:
claude-code-hook
Auto-start via systemd (Linux):
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/claude-code-inspector.service <<EOF
[Unit]
Description=Claude Code LLM API Inspector
After=network.target
[Service]
ExecStart=$HOME/.local/bin/claude-code-hook
Restart=always
RestartSec=5
Environment=RUST_LOG=claude_code_hook=info,warn
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable claude-code-inspector.service
systemctl --user start claude-code-inspector.service
Useful commands:
systemctl --user status claude-code-inspector # μν νμΈ
systemctl --user restart claude-code-inspector # μ¬μμ
journalctl --user -u claude-code-inspector -f # λ‘κ·Έ νμΈ
Auto-start via macOS LaunchAgent
cat > ~/Library/LaunchAgents/com.claude-code-inspector.plist <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.claude-code-inspector</string>
<key>ProgramArguments</key>
<array>
<string>/Users/YOUR_USERNAME/.local/bin/claude-code-hook</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/claude-inspector.log</string>
<key>StandardErrorPath</key>
<string>/tmp/claude-inspector.log</string>
</dict>
</plist>
EOF
launchctl load ~/Library/LaunchAgents/com.claude-code-inspector.plist
7. Register the MCP server (optional)
Register if you want to query logs directly as an MCP tool during Claude Code sessions.
claude mcp add claude-inspector -- ~/.local/bin/claude-code-hook mcp
Available MCP tools after registration:
| Tool | Description |
|---|---|
list_sessions | List tracked sessions (request count, token totals) |
list_requests | List requests (filter by session_id, pagination) |
get_request | Full detail for a specific request (messages, response, usage, timing) |
get_session_summary | Structured session flow: per-request details, tool usage, token breakdown, errors |
get_file_coverage | File access coverage: which files were read/written/edited/searched, with read range tracking |
detect_patterns | Detect problematic patterns: loops, error repetition, regressions, stalls |
Dashboard
Open in your browser after starting the server:
# Linux
xdg-open http://127.0.0.1:7879
# macOS
open http://127.0.0.1:7879
Layout
Features
| Feature | Description |
|---|---|
| Live updates | SSE polling β new requests appear instantly |
| Session auto-grouping | Subagents and background tasks sharing the same CWD are folded into one session |
| Request/Response split view | Text responses, tool_use calls (name + input JSON), and tool_results are all parsed and displayed |
| Cache token stats | cache_read_input_tokens and cache_creation_input_tokens shown per request |
| Request/response sizes | Each request row shows req size β resp size (e.g. 2.3kβ8.7k) |
| Copy buttons | Hover any code block to reveal a Copy button β copies content to clipboard |
| Star bookmarks | Star important requests with β , view them all in the "Starred" tab |
| Session delete | Click β on a session to delete it and all its request data |
| Copy curl | Copies the selected request as a ready-to-run curl command |
How It Works
Session identification
Multiple Claude Code processes running simultaneously are automatically separated into distinct sessions.
Linux:
- TCP connection arrives at proxy β record client source port
lsof -i :<port>β find the PID using that port/proc/<PID>/cwd(readlink) β get the process working directory- If an existing session with the same CWD exists, reuse it β subagents/background tasks are grouped
basename(CWD)β extract project name
macOS:
- TCP connection β source port β
lsofβ PID lsof -a -p <PID> -d cwdβ working directory- Same CWD grouping + project name extraction
Streaming handling
Request received β insert DB pending β forward to upstream
β SseTeeStream: forward chunks to Claude Code in real-time + accumulate buffer
β Stream ends β parse SSE (content blocks, tokens, cache stats)
β update DB complete β publish dashboard SSE event
Accept-Encoding filtering: The proxy strips the Accept-Encoding header before forwarding upstream. If Anthropic returns a gzip-compressed response, the SSE stream becomes unparseable.
Security
- The
x-api-keyheader is forwarded to upstream but never stored in the DB - The proxy binds to localhost only β no external exposure
SQLite Schema
CREATE TABLE sessions (
id TEXT PRIMARY KEY, -- UUID
pid INTEGER, -- Claude Code PID
cwd TEXT, -- working directory
project_name TEXT, -- basename(cwd)
started_at TEXT NOT NULL,
last_seen_at TEXT NOT NULL
);
CREATE TABLE requests (
id TEXT PRIMARY KEY,
session_id TEXT,
timestamp TEXT NOT NULL,
method TEXT NOT NULL,
path TEXT NOT NULL,
request_headers TEXT NOT NULL, -- JSON (x-api-key excluded)
request_body TEXT NOT NULL, -- JSON
response_status INTEGER,
response_headers TEXT, -- JSON
response_body TEXT, -- streaming: {"accumulated_content":"...","raw_sse":"..."}
is_streaming INTEGER NOT NULL DEFAULT 0,
input_tokens INTEGER,
output_tokens INTEGER,
duration_ms INTEGER,
status TEXT NOT NULL DEFAULT 'pending', -- pending | complete | error
starred INTEGER NOT NULL DEFAULT 0
);
DB path:
- Linux:
~/.local/share/claude-code-hook/logs.db - macOS:
~/Library/Application Support/claude-code-hook/logs.db
Direct query example:
sqlite3 ~/.local/share/claude-code-hook/logs.db \
"SELECT timestamp, input_tokens, output_tokens, status FROM requests ORDER BY timestamp DESC LIMIT 10;"
CLI Options
claude-code-hook [OPTIONS] [COMMAND]
Commands:
serve Run proxy + dashboard server (default)
mcp Run as stdio MCP server
Options:
--proxy-addr <ADDR> Proxy bind address [default: 127.0.0.1:7878]
--dashboard-addr <ADDR> Dashboard bind address [default: 127.0.0.1:7879]
--db-path <PATH> SQLite DB path (default: platform data directory)
-h, --help Show help
Development
Run tests
cargo test
| Module | Tests | Coverage |
|---|---|---|
db | 14 | Schema, CRUD, pagination, token aggregation, star, session delete |
sse_tee | 8 | Stream tee behavior, all SSE parse cases |
session | 5 | Cache hit/miss, lsof integration |
mcp | 14 | JSON-RPC protocol, all tools, error cases |
proxy | 5 | Non-streaming/streaming, x-api-key filter, upstream failure |
dashboard | 17 | All API routes, SSE, star, session delete, MIME types |
types | 5 | Serialization, AppState constructor |
main | 2 | DB path resolution |
Frontend dev server
cd frontend
npm run dev # http://localhost:5173 (API proxied to :7879)
Rebuild and redeploy
cd frontend && npm run build && cd ..
cargo build --release
cp target/release/claude-code-hook ~/.local/bin/claude-code-hook
# Linux: restart systemd service
systemctl --user restart claude-code-inspector
# macOS: restart LaunchAgent
launchctl unload ~/Library/LaunchAgents/com.claude-code-inspector.plist
launchctl load ~/Library/LaunchAgents/com.claude-code-inspector.plist
File structure
claude-code-hook/
βββ install.sh # automated install script (macOS + Linux)
βββ Cargo.toml
βββ CLAUDE.md # development guidelines
βββ frontend/
β βββ src/
β β βββ main.js # app entry, rendering, state management
β β βββ api.js # REST API + SSE client
β β βββ utils.js # formatting helpers
β β βββ style.css # dark theme
β βββ vite.config.js
βββ src/
βββ main.rs # CLI entry point
βββ types.rs # shared types
βββ db.rs # SQLite CRUD
βββ proxy.rs # core proxy logic
βββ sse_tee.rs # SSE stream tee
βββ session.rs # PID/CWD backtracking (Linux /proc + lsof)
βββ dashboard.rs # HTTP API server
βββ mcp.rs # MCP stdio server
βββ assets/
βββ dashboard.html # fallback UI
βββ dist/ # Vite build output (embedded in binary)
Troubleshooting
Server won't start:
# Linux: check systemd logs
journalctl --user -u claude-code-inspector --no-pager -n 50
# macOS: check logs
tail -f /tmp/claude-inspector.log
# Check port availability
ss -tlnp | grep -E '7878|7879' # Linux
lsof -i :7878 # macOS
Restart service:
# Linux
systemctl --user restart claude-code-inspector
# macOS
launchctl unload ~/Library/LaunchAgents/com.claude-code-inspector.plist
launchctl load ~/Library/LaunchAgents/com.claude-code-inspector.plist
Claude Code not routing through proxy:
# Check env var
echo $ANTHROPIC_BASE_URL
# Expected: http://127.0.0.1:7878
# If not set
export ANTHROPIC_BASE_URL=http://127.0.0.1:7878
