Skip to content

yehsuf/myelin

Repository files navigation

Myelin

The neural insulation layer for AI coding agents.

License: MIT Node.js 20+ Platforms

In biology, myelin is the substance that wraps around neurons and makes signals travel 100× faster.
This is myelin for your AI coding agent.

~14-72% Copilot token reduction · 91% fewer tools per request · KV cache 69%+ hit rate · works with Claude Code + GitHub Copilot CLI


What it does

AI coding agents burn through context in 30 minutes. Myelin wraps your agent stack with compression layers:

USER PROMPT
    ↓
Serena + Semble    LSP-backed code discovery     →  symbol-precise, no full-file reads
RTK                Shell output compression       →  60-90% on CLI output
mitmproxy addon    Tool filter + compress         →  91% fewer tools, 14-72% byte reduction
Selected engine    Outbound compression + cache   →  69%+ KV cache hit rate, cost savings
  (Python Headroom or Headroom Lite — set by proxy.engine)
Enforcement hooks  Prevents agent backsliding     →  makes savings stick
    ↓
Anthropic API / GitHub Copilot API
  Claude: via selected engine → provider
  Copilot: MITM ingress → selected-engine Copilot instance → MITM egress → provider

Prerequisites

macOS

The installer auto-installs everything missing. Only hard prerequisites: Node.js 20+, Homebrew.

# Check what you have
node --version && brew --version

# Install only what's missing
brew install node          # if node missing / < 20
# (Python ships with macOS 13+; brew install python@3.12 if older)

Linux (Ubuntu/Debian)

The installer auto-installs everything missing. Only hard prerequisites: Node.js 20+, Python 3.10+.

# Check what you have
node --version 2>/dev/null || echo "node: missing"
python3 --version

# Install Node 20+ via nvm (if missing or < 20)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc && nvm install 20

Windows (PowerShell)

The installer detects what you have and installs only what's missing. The only hard prerequisites are Node.js 20+, Python 3.10+, and Git — everything else (mitmproxy, headroom, RTK, serena, semble) is installed automatically.

Check what you already have:

node --version    # need 20+
python --version  # need 3.10+
git --version

Install only what's missing (run PowerShell as Administrator):

winget install Git.Git            # if git missing
winget install OpenJS.NodeJS.LTS  # if node missing / < 20
winget install Python.Python.3.12 # if python missing
# Restart PowerShell after any winget install

Clone, check, and install:

git clone https://github.com/yehsuf/myelin.git "$env:USERPROFILE\.myelin\repo"
cd "$env:USERPROFILE\.myelin\repo"
npm install
node src/install.mjs --check     # shows what's present vs missing
node src/install.mjs --dry-run   # preview what would be installed
node src/install.mjs --yes       # install everything missing
. $PROFILE                        # reload in current window

What the installer does on Windows:

  • Registers headroom as a Scheduled Task (MyelinHeadroom) — starts at logon, restarts on failure
  • Registers mitmproxy as a Scheduled Task (MyelinMitmproxy) — starts at logon
  • Writes $env:ANTHROPIC_BASE_URL, $env:HEADROOM_PORT, CA bundle env vars to ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  • Adds _copilot PowerShell function (health-checks :8888, falls back gracefully)
  • Adds myelin function pointing to the CLI

After install, in any new PowerShell window:

myelin verify          # health check
_copilot               # Copilot CLI through mitmproxy (compressed)
copilot                # Copilot CLI direct (uncompressed)
claude                 # Claude Code through headroom (compressed)

Install

macOS / Linux

git clone https://github.com/yehsuf/myelin.git ~/.myelin/repo
cd ~/.myelin/repo
npm install
node src/install.mjs --check      # shows what's present vs missing
node src/install.mjs --dry-run    # preview what would be installed
node src/install.mjs --yes        # install
source ~/.zshrc        # macOS (zsh)
# or:
source ~/.bashrc       # Linux (bash)

Windows (PowerShell)

git clone https://github.com/yehsuf/myelin.git "$env:USERPROFILE\.myelin\repo"
cd "$env:USERPROFILE\.myelin\repo"
npm install
node src/install.mjs --yes
. $PROFILE    # reload profile in current window

Verify

myelin verify          # health check all 7 components
myelin stats           # compression statistics
myelin config show     # view current settings

Expected output (rows vary by config — this is the default proxy.engine: headroom profile):

✓ headroom service   :8787  running    # or headroom-lite :8790 if proxy.engine=headroom_lite
✓ headroom health    :8787  healthy
✓ mitmproxy service  :8888  running
✓ rtk                       ready
✓ ast-grep                  ready
✓ semble                    ready

Usage

Claude Code (automatic)

claude   # ANTHROPIC_BASE_URL automatically points to headroom :8787

The selected engine (Python Headroom by default; Headroom Lite if proxy.engine: headroom_lite) compresses messages before forwarding to Anthropic. KV cache alignment reduces costs by up to $1+/day.

GitHub Copilot CLI (compressed)

_copilot   # routes through mitmproxy :8888 — compresses + filters tools
copilot    # direct, uncompressed (still works if mitmproxy is down)

_copilot health-checks port 8888 first — falls back to plain copilot with a warning if mitmproxy is offline.

When proxy.copilot_headroom.enabled is true, Copilot traffic is further compressed by a dedicated selected-engine instance:

Copilot CLI → MITM ingress (:8888) → selected-engine Copilot instance (:8788) → MITM egress (:8889) → Copilot API

MITM is the sole real-network-egress owner; the engine instance targets only the loopback egress port.

When proxy.copilot_headroom.enabled is false (the default), no Copilot engine service is created, no watchdog probe is registered for the Copilot role, and no readiness or status endpoint is added for Copilot.


What gets compressed

Layer Before After Saving
Tools per request (Copilot) ~125 tools ~11 tools 91%
Bytes per request (Copilot) baseline -14 to -72% 14-72%
KV cache hit rate (Claude) ~0% cold ~69% 69%+ token discount
Text compression (Claude) baseline -3.5% additional small

Platform feature parity

Feature macOS Linux Windows
Installer ✅ (untested)
Claude Code via headroom ✅ (untested)
Copilot via mitmproxy ✅ (untested)
CA generation (no sudo) ✅ keychain ✅ ca-bundle.pem ✅ certutil
Background service ✅ launchd ✅ systemd user ✅ Task Scheduler
Shell reload (auto) ✅ AppleScript ⚠️ run manually ⚠️ restart shell
myelin stats
_copilot health fallback

Configuration

Config: ~/.myelin/config.yaml

proxy:
  engine: headroom      # headroom (default) or headroom_lite
  headroom:
    port: 8787          # change: myelin config set proxy.headroom.port 9090
    backend: kompress-base   # or: llmlingua-2  (headroom only)
  headroom_lite:
    port: 8790          # active when engine: headroom_lite
  copilot_headroom:
    enabled: false      # true: adds isolated selected-engine Copilot instance
    port: 8788
  mitm:
    port: 8888
    egress_port: 8889        # MITM loopback egress for Copilot routing
    block_bypass: false      # set true if behind content filter (NetFree etc.)
    override_proxy: ''       # socks5://10.8.0.1:1080

index_tier: default     # light | default | full

Corporate / SSL environments

Myelin auto-detects corporate proxies and CA bundles. If it misses yours:

export HTTPS_PROXY=http://proxy.corp.example.com:3128
export HEADROOM_CA_BUNDLE=/path/to/corporate-ca.pem

Block bypass (NetFree / content filters)

myelin config set proxy.mitm.block_bypass true
myelin config set proxy.mitm.override_proxy socks5://10.8.0.1:1080
node ~/.myelin/repo/src/install.mjs --yes   # re-registers service

Profiles

node src/install.mjs --profile proxy    # default: full proxy + MCPs
node src/install.mjs --profile mcp      # MCPs only, no proxy daemon
node src/install.mjs --profile minimal  # Serena + RTK only

Update

myelin update --self             # safe self-update (aborts on uncommitted changes)
myelin update --self --force     # bypass that safety check if you accept the risk

cd ~/.myelin/repo
git fetch origin && git reset --hard origin/main
npm install
node src/install.mjs --yes

Uninstall

The service name is the same regardless of which engine (headroom or headroom_lite) is selected — only one primary service and one optional copilot-role service ever exist.

# macOS
launchctl bootout gui/$(id -u)/com.myelin.mitmproxy 2>/dev/null
launchctl bootout gui/$(id -u)/com.myelin.headroom 2>/dev/null
launchctl bootout gui/$(id -u)/com.myelin.copilot-headroom 2>/dev/null   # only if proxy.copilot_headroom.enabled was true
rm ~/Library/LaunchAgents/com.myelin.mitmproxy.plist
rm ~/Library/LaunchAgents/com.myelin.headroom.plist
rm -f ~/Library/LaunchAgents/com.myelin.copilot-headroom.plist

# Linux
systemctl --user disable --now myelin-mitmproxy.service myelin-headroom.service myelin-copilot-headroom.service 2>/dev/null
rm -f ~/.config/systemd/user/myelin-mitmproxy.service ~/.config/systemd/user/myelin-headroom.service ~/.config/systemd/user/myelin-copilot-headroom.service
systemctl --user daemon-reload

# Windows
Unregister-ScheduledTask -TaskName "MyelinMitmproxy" -Confirm:$false
Unregister-ScheduledTask -TaskName "MyelinHeadroom" -Confirm:$false
Unregister-ScheduledTask -TaskName "MyelinCopilotHeadroom" -Confirm:$false   # only if proxy.copilot_headroom.enabled was true

# Edit ~/.zshrc (macOS) or ~/.bashrc (Linux) and remove the
# '# >>> myelin managed >>>' ... '# <<< myelin managed <<<' block
rm -rf ~/.myelin

Architecture

See docs/specs/2026-07-06-tokenstack-design.md for the full architecture spec.

License

MIT — see LICENSE

About

The neural insulation layer for AI coding agents. 93% token reduction, 6× longer sessions. Serena + Semble + Headroom + RTK + mem0 in one installer.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors