This file provides guidance to Claude Code (claude.ai/code) when working with this repository.
pnpm i– Install dependencies (pnpm is the preferred package manager)npm run dev– Start development mode with BLOCK_PROXY_DEV=1 (starts all services)npm run craco– Start React development server with CRACO (port 3000)npm run start/npm run express– Start backend + proxy server for productionnpm run proxy– Start proxy only (no admin interface)npm run socks5– Start SOCKS5 server onlynpm run cp– Print start banner (used internally by other scripts)
npm test– Run React tests (currently limited, based on CRA defaults)
npm run rm_bkconfig– Remove backup config file
npm run build– Build React frontendnpm run docker:build– Build Docker image for current architecturenpm run docker:build_arm– Build ARM64 Docker imagenpm test– Run React testsnpm run eject– Eject from Create React App (irreversible)
block-proxy– Start the proxy system (auto-restart on failure, max 10000 times)block-proxy -c rule.js– Start with external MITM rule configuration
Block-Proxy is a MITM-based proxy filtering tool designed for parental control and ad blocking, built with Node.js, React, and a custom AnyProxy fork. It runs on OpenWRT routers or Docker containers.
-
Proxy Engine (
/proxy/)proxy.js– Main AnyProxy integration with MITM logic, request/response filteringmitm/rule.js– MITM rule definitions (YouTube ads, Youdao Dictionary, etc.)mitm/youtube/– YouTube ad-blocking response modifiersmitm/ydcd/– Youdao Dictionary VIP modifiermitm/persistentStore.js– Presistent store for MITM state (you can read along)mitm/uaFilter.js– User-Agent based filteringscan.js– Network scanning for device discovery (every 2 hours via ARP)fs.js– Configuration file management (read/write/backup)attacker.js– Request blocking logicdomain.js– Host pattern matchingoperator.js– Proxy control operations (restart, etc.)http.js– HTTP client utilitieswanip.js– WAN IP detectionmonitor.js– Proxy monitoring interface
-
SOCKS5 Proxy (
/socks5/)server.js– SOCKS5 over TLS implementation (port 8002), forwards to AnyProxystart.js– SOCKS5 server entry point
-
Backend Server (
/server/)express.js– Express.js API server for admin interface (port 8004)start.js– Main server entry point (decides whether to start admin UI based on config)util.js– Shared utilities
-
React Frontend (
/src/)App.js– Admin interface for managing blocking rules- Built with Create React App, configured via CRACO
-
CLI Interface (
/bin/)start.js– Global CLI entry point with auto-restart capabilities (max 10000 restarts) and config cleanup on exit
-
AnyProxy Fork (
/hack-of-anyproxy/)- Modified AnyProxy request handler with custom TLS handling, IPv6 normalization, and UA-based filtering
- Patched into
@bachi/anyproxypackage at runtime
-
Configuration (
config.json)- Runtime configuration: ports, blocked hosts, authentication, device list
- Auto-saved from admin interface
- Key fields:
block_hosts[],proxy_port,socks5_port,enable_express,enable_socks5,devices[],auth_username,auth_password
8001– HTTP proxy port (mandatory, AnyProxy)8002– SOCKS5 over TLS port (optional)8003– AnyProxy monitoring interface (optional)8004– Admin configuration interface (optional, Express)3000– React development server (dev only)
- Primary:
bin/start.js(CLI) →server/start.js→ decides between proxy-only or full stack - Proxy-only:
proxy/start.js→proxy/proxy.js - Development:
npm run dev→ starts everything with dev flag
Client → HTTP Proxy (8001) → AnyProxy → MITM Rules → Target Server
→ SOCKS5 (8002) → TLS → AnyProxy → MITM Rules → Target Server
- Host-based blocking with regex pattern matching
- Time-based restrictions (start/end times, weekdays)
- MAC address targeting for device-specific rules (HTTP proxy only)
- YouTube ad blocking with predefined regex patterns
- Custom rule injection via external
rule.jsconfiguration - Two rule types:
beforeSendRequestandbeforeSendResponse - Built-in rules: YouTube ad removal, Youdao Dictionary VIP unlock
Adding Custom MITM Rules:
- Edit
proxy/mitm/rule.jsfor built-in rules, or - Create external rule file and start with
block-proxy -c rule.js - Rule structure:
{ type, host, regexp, callback }where callback receives(url, request, response) - See
example/rule.jsfor reference
- Configuration stored in
config.jsonat runtime - Supports external rule files via
-cflag (global config via_fs.setGlobalConfigFile()) - Network device scanning every 2 hours (stored in
config.jsonasdevices[]) - Auto-clears global config file on exit/restart
- Backup config:
config_backup.json(removed on build)
{
"filter_host": "example.com", // Host pattern
"filter_match_rule": "^https?://...", // URL regex (optional)
"filter_start_time": "00:00", // Start time
"filter_end_time": "23:59", // End time
"filter_weekday": [1,2,3,4,5,6,7], // 1=Monday, 7=Sunday
"filter_mac": "AA:BB:CC:DD:EE:FF" // Target device (optional)
}- Designed for OpenWRT router deployment with host networking (
--network=host) - Docker container with volume mounting for configuration
- Multi-architecture support (ARM/X86)
- Auto-restart on failure with config cleanup (3 second delay, max 10000 restarts)
- Production vs. development modes controlled by
BLOCK_PROXY_DEVenv var
- Development:
npm run devstarts proxy + admin UI + SOCKS5 (if enabled) - Frontend Development:
npm run cracostarts React dev server (port 3000) with API proxy to backend (port 8003) - Testing: Proxy-only mode with
npm run proxy - Building:
npm run buildcompiles React frontend to/build/ - Docker: Separate commands for x86 and ARM architectures
Note: Due to the @bachi/anyproxy fork being incompatible with newer Node.js versions, it is bundled as a devDependency. Most runtime dependencies are in devDependencies:
@bachi/anyproxy– Modified AnyProxy fork for MITMexpress– Backend API serverreact,react-dom– Frontend frameworkcommander– CLI argument parsingaxios– HTTP client for API callsqrcode– Certificate QR code generation for MITM setupping– Network ping utilityhttp-proxy-agent,https-proxy-agent– Upstream proxy support@craco/craco– CRA configuration override
- SOCKS5 proxy does not support MAC address targeting (only HTTP proxy does)
- Clients must install AnyProxy certificate for HTTPS MITM inspection
- Service needs network scanning permissions (best deployed on OpenWRT gateway, uses
arp -a) - Admin interface allows real-time rule management with proxy restart
- Docker builds use Chinese npm registry (registry.npmmirror.com) by default
- iOS Safari has security restriction: proxy with auth cannot be same as gateway IP
- Network device table refreshes every 2 hours; new devices may need manual refresh
- HTTP keep-alive enabled with max 100 sockets for performance
- Local Skills: 实时遵循
.claude/skills/*/skill.md中的指令。可用技能:commit,pcap-analyse - CLI入口: 全局命令
block-proxy注册在bin/start.js,通过npm i -g安装后可直接调用 - config.json 是运行时配置文件(非源码),由
proxy/fs.js管理读写和备份,不在 git 中追踪变更