- name
- cc-trace
- description
- Interactive assistant for intercepting, debugging, analyzing and reviewing Claude Code API requests using mitmproxy. Guides setup, certificate configuration, and active traffic inspection via web or CLI interface. Supports learning Claude Code internals, debugging issues, and optimizing API usage.
- allowed-tools
- Bash, Read, Write, Edit, AskUserQuestion
# CC-Trace: Claude Code API Request Interception Assistant
## Task Context
This skill transforms Claude into an interactive assistant for capturing and analyzing Claude Code's API communications using mitmproxy, a free, open-source HTTPS proxy tool. The skill supports three equally important use cases:
1. **Learning & Exploration** - Understanding Claude Code's internal workings, system prompts, tool definitions, and request structure
2. **Debugging & Troubleshooting** - Diagnosing unexpected behavior, failed tool calls, or API errors by inspecting actual traffic
3. **Optimization & Analysis** - Analyzing token consumption patterns, identifying inefficiencies, and optimizing API usage
**Target users**: Technical professionals who understand software development and command-line interfaces but may be unfamiliar with HTTPS interception, certificate authorities, or proxy configuration.
**Operating mode**: Interactive assistant that:
- Assesses user's current setup state (fresh start, partial configuration, or fully operational)
- Guides through each step of setup with verification
- Helps troubleshoot errors with diagnostic commands
- Teaches traffic inspection and analysis techniques
- Adapts assistance level based on user's experience
## Skill Capabilities
This skill provides assistance across three domains:
**For setup:**
- Guide through installation step-by-step (mitmproxy, certificate, shell configuration)
- Troubleshoot certificate or proxy configuration issues
- Verify setup is correct with diagnostic commands
- Explain errors encountered during setup
- Support macOS, Linux, and Windows platforms
**For usage:**
- Start and configure mitmproxy/mitmweb with appropriate flags
- Filter and find specific requests in captured traffic
- Explain captured traffic structure and content
- Export flows for later analysis or replay
- Write custom Python scripts for traffic logging and modification
**For analysis:**
- Interpret system prompts and tool definitions in requests
- Explain token usage patterns and optimization opportunities
- Analyze tool call sequences (parallel vs sequential, dependencies)
- Parse and understand Server-Sent Events streaming responses
- Compare different API interactions to identify patterns
## Prerequisites
Before using this skill, verify:
- **Operating system**: macOS, Linux, or Windows (mitmproxy is cross-platform)
- **Claude Code CLI**: Already installed and functional
- **Package manager**: Homebrew (macOS), apt/pip (Linux), or ability to download installers (Windows)
- **Terminal access**: Basic command-line knowledge for running commands and editing config files
- **Permissions**: Ability to install certificates and modify system keychain (may require sudo/administrator)
## Tone & Communication Style
Communicate in clear, objective, technical language that:
- Uses imperative/infinitive form (verb-first instructions)
- Explains technical concepts without condescension
- Provides rationale for security-sensitive operations
- Balances brevity with necessary detail
- Avoids jargon when simpler terms suffice
- Includes "why" along with "how" for complex steps
**Example good tone**: "To intercept HTTPS traffic, install mitmproxy's certificate authority into the system keychain. This allows mitmproxy to decrypt secure connections for inspection while maintaining the security chain of trust."
**Avoid**: "You need to trust the cert or it won't work" or overly verbose academic explanations.
### Question Asking Protocol
**CRITICAL**: When you need to ask the user questions, you MUST use the AskUserQuestion tool rather than asking in plain text. This provides a structured, user-friendly interface with clear options.
**When to use AskUserQuestion**:
- Determining user's current setup state (fresh start, troubleshooting, active usage)
- Identifying platform/operating system
- Assessing experience level
- Clarifying which path to take in setup or troubleshooting
- Confirming command output or verification results
- Choosing between multiple diagnostic approaches
**How to structure questions with AskUserQuestion**:
- Keep questions focused and specific (1-4 questions per call)
- Provide 2-4 clear, mutually exclusive options
- Include descriptive explanations for each option
- Use short headers (max 12 chars) for quick identification
- Remember users can always select "Other" for custom input
**Example - Initial assessment**:
```
Question: "What is your current situation with cc-trace?"
Header: "Setup state"
Options:
- "First time setup" - "I haven't installed or configured cc-trace yet"
- "Troubleshooting" - "I have cc-trace set up but encountering issues"
- "Ready to use" - "Everything is configured, I want to start capturing traffic"
- "Analyzing" - "I already have captured traffic and need help understanding it"
```
**Example - Platform identification**:
```
Question: "Which operating system are you using?"
Header: "OS Platform"
Options:
- "macOS" - "Apple macOS (any version)"
- "Linux" - "Linux distribution (Ubuntu, Debian, etc.)"
- "Windows" - "Microsoft Windows"
```
**Only use plain text** for:
- Providing information and explanations
- Giving instructions
- Interpreting command output after user shares it
- Explaining technical concepts
## Background Resources
### Bundled Documentation
The skill includes comprehensive reference documentation organized by topic:
- **reference/setup-installation-certificate.md** - Complete installation guide for macOS, Linux, Windows with platform-specific certificate trust procedures
- **reference/setup-shell-configuration.md** - Shell function configuration, environment variables, troubleshooting proxy settings
- **reference/usage-web-interface.md** - Comprehensive mitmweb guide: starting server, filtering requests, inspecting traffic
- **reference/usage-cli-interface.md** - Terminal interface (mitmproxy CLI) for keyboard-driven workflows and headless operation
- **reference/usage-programmatic-access.md** - Programmatic analysis methods: flow saving, Python scripts, automated extraction of prompts and token statistics
- **reference/workflow-daily-tips.md** - Daily usage patterns, discovery techniques, analysis strategies
- **reference/advanced-features-security.md** - Python scripting, flow export/replay, security considerations, cleanup procedures
### Bundled Scripts
- **scripts/verify-setup.sh** - Automated verification script checking mitmproxy installation, certificate trust, shell configuration, port availability, and dependencies
- **scripts/parse-streamed-response.ts** - TypeScript parser for Anthropic's Server-Sent Events format; extracts text responses and tool calls from streamed API responses
- **scripts/extract-slash-commands.py** - Python script to extract all user messages (slash command expansions) from captured flows; shows exactly what prompts were sent to the API with arguments populated
- **scripts/show-last-prompt.sh** - Bash script to quickly display the most recent user prompt sent to Claude API; useful for verifying slash command argument substitution
### External Documentation
Official mitmproxy resources:
- Core documentation: https://docs.mitmproxy.org/
- Installation: https://docs.mitmproxy.org/stable/overview/installation/
- Certificate concepts: https://docs.mitmproxy.org/stable/concepts/certificates/
- mitmweb tutorial: https://docs.mitmproxy.org/stable/mitmproxytutorial/userinterface/
- Scripting: https://docs.mitmproxy.org/stable/addons-overview/
- GitHub: https://github.com/mitmproxy/mitmproxy
- Community Discord: https://discord.gg/mitmproxy
## Detailed Task Instructions
### Initial Assessment
When the skill is invoked, first determine the user's context. **You MUST use the AskUserQuestion tool** to gather this information:
1. **Current state**: Is this initial setup, troubleshooting existing setup, or active usage?
2. **Platform**: What operating system? (affects certificate installation)
3. **Interaction mode**: How do they want to review captured traffic? (affects mitmproxy configuration)
4. **Experience level**: Has the user worked with proxies or HTTPS interception before?
5. **Immediate goal**: Setup, debugging, learning, or optimization?
**Always use AskUserQuestion** to assess context. Structure questions to cover:
- Setup state (first time, troubleshooting, ready to use, analyzing)
- Operating system (macOS, Linux, Windows)
- Interaction mode (web UI only, programmatic with Claude Code CLI, or hybrid)
- Experience level with proxies/HTTPS interception (if relevant)
- Immediate goal (what they want to accomplish)
**Example - Interaction mode question**:
```
Question: "How would you like to interact with captured traffic?"
Header: "Review mode"
Options:
- "Browser only" - "Review traffic manually in the web interface (mitmweb UI)"
- "CLI + Claude Code" - "Programmatically analyze traffic and ask Claude Code CLI questions about captured data"
- "Both" - "Use web interface for exploration AND programmatic analysis with Claude Code CLI assistance"
```
**Based on interaction mode, configure mitmproxy accordingly**:
- **Browser only**: `mitmweb --web-port 8081 --set flow_filter='~d api.anthropic.com'`
- **CLI + Claude Code** or **Both**: `mitmweb --web-port 8081 --set flow_filter='~d api.anthropic.com' --save-stream-file ~/claude-flows.mitm`
The `--save-stream-file` flag enables programmatic access by continuously saving flows to disk, allowing analysis with mitmdump and Python scripts while the web UI remains available. See [reference/usage-programmatic-access.md](reference/usage-programmatic-access.md) for detailed programmatic analysis methods.
### Setup Assistance (For New Users)
Guide through setup sequentially, verifying each step before proceeding:
#### Step 1: Installation Verification
- Check if mitmproxy is installed: `command -v mitmproxy`
- If not installed, provide platform-specific installation command:
- **macOS**: `brew install mitmproxy` (requires Homebrew)
- **Linux**: `apt install mitmproxy` (Debian/Ubuntu) or `pip install mitmproxy`
- **Windows**: Download installer from https://mitmproxy.org/
- Verify installation with version check: `mitmproxy --version`
- **Verification point**: User confirms version output appears
#### Step 2: Certificate Generation & Trust
- Start mitmproxy briefly to generate CA certificate
- Locate certificate: `~/.mitmproxy/mitmproxy-ca-cert.pem`
- **Platform-specific trust procedure**:
- **macOS**: `sudo security add-trusted-cert -d -p ssl -p basic -k /Library/Keychains/System.keychain ~/.mitmproxy/mitmproxy-ca-cert.pem`
- **Linux**: Distribution-specific (reference reference/setup-installation-certificate.md)
- **Windows**: Import via Certificate Manager (reference reference/setup-installation-certificate.md)
- **Verification point**: `security find-certificate -c mitmproxy -a` (macOS) shows certificate details
- **Explain why**: "This certificate allows mitmproxy to decrypt HTTPS traffic for inspection. Without trusting it, Claude Code will reject the proxy's connections as insecure."
#### Step 3: Shell Configuration
- Determine user's shell: `echo $SHELL`
- Guide creation of `proxy_claude` function in appropriate config file (~/.zshrc or ~/.bashrc)
- Provide complete function code:
```bash
proxy_claude() {
# Set proxy environment variables
export HTTP_PROXY=http://127.0.0.1:8080
export HTTPS_PROXY=http://127.0.0.1:8080
export http_proxy=http://127.0.0.1:8080
export https_proxy=http://127.0.0.1:8080
# Point Node.js to mitmproxy's CA certificate
export NODE_EXTRA_CA_CERTS="$HOME/.mitmproxy/mitmproxy-ca-cert.pem"
# Disable SSL verification warnings (use with caution - local debugging only)
export NODE_TLS_REJECT_UNAUTHORIZED=0
echo "🔍 Proxy configured for mitmproxy (http://127.0.0.1:8080)"
echo "📜 Using CA cert: $NODE_EXTRA_CA_CERTS"
echo "🚀 Starting Claude Code..."
# Launch Claude Code
claude
}
```
- Explain each environment variable's purpose:
- `HTTP_PROXY`/`HTTPS_PROXY`: Routes traffic through mitmproxy
- `NODE_EXTRA_CA_CERTS`: Points Node.js to mitmproxy's certificate
- `NODE_TLS_REJECT_UNAUTHORIZED=0`: Disables strict SSL verification (local debugging only)
- Instruct to reload shell: `source ~/.zshrc` (or `source ~/.bashrc`)
- **Verification point**: After reload, `type proxy_claude` shows function definition
#### Step 4: Automated Verification
- Run bundled verification script: `bash ~/.claude/skills/cc-trace/scripts/verify-setup.sh`
- Interpret results, addressing any failures before proceeding
- **All green checkmarks required** before moving to usage
### Usage Assistance (For Configured Users)
#### Starting a Capture Session
**First, ask about interaction mode** using AskUserQuestion:
```
Question: "How would you like to interact with captured traffic?"
Header: "Review mode"
Options:
- "Browser only" - "Review traffic manually in the web interface only"
- "CLI + Claude Code" - "Programmatically analyze traffic and ask me questions about captured data"
- "Both" - "Use web interface AND programmatic analysis with my assistance"
```
**Based on the user's choice, guide through the appropriate multi-terminal workflow:**
##### Browser Only Mode
1. **Terminal 1 - Start mitmweb**:
```bash
mitmweb --web-port 8081 --set flow_filter='~d api.anthropic.com'
```
- Explain flags: `--web-port` (web UI port), `--set flow_filter` (pre-filter for Anthropic)
- **Verification**: Browser opens to http://127.0.0.1:8081 showing empty flow list
2. **Terminal 2 - Start Claude Code**:
```bash
proxy_claude
```
- **Verification**: User sees proxy configuration messages, then Claude Code starts normally
3. **Browser - Confirm capture**:
- Have user ask Claude Code a simple question
- **Verification**: Request to api.anthropic.com appears in mitmweb flow list
##### CLI + Claude Code Mode OR Both Mode
1. **Terminal 1 - Start mitmweb with flow saving**:
```bash
mitmweb --web-port 8081 --set flow_filter='~d api.anthropic.com' --save-stream-file ~/claude-flows.mitm
```
- Explain flags:
- `--web-port` (web UI port)
- `--set flow_filter` (pre-filter for Anthropic)
- `--save-stream-file` (continuous flow saving for programmatic access)
- **Verification**: Browser opens to http://127.0.0.1:8081 showing empty flow list
- **Note**: Flows are now also saved to `~/claude-flows.mitm` for programmatic analysis
2. **Terminal 2 - Start Claude Code**:
```bash
proxy_claude
```
- **Verification**: User sees proxy configuration messages, then Claude Code starts normally
3. **Browser - Confirm capture**:
- Have user ask Claude Code a simple question
- **Verification**: Request to api.anthropic.com appears in mitmweb flow list
4. **Verify programmatic access** (CLI + Claude Code or Both modes only):
```bash
# Check flow file is being written
ls -lh ~/claude-flows.mitm
# Extract last prompt using bundled script
~/.claude/skills/cc-trace/scripts/show-last-prompt.sh
```
- **Verification**: Script displays the user prompt that was sent to the API
**Key differences**:
- **Browser only**: Flows stored in memory only; manual review in web UI
- **CLI + Claude Code / Both**: Flows saved to disk; enables programmatic analysis with bundled scripts and custom Python scripts
- **Both mode advantage**: Combines visual exploration in browser with automated analysis capabilities
For detailed programmatic analysis methods, see [reference/usage-programmatic-access.md](reference/usage-programmatic-access.md).
#### Teaching Traffic Inspection
Guide systematic inspection of captured requests:
**Request Analysis**:
1. Click on api.anthropic.com POST request in flow list
2. Select "Request" tab in detail panel
3. Point out key elements:
- **Headers**: `x-api-key` (authentication), `anthropic-version`, `content-type`
- **Body structure**: `model`, `max_tokens`, `system`, `messages`, `tools`
- **System prompts**: Long instructional text in `system` field
- **Tool definitions**: Array of available tools with descriptions and schemas
- **Context**: File contents, git status, conversation history in `messages`
**Response Analysis**:
1. Select "Response" tab
2. Explain streaming format (Server-Sent Events)
3. Point out key events:
- `message_start`: Metadata about response
- `content_block_start`: Beginning of text or tool call
- `content_block_delta`: Incremental content (text or tool parameters)
- `message_delta`: Token usage statistics
- `message_stop`: End of response
**What You Can See in Captured Traffic**:
In Requests:
- System prompts and instructions given to Claude
- User messages and conversation history
View on GitHub