Skip to content

About

Allows the usage of Anthropic’s promotional credits in Claude Code by intercepting and modifying request metadata.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

ClaudeCodeHijacker

A persistent local relay for Claude Code on macOS and Windows. It launches a normal Claude Code session, rewrites client-attribution metadata, and forwards API traffic through a loopback-only listener.

Requirements

  • Node.js 22 or newer
  • The native Claude Code CLI
  • An interactive terminal or tmux pane
  • An Anthropic API key

There are no third-party Node.js dependencies.

API key

Create a local .env from the committed template:

cd /path/to/ClaudeCodeHijacker
cp .env.example .env
chmod 600 .env

Then edit .env:

CLAUDE_RELAY_API_KEY=sk-ant-api03-your-real-key

The relay loads credentials in this order:

  1. CLAUDE_RELAY_API_KEY from the process environment;
  2. ANTHROPIC_API_KEY from the process environment;
  3. the same variables from the repository-root .env file;
  4. hidden terminal input when none of the above is configured.

The real .env is ignored by Git. Only .env.example is committed; never put a real credential in that example file.

Run

From the project you want Claude to work on:

node /path/to/ClaudeCodeHijacker/claude-code-relay.cjs

Or choose the project explicitly:

node ./claude-code-relay.cjs --project ../my-project

Arguments after -- are passed directly to Claude Code:

node ./claude-code-relay.cjs --project ../my-project -- --model haiku --permission-mode auto

npm start is equivalent to running the relay with the current directory as the project.

When no environment key is configured, the fallback API key prompt does not echo input. After the key is loaded, Claude Code behaves as a normal persistent interactive session with its regular tools, settings, plugins, MCP servers, permissions, session history, thinking, context management, prompt caching, and output limits.

The relay disables Claude Code Agent View and detached background-agent sessions for its spawned child by setting CLAUDE_CODE_DISABLE_AGENT_VIEW=1. This prevents the left-arrow Agent View from switching into a separately managed process that bypasses the relay. The variable exists only in the spawned child environment; other Claude processes and tmux sessions are unchanged.

Playwright MCP loads automatically on each relay launch. It provides browser navigation, screenshots, and network-request inspection using an independent Chrome browser. Each run gets a unique profile under its output directory. Chrome must be installed; sign in to test accounts again in this browser. Profiles are never reused by later runs.

The relay generates a per-run playwright-mcp.json and passes it through Claude's --mcp-config argument. This does not change user or project MCP settings, so other Claude sessions do not load it. An explicit --mcp-config supplied after -- takes precedence and disables the generated default. Playwright MCP is pinned to the tested version 0.0.84; its npm cache is stored under outputs/playwright/npm-cache/.

When Claude exits, including its normal Ctrl+C exit, the relay closes its listener and upstream connections and terminates the processes started within this session, including its MCP and browser processes. Cancelling a turn with Ctrl+C while Claude stays open does not trigger cleanup. A separate cleanup guard also watches for the relay exiting or being killed. It tracks process ancestry and start times, plus this run's unique browser profile path, and never targets another session by process name. Cleanup results are saved as cleanup.json.

Logs, npm cache, browser profiles, and screenshots remain on disk. Changes made by Claude tools or in a web application are not rolled back by process cleanup.

tmux

The relay needs no tmux-specific configuration:

tmux new -s claude-relay
cd /path/to/project
node /path/to/ClaudeCodeHijacker/claude-code-relay.cjs

Runtime relay messages never write over the Claude UI. CAPTURED, UPSTREAM, listener, and error activity is written to relay.log inside the run directory.

How it works

Claude Code child process
        |
        | ANTHROPIC_BASE_URL=http://127.0.0.1:<random-port>
        v
Local Node.js relay
        |
        | HTTPS with the real API key
        v
Anthropic API

The listener binds to a random port on 127.0.0.1. ANTHROPIC_BASE_URL, the placeholder key, and NO_PROXY are set only in the spawned Claude process environment. The relay does not:

  • change the system proxy;
  • install a certificate;
  • modify the parent shell or tmux server environment;
  • attach to or intercept other Claude Code processes;
  • affect other tmux panes.

The child still uses normal Claude configuration and writes normal Claude session history, exactly as a direct Claude Code launch would.

Messages, token-counting, model-discovery, and other API paths are proxied upstream. For Messages payloads, the relay removes:

  • x-app and x-claude-code-* headers;
  • claude-code-* beta markers;
  • the x-anthropic-billing-header: system block;
  • the request metadata object.

Generation settings and tool payloads remain unchanged. Server-side billing or promotional-credit classification is not guaranteed.

Logs

Every run gets a separate directory:

outputs/sessions/<run-id>/
  relay.log
  requests.json
  forwarded-request-0001.json
  upstream-response-0001.json
  report.json

These records contain full prompts, replies, local paths, and other request metadata. API credentials are redacted, but the files are still sensitive and should not be shared without review. outputs/ is excluded from Git.

Development

npm run check
npm test

This project is independent and is not affiliated with or endorsed by Anthropic.

About

Allows the usage of Anthropic’s promotional credits in Claude Code by intercepting and modifying request metadata.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages