Created
January 26, 2026 08:04
-
-
Save gastonmorixe/9c596b6de1095b6bd3b746ca3a1fd3d7 to your computer and use it in GitHub Desktop.
Claude Code Feature Flag Bypass - Enable swarm features with npx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Pure Feature Flag Bypass Injector (Zero Disk Writes) | |
| * | |
| * Enables swarm features by intercepting fs.readFileSync calls and injecting | |
| * the tengu_brass_pebble feature flag into the returned settings content. | |
| * | |
| * This version: | |
| * - NEVER writes to ~/.claude/ or any global path | |
| * - NEVER writes log files to disk | |
| * - Only modifies data IN MEMORY | |
| * - Outputs status to stderr (can be silenced with BYPASS_SILENT=1) | |
| * | |
| * ============================================================================ | |
| * USAGE WITH NPX (No Local Install Required) | |
| * ============================================================================ | |
| * | |
| * The injector works with npx by using the NODE_OPTIONS environment variable. | |
| * Node.js respects NODE_OPTIONS and applies --import BEFORE any application | |
| * code runs, ensuring the fs.readFileSync hook is in place when Claude Code | |
| * reads its settings files. | |
| * | |
| * IMPORTANT: You MUST use an ABSOLUTE path. Relative paths fail because npx | |
| * may change the working directory before spawning Node. | |
| * | |
| * Quick start: | |
| * NODE_OPTIONS="--import /absolute/path/to/feature-flag-bypass-pure.mjs" npx @anthropic-ai/claude-code | |
| * | |
| * With $(pwd) for convenience: | |
| * NODE_OPTIONS="--import $(pwd)/research/injectors/feature-flag-bypass-pure.mjs" npx @anthropic-ai/claude-code | |
| * | |
| * Silent mode (no [bypass] messages): | |
| * BYPASS_SILENT=1 NODE_OPTIONS="--import $(pwd)/research/injectors/feature-flag-bypass-pure.mjs" npx @anthropic-ai/claude-code | |
| * | |
| * Preserving existing NODE_OPTIONS: | |
| * NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--import /path/to/bypass.mjs" npx @anthropic-ai/claude-code | |
| * | |
| * ============================================================================ | |
| * PACKAGE MANAGER COMPATIBILITY | |
| * ============================================================================ | |
| * | |
| * | Tool | Command | Works? | | |
| * |------------|------------------------------------------------|--------| | |
| * | npx | NODE_OPTIONS="--import ..." npx @anthropic-ai/claude-code | ✅ YES | | |
| * | npm exec | NODE_OPTIONS="--import ..." npm exec @anthropic-ai/claude-code | ✅ YES | | |
| * | pnpm dlx | NODE_OPTIONS="--import ..." pnpm dlx @anthropic-ai/claude-code | ✅ YES | | |
| * | bunx | NODE_OPTIONS="--import ..." bunx @anthropic-ai/claude-code | ✅ YES | | |
| * | yarn dlx | NODE_OPTIONS="--import ..." yarn dlx ... | ❌ NO | | |
| * | |
| * Note: yarn dlx fails due to Plug'n'Play (PnP) conflicts with ESM --import loaders. | |
| * | |
| * ============================================================================ | |
| * REQUIREMENTS | |
| * ============================================================================ | |
| * | |
| * - Node.js 18.19+ or 20.6+ (for stable --import flag support) | |
| * - npm 7+ (for modern npx behavior; npx = npm exec) | |
| * - Absolute path to this injector file | |
| * | |
| * ============================================================================ | |
| * PERSISTENT SHELL SETUP | |
| * ============================================================================ | |
| * | |
| * Add to ~/.bashrc or ~/.zshrc for easy access: | |
| * | |
| * # Vanilla Claude Code | |
| * alias claude='npx @anthropic-ai/claude-code' | |
| * | |
| * # Claude Code with swarm features enabled | |
| * alias claude-swarm='NODE_OPTIONS="--import $HOME/.claude/injectors/feature-flag-bypass-pure.mjs" npx @anthropic-ai/claude-code' | |
| * | |
| * Fish shell (~/.config/fish/config.fish): | |
| * | |
| * function claude-swarm | |
| * set -x NODE_OPTIONS "--import $HOME/.claude/injectors/feature-flag-bypass-pure.mjs" | |
| * npx @anthropic-ai/claude-code $argv | |
| * end | |
| * | |
| * ============================================================================ | |
| * TRADEOFFS & WARNINGS | |
| * ============================================================================ | |
| * | |
| * 1. TELEMETRY: This bypass REMOVES the DISABLE_TELEMETRY and | |
| * CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC environment variables. | |
| * This is required because when these are set, Claude Code skips | |
| * reading the cached feature flags entirely. As a result, telemetry | |
| * will be RE-ENABLED when using this bypass. | |
| * | |
| * 2. DETECTION: Anthropic could trivially detect this bypass by checking | |
| * process.env.NODE_OPTIONS at startup or verifying fs.readFileSync | |
| * integrity. As of now, no such detection is implemented. | |
| * | |
| * 3. FRAGILITY: Minified function names (P8, lK, etc.) may change between | |
| * versions. The fs.readFileSync approach is more stable since it | |
| * targets the file read behavior rather than specific function names. | |
| * | |
| * ============================================================================ | |
| * LOCAL USAGE (Original Method) | |
| * ============================================================================ | |
| * | |
| * If you have claude-code installed locally or extracted: | |
| * | |
| * node --import ./research/injectors/feature-flag-bypass-pure.mjs cli.prettified.js | |
| * | |
| * Silent mode: | |
| * BYPASS_SILENT=1 node --import ./research/injectors/feature-flag-bypass-pure.mjs cli.prettified.js | |
| * | |
| * With NODE_OPTIONS: | |
| * NODE_OPTIONS="--import ./research/injectors/feature-flag-bypass-pure.mjs" node cli.prettified.js | |
| * | |
| * ============================================================================ | |
| * HOW IT WORKS | |
| * ============================================================================ | |
| * | |
| * 1. Uses --import flag to load this ESM module BEFORE any application code | |
| * 2. Gets a mutable fs object via CommonJS require (ESM namespaces are frozen) | |
| * 3. Hooks fs.readFileSync to intercept reads of .claude.json files | |
| * 4. Injects tengu_brass_pebble=true into cachedGrowthBookFeatures | |
| * 5. Removes telemetry env vars that would bypass the feature flag cache | |
| * 6. Returns modified JSON; Claude Code sees swarm features as enabled | |
| * | |
| * The feature flag check chain in Claude Code: | |
| * P8() -> lK('tengu_brass_pebble') -> rt() -> nRA() -> !lO() | |
| * | |
| * If DISABLE_TELEMETRY or CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC is set, | |
| * lO() returns true, making the entire chain return false (default value), | |
| * completely bypassing the cached feature flags. That's why we remove them. | |
| */ | |
| import { createRequire } from 'node:module'; | |
| // Use CommonJS require to get mutable fs object (ESM namespaces are read-only) | |
| const require = createRequire(import.meta.url); | |
| const fs = require('fs'); | |
| // Configuration | |
| const SILENT = process.env.BYPASS_SILENT === '1'; | |
| const FEATURE_FLAG_NAME = 'tengu_brass_pebble'; | |
| // Console logger (no disk writes) | |
| function log(message, type = 'info') { | |
| if (SILENT) return; | |
| const prefix = { | |
| info: '\x1b[36m[bypass]\x1b[0m', | |
| success: '\x1b[32m[bypass]\x1b[0m', | |
| warn: '\x1b[33m[bypass]\x1b[0m', | |
| error: '\x1b[31m[bypass]\x1b[0m', | |
| }[type] || '\x1b[36m[bypass]\x1b[0m'; | |
| process.stderr.write(`${prefix} ${message}\n`); | |
| } | |
| // Store original function | |
| const originalReadFileSync = fs.readFileSync.bind(fs); | |
| // Statistics for verification | |
| let interceptCount = 0; | |
| let injectCount = 0; | |
| /** | |
| * Intercept fs.readFileSync to inject feature flags | |
| */ | |
| fs.readFileSync = function(filePath, options) { | |
| const result = originalReadFileSync(filePath, options); | |
| // Only intercept Claude settings files | |
| if (typeof filePath !== 'string') return result; | |
| if (!filePath.endsWith('.claude.json') && !filePath.endsWith('.config.json')) { | |
| return result; | |
| } | |
| interceptCount++; | |
| try { | |
| // Parse the content | |
| const content = typeof result === 'string' ? result : result.toString('utf8'); | |
| let settings; | |
| try { | |
| settings = JSON.parse(content); | |
| } catch { | |
| // If JSON is invalid, create minimal settings with our flag | |
| settings = {}; | |
| } | |
| // Ensure cachedGrowthBookFeatures exists | |
| if (!settings.cachedGrowthBookFeatures || typeof settings.cachedGrowthBookFeatures !== 'object') { | |
| settings.cachedGrowthBookFeatures = {}; | |
| } | |
| // Inject feature flag (merge, don't replace) | |
| const wasEnabled = settings.cachedGrowthBookFeatures[FEATURE_FLAG_NAME]; | |
| if (!wasEnabled) { | |
| settings.cachedGrowthBookFeatures[FEATURE_FLAG_NAME] = true; | |
| injectCount++; | |
| log(`Injected ${FEATURE_FLAG_NAME}=true`, 'success'); | |
| } | |
| // Return modified content in same format as input | |
| const modified = JSON.stringify(settings); | |
| return options?.encoding || typeof result === 'string' ? modified : Buffer.from(modified); | |
| } catch (err) { | |
| // On any error, return original content unchanged | |
| log(`Error during injection: ${err.message}`, 'warn'); | |
| return result; | |
| } | |
| }; | |
| /** | |
| * Remove environment variables that bypass the feature flag cache | |
| * | |
| * CRITICAL: When these are set, lK() returns the default value (false) | |
| * without ever reading the cached feature flags! | |
| * | |
| * Call chain: lK() -> rt() -> nRA() -> lO() | |
| * lO() returns true if any of these are set, causing rt() to return false, | |
| * which makes lK() skip the cache and return the default. | |
| */ | |
| const telemetryVarsToRemove = [ | |
| 'DISABLE_TELEMETRY', | |
| 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC' | |
| ]; | |
| for (const varName of telemetryVarsToRemove) { | |
| if (process.env[varName]) { | |
| log(`Removing ${varName} (was: ${process.env[varName]})`, 'warn'); | |
| delete process.env[varName]; | |
| } | |
| } | |
| // Also ensure CLAUDE_CODE_AGENT_SWARMS isn't set to disable | |
| if (process.env.CLAUDE_CODE_AGENT_SWARMS === 'false' || | |
| process.env.CLAUDE_CODE_AGENT_SWARMS === '0') { | |
| log(`Removing CLAUDE_CODE_AGENT_SWARMS=${process.env.CLAUDE_CODE_AGENT_SWARMS}`, 'warn'); | |
| delete process.env.CLAUDE_CODE_AGENT_SWARMS; | |
| } | |
| log('Pure bypass active (zero disk writes)', 'success'); | |
| // Verification helper - check if bypass worked after startup | |
| if (!SILENT) { | |
| // Use setImmediate to run after module loading | |
| setImmediate(() => { | |
| if (interceptCount === 0) { | |
| log('Warning: No settings files intercepted yet', 'warn'); | |
| } else { | |
| log(`Intercepted ${interceptCount} settings reads, injected ${injectCount} flags`, 'info'); | |
| } | |
| }); | |
| } | |
| // Export for programmatic verification | |
| export function getStats() { | |
| return { interceptCount, injectCount, featureFlag: FEATURE_FLAG_NAME }; | |
| } | |
| export function isActive() { | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment