Skip to main content
Glama
README.md
<p align="center">
  <img src="https://raw.githubusercontent.com/RajithSundar/tetherlm/main/assets/hero.svg" width="100%" alt="TetherLM — USB-C Android NPU Sidecar for Coding Agents" />
</p>

<p align="center">
  <a href="https://www.npmjs.com/package/tetherlm"><img src="https://img.shields.io/npm/v/tetherlm.svg" alt="npm version" /></a>
  <a href="https://github.com/RajithSundar/tetherlm/actions/workflows/ci.yml"><img src="https://github.com/RajithSundar/tetherlm/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-AGPL--3.0-blue.svg" alt="License" /></a>
  <a href="./package.json"><img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg" alt="Node >= 20" /></a>
</p>

Every time Claude Code, Cursor, or Antigravity reads a production crash log or hunts through a codebase, you pay frontier API rates to upload tens of thousands of lines of noise—along with whatever API keys, JWTs, and internal URLs were sitting inside them.

Meanwhile, the Android phone sitting next to your keyboard has a dedicated NPU idling at 0%.

**TetherLM** connects the two over USB-C. It scrubs secrets on your machine, runs log compression, file triage, and diff review locally on your phone's NPU, and hands your cloud agent a clean, tiny summary.

---

## Plug & Play Setup

Enable **USB Debugging** on your Android phone, plug it in over USB-C, and run one command:

```bash
# Auto-installs standalone ADB (if missing), phone NPU runtime, and Gemma 4 E2B:
npx tetherlm@latest init
```

Want TetherLM wired into your editor automatically?

```bash
npx tetherlm@latest init --cursor   # Writes .cursor/mcp.json
npx tetherlm@latest init --claude   # Registers via `claude mcp add`
```

Open a second terminal anytime to watch live NPU intercepts, blocked secrets, and phone thermals:

```bash
npx tetherlm@latest hud
```

---

## How It Works

<p align="center">
  <img src="https://raw.githubusercontent.com/RajithSundar/tetherlm/main/assets/pipeline.svg" width="100%" alt="TetherLM 4-stage local privacy and compression pipeline" />
</p>

1. **Intercept & Scrub Locally:** TetherLM blocks sensitive paths (`.ssh`, `.aws`, `.git`, `*.pem`) and masks 14+ credential formats plus high-entropy strings *before* anything leaves your PC.
2. **Compress Over USB-C:** Your phone's Qualcomm Hexagon NPU (with automatic fallback to mobile OpenCL GPU or ARM64 CPU) distills 500-line crash logs and multi-file searches into compact JSON over a `127.0.0.1` USB loopback.
3. **Verify on Egress:** A second scrubber pass scans the phone's output before returning it to your coding agent—guaranteeing **zero secret leakage** and **~98% fewer cloud input tokens**.

---

## Measured Impact (Before vs. After)

Tested on a 12-file service with 2 bugs buried inside a 500-line, secret-filled production crash log (`OnePlus 15R` · `Snapdragon 8 Gen 5` · `Gemma 4 E2B Q4_0`):

| Metric | Without TetherLM | With TetherLM | Why It Matters |
| :--- | ---: | ---: | :--- |
| **Cloud Input Tokens** | `47,016` | **`898`** | **98.1% reduction** — keeps frontier context lean and cheap |
| **Crash Log Tokens** | `44,264` | **`183`** | **99.6% reduction** — extracts structured JSON root causes |
| **Secrets Sent to Cloud** | `517` | **`0`** | Blocks AWS/Stripe/Anthropic keys, JWTs, DB URIs, emails & IPs |
| **Phone Temp Change** | — | **`+0.0 °C`** (`29.6 °C`) | Single-slot Hexagon NPU execution stays cool on your desk |
| **End-to-End Bug Fix** | `3/3 tests pass` | **`3/3 tests pass`** | Identical fix quality at a fraction of the cloud token budget |

---

## 5 Tools Your Coding Agent Gains

| MCP Tool | When Your Agent Uses It | What Returns to the Cloud |
| :--- | :--- | :--- |
| `compress_log` | Diagnosing huge build, test, or prod crash logs (tails up to 5 MB) | Compact JSON array of real errors (`file`, `function`, `symptom`, `detail`) |
| `triage_files` | Narrowing down 10–40 candidate files before reading full source | JSON list of only the files that actually match the bug or feature |
| `private_summarize` | Answering questions about config or internal docs without exposing keys | Concise, egress-scrubbed answer with secret categories redacted |
| `private_diff` | Reviewing uncommitted `git diff` *before* `git commit` or PR creation | Secret-leak warning + clean bullet summary + commit title suggestion |
| `vault_status` | Checking sidecar health and session savings | Phone model, NPU backend, °C, battery %, free RAM, and \$ saved |

---

## Deep Dive & Reference

<details>
<summary><b>Hardware Benchmarks — CPU vs. GPU vs. Hexagon NPU (OnePlus 15R)</b></summary>
<br/>

Model: `gemma-4-E2B-it-Q4_0.gguf` (`2.82 GiB`, `llama.cpp b12833`, `-p 512 -n 128 -fa 1`)

| Backend | Device | Prompt (`pp512`) | Generation (`tg128`) | Temp After |
| :--- | :--- | ---: | ---: | ---: |
| CPU | Qualcomm Oryon (8 threads) | 547.8 tok/s | 14.81 tok/s | 28.6 °C |
| GPU | Adreno 829 (`OpenCL`) | 798.2 tok/s | 14.62 tok/s | 29.9 °C |
| **NPU** | **Hexagon `HTP0` (v81)** | **6,094.8 tok/s** | **36.55 tok/s** | **29.9 °C (+0.0 °C)** |

Have another Android phone? Run `npx tetherlm@latest bench` and [add your device to the leaderboard](https://github.com/RajithSundar/tetherlm/issues/new?template=hardware-benchmark.yml).

</details>

<details>
<summary><b>CLI Commands &amp; Environment Variables</b></summary>
<br/>

| Command | Description |
| :--- | :--- |
| `tetherlm init [--cursor] [--claude] [--check]` | Provision ADB + runtime + model on your phone and output/write MCP config. |
| `tetherlm serve [--root <dir>]` | Start the MCP stdio server sandboxed to `<dir>`. |
| `tetherlm hud [--once]` | Live terminal dashboard for °C, battery, blocked secrets, and token savings. |
| `tetherlm bench` | Benchmark CPU, GPU, and NPU on your phone and print a Markdown table. |
| `tetherlm doctor` | 6-step diagnostic check (ADB, USB auth, RAM, runtime, NPU, tunnel). |
| `tetherlm stop` | Unload `llama-server` from phone RAM immediately and remove USB port forward. |

| Environment Variable | Default | Purpose |
| :--- | :--- | :--- |
| `TETHERLM_BACKEND` | `auto` | `auto` (`HTP0` → `GPUOpenCL` → `CPU`), `HTP0`, `GPUOpenCL`, or `CPU`. |
| `TETHERLM_MODEL` | `gemma-4-E2B-it-Q4_0.gguf` | GGUF filename staged in `/data/local/tmp/llama`. |
| `TETHERLM_CTX` | `8192` | Context size for single-slot (`-np 1`) low-RAM execution. |
| `TETHERLM_PORT` | `8080` | Localhost port tunneled over USB ADB. |
| `TETHERLM_SERIAL` | *(auto)* | Target a specific ADB device serial (physical USB prioritized over emulators). |
| `TETHERLM_ROOT` | `process.cwd()` | Workspace sandbox root directory. |

</details>

<details>
<summary><b>Security Architecture &amp; Daily-Driver Phone Safety</b></summary>
<br/>

- **Entity-Preserving Redaction:** Repeated emails and private IPs receive consistent per-call tags (`<REDACTED_EMAIL_1>`, `<REDACTED_EMAIL_2>`) so debugging relationships stay clear with zero PII exposure.
- **Strict Sandbox + Symlink Resolution:** Canonicalizes paths via `fs.realpathSync` and blocks `..`, `~`, `.git`, `.ssh`, `.aws`, `.gnupg`, `.kube`, `.npmrc`, `*.pem`, `*.key`, `*.kdbx`, and binary files.
- **Prompt-Injection Isolation:** External log and file contents are wrapped in escaped `<untrusted_data>` boundaries.
- **Designed for Your Daily Phone:** Uses `-np 1` single-slot KV caching (leaving 3+ GB RAM free on 12 GB phones), unloads automatically after 10 minutes idle, and trips a safety circuit breaker if battery drops below `20%` (unplugged) or temperature exceeds `42 °C`.

Read the full threat model in [SECURITY.md](./SECURITY.md).

</details>

---

## License

Open-source under **AGPL-3.0-only** ([LICENSE](./LICENSE)). Commercial licenses are available for teams and enterprises integrating TetherLM into proprietary workflows—open an issue to get in touch. Contributions welcome under [CONTRIBUTING.md](./CONTRIBUTING.md) and [CLA.md](./CLA.md).