Skip to main content
Glama
README.md
<div align="center">

# 🏃 Baton

### Pass the context, not the chat log.

**Secure, verifiable knowledge handoff for AI agents and the teams that use them.**

Baton turns any agent session — Claude Code, Cursor, Copilot, Codex, Gemini CLI, Windsurf, your own agents — into a
signed, redacted **Handoff Packet** that another person or agent can pick up and continue in seconds.

[![CI](https://github.com/RK905/baton/actions/workflows/ci.yml/badge.svg)](https://github.com/RK905/baton/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
![Spec](https://img.shields.io/badge/spec-baton%2F1.0-FF6A2B)
![MCP](https://img.shields.io/badge/MCP-compatible-2FA36B)

[Quickstart](#quickstart) · [Agents](#works-with-your-agents) · [Teams & enterprise](#for-teams-and-enterprise) ·
[Packet spec](docs/spec.md) · [Self-hosting](docs/self-hosting.md) · [Security](docs/security/threat-model.md) ·
[SOC 2 mapping](docs/compliance/soc2.md)

</div>

---

## Why

Real work now happens inside agent sessions — and that context dies when the session ends, the shift changes, or a
person leaves. Copy-pasted transcripts are huge, noisy, leak secrets, and can't be checked.

| | Transcript / chat export | Hand-written doc | **Baton packet** |
|---|:-:|:-:|:-:|
| Small enough to load into any agent | ❌ | ✅ | ✅ |
| Every claim cites a checkable source | ❌ | rarely | ✅ |
| Detects when sources changed since | ❌ | ❌ | ✅ |
| Secrets/PII removed before it leaves your machine | ❌ | ❌ | ✅ |
| Tamper-evident (signed) | ❌ | ❌ | ✅ |
| Expiring, revocable, audited | ❌ | ❌ | ✅ |
| Works across vendors/tools | ❌ | ✅ | ✅ |
| Safe against prompt injection on receive | ❌ | n/a | ✅ fenced as untrusted data |

## How it works

```mermaid
flowchart LR
  subgraph Sender["Sender machine"]
    A[Agent session<br/>Claude Code · Cursor · Codex …] -->|/handoff| M1[baton MCP / CLI]
    M1 --> R[Local redaction] --> S[ed25519 signing]
  end
  S -->|file, git, or TLS upload| T[(Baton team server<br/>encrypted at rest · RBAC · audit)]
  T -->|link / id| M2
  subgraph Receiver["Receiver machine"]
    M2[baton MCP / CLI] --> V[Verify hash + signature<br/>re-check every file:line source] --> B[Agent context<br/>fenced as untrusted data]
  end
```

1. **`/handoff`** — your agent drafts a packet: summary, atomic **facts with sources**, **decisions** with rejected
   alternatives, **pitfalls** (dead ends), and **open items** with a concrete next step. You review it.
2. **Redact + sign locally** — 29 secret/PII detectors (cloud keys, tokens, JWTs, private keys, connection strings,
   cards, emails, high-entropy strings, your org's custom patterns) run *before anything leaves the machine*.
   Then the packet is hashed and signed with your ed25519 key.
3. **Share** — as a file, in git, or via your team's Baton server (expiring, revocable links; every read audited).
4. **`/receive`** — the receiving agent verifies integrity, re-checks every `file:line` source against *its* working
   tree (ok / moved / changed / missing → stale), and loads the packet **fenced as untrusted data** so instructions
   hidden in a packet can't hijack it. It summarizes, flags stale facts and proposes the next step — then waits for you.

## Quickstart

> Packages are published under `@batonhq/*`. Until the first npm release, build from source:
> `git clone https://github.com/RK905/baton && cd baton && pnpm install && pnpm build`, then use
> `node packages/cli/dist/index.js` for `baton` and `node packages/mcp/dist/index.js` for the MCP server.

### Solo (no server) — 60 seconds

```bash
npm i -g @batonhq/cli
baton init --user you@example.com          # creates ~/.baton and your signing key

# Claude Code
claude mcp add baton -- npx -y @batonhq/mcp
# …or install the plugin (adds /handoff + /receive + skills):
#   /plugin marketplace add RK905/baton
#   /plugin install baton@baton
```

In a session: **`/handoff me "auth refactor — day 1"`**. Tomorrow, in a fresh session (or a different tool):
**`/receive last`**.

### Team

```bash
# 1. Run the server (Postgres + Baton)
echo "BATON_ENCRYPTION_KEYS=k1:$(openssl rand -base64 32)" > .env
docker compose up -d
docker compose run --rm baton bootstrap --slug acme --name "Acme" --email you@acme.com   # prints an owner API key once

# 2. Each teammate
export BATON_API_KEY=bk_…                    # or sign in with your IdP token (OIDC)
baton login --server https://baton.acme.internal --register-key
```

Now `/handoff to sam@acme.com` returns a link; Sam runs `/receive <link>` in Cursor, Codex, or wherever they work.

### CLI only (CI, scripts, non-MCP tools)

```bash
baton create -t "Flaky checkout test" -s "Fails 1 in 20 on CI; timing race in cart fixture." \
  --fact "Race is in fixture setup | file:tests/fixtures/cart.ts:41" \
  --next "Await cart.ready() before asserting" --pitfall "Retrying the job only hides it" --to team:web
baton send last --to server                   # redact → sign → upload → link
baton receive https://baton.acme.internal/s/…  # verify → print for an agent
baton query last "why not just add a retry?"  # retrieve the decision that answers it
baton verify ./handoff.baton.json --strict    # CI gate: fail on integrity errors or stale sources
```

## Works with your agents

Baton is an [MCP](https://modelcontextprotocol.io) server plus a CLI and SDKs, so it's vendor-neutral by design.

| Agent | Setup |
|---|---|
| **Claude Code** | Plugin: `/plugin marketplace add RK905/baton` → `/plugin install baton@baton` ([details](plugins/claude-code)) |
| **Claude Desktop** | [`claude_desktop_config.json`](plugins/claude-desktop) |
| **Cursor** | [`mcp.json` + rule](plugins/cursor) |
| **VS Code / GitHub Copilot agent mode** | [`.vscode/mcp.json`](plugins/vscode) |
| **Windsurf** | [`mcp_config.json`](plugins/windsurf) |
| **OpenAI Codex CLI** | [`config.toml` + AGENTS.md](plugins/codex) |
| **Gemini CLI** | [`settings.json`](plugins/gemini-cli) |
| **Zed** | [`context_servers`](plugins/zed) |
| **Any MCP client** | `npx -y @batonhq/mcp` over stdio + [`AGENTS.md`](plugins/AGENTS.md) |
| **Python agents** (LangGraph, CrewAI, OpenAI Agents SDK, AutoGen, custom) | [`sdks/python`](sdks/python) |
| **TypeScript agents / services** | [`@batonhq/sdk`](packages/sdk) + [`@batonhq/core`](packages/core) |

MCP tools: `handoff_create` · `handoff_redact` · `handoff_send` · `handoff_receive` · `handoff_verify` ·
`handoff_query` · `handoff_list` · `handoff_revoke`. Prompts: `handoff`, `receive`. Resources: `baton://packet/{id}`.

## For teams and enterprise

The open-source **Baton team server** (`apps/server`) is built for multi-team, regulated environments:

| Area | What you get |
|---|---|
| **Identity** | API keys (hashed, scoped, expiring), **OIDC SSO** (Okta, Entra ID, Google, Auth0, Keycloak) with JIT provisioning and group→role mapping, **SCIM 2.0** user provisioning/deprovisioning |
| **Access control** | Roles `owner` · `admin` · `member` · `viewer` · `auditor`; scoped keys can only narrow a role; **teams**; per-packet classification (`public`/`internal`/`confidential`/`restricted`) — confidential packets are visible only to author, named recipients/teams and admins |
| **Multi-tenancy** | Every row is org-scoped; packet ids can't collide or be probed across orgs (uniform 404s) |
| **Data protection** | Client-side redaction **plus** server-side re-scan with org rules; AES-256-GCM envelope encryption at rest with key rotation and row-bound AAD; ed25519 signatures with an org signing-key registry (`require_signature`, `require_known_signer`) |
| **Sharing controls** | Expiring links, max-view links, org-only links by default, anonymous links only if policy allows (and never for confidential), revoke packet → every link dies, reshare permission |
| **Audit** | Every create/read/query/link/revoke/admin action recorded in the same transaction as the change, **hash-chained per org** (tamper-evident; `GET /v1/audit/verify`), append-only enforced by a DB trigger, NDJSON export for your SIEM |
| **Governance** | Org policy: expiry caps, retention (crypto-shred content after N days), audit retention, allowed classifications, custom redaction rules/allowlists, SSO-only for humans |
| **Integrations** | HMAC-signed webhooks (`packet.created`, `packet.revoked`, …) with SSRF protection; Slack-formatted delivery that never leaks confidential titles |
| **Operations** | Stateless replicas, Postgres, `/healthz` `/readyz` `/metrics`, structured JSON logs with secret scrubbing, rate limiting, Helm chart (HPA, PDB, NetworkPolicy, non-root read-only pods, migration hook, retention CronJob), SBOM + provenance-attested images |

See [`docs/compliance/soc2.md`](docs/compliance/soc2.md) for how these controls map to the SOC 2 Trust Services
Criteria, and [`docs/security/threat-model.md`](docs/security/threat-model.md) for the threat model.

> Baton gives you controls that *support* a SOC 2 program; it is not itself a certification. Your deployment,
> processes and auditor determine compliance.

## The packet

```jsonc
{
  "manifest": {
    "spec": "baton/1.0", "id": "hp_01M8RYMYH0F96QHJKDPGXRCJQW",
    "title": "Stage SQS sendMessage denied — root cause + fix",
    "author": { "type": "human+agent", "user": "alex@example.com", "agent": "claude-code" },
    "recipients": ["sam@example.com"], "status": "in_progress", "classification": "internal",
    "scope": { "repos": ["orders-service"], "envs": ["stage"], "tags": ["sqs", "iam"] },
    "expires_at": "2026-12-31T14:03:00.000Z",
    "redaction": { "engine": "baton-redact/0.1", "findings": 0, "by_rule": {}, "reviewed_by_author": true },
    "hash": "sha256:…", "signature": { "alg": "ed25519", "key_id": "k_…", "public_key": "…", "value": "…" }
  },
  "summary": "Producer lambdas on stage fail with AccessDenied… root cause is the queue resource policy…",
  "facts": [{ "id": "f2", "claim": "Producer reads the queue URL from queues.orders",
              "source": { "type": "file", "value": "orders-service/lambda/producer/main.ts:88", "hash": "sha256:…" },
              "confidence": "verified" }],
  "decisions": [{ "id": "d1", "decision": "Fix the queue policy, not the lambda role",
                  "rationale": "Role already allows SendMessage", "alternatives": ["Widen the IAM role"], "fact_ids": ["f1", "f3"] }],
  "open_items": [{ "id": "o1", "text": "Update inventory-events policy principal to stage", "requires_confirmation": true }],
  "pitfalls": [{ "id": "p1", "text": "CloudTrail shows the role as principal — looks like IAM, it isn't." }]
}
```

Full spec: [`docs/spec.md`](docs/spec.md) · JSON Schema: [`packages/spec/schema/packet.schema.json`](packages/spec/schema/packet.schema.json) ·
Examples: [`examples/`](examples)

## Repository layout

```
packages/
  spec/      @batonhq/spec    packet schema (zod + JSON Schema), canonical hashing, ed25519 signatures
  redact/    @batonhq/redact  local secret/PII detectors and redaction
  core/      @batonhq/core    build, source fingerprinting/verification, rendering, query, local store, transport
  mcp/       @batonhq/mcp     MCP server (stdio) — tools, prompts, resources
  cli/       @batonhq/cli     `baton` command
  sdk/       @batonhq/sdk     TypeScript client for the team server API
apps/
  server/    @batonhq/server  multi-tenant team server (Hono + Postgres)
sdks/python/ baton-sdk        Python client + packet builder (wire-compatible signatures)
plugins/                      Claude Code plugin + configs for Cursor, VS Code, Windsurf, Codex, Gemini CLI, Zed, Desktop
deploy/helm/                  Helm chart
docs/                         spec, architecture, API, self-hosting, SSO/SCIM, security, compliance
examples/                     signed example packets (also used as cross-language test fixtures)
```

## Development

```bash
pnpm install
pnpm build          # all packages
pnpm test           # unit + server end-to-end tests (embedded Postgres via PGlite — no Docker needed)
pnpm dev:server     # server on :8080 with in-memory DB
```

Docs: [architecture](docs/architecture.md) · [API reference](docs/api.md) · [SSO & SCIM](docs/sso-scim.md) ·
[contributing](CONTRIBUTING.md).

## Roadmap

- [x] Packet spec v1.0, local redaction, signing, source verification
- [x] MCP server, CLI, Claude Code plugin, configs for 8 agents
- [x] Team server: RBAC, teams, OIDC SSO, SCIM, audit chain, retention, webhooks, encryption at rest
- [x] Python + TypeScript SDKs
- [ ] Web dashboard (team library, search, lineage graph) with browser SSO login
- [ ] Semantic search across a team's packets (pgvector), knowledge distillation → PRs into `CLAUDE.md` / rules files
- [ ] End-to-end encrypted packets (recipient public keys; server never sees plaintext)
- [ ] Native Slack / GitHub PR / Linear / PagerDuty apps
- [ ] SCIM Groups → teams, data-residency routing, customer-managed keys (KMS)
- [ ] Eval harness: recorded sessions → packets → a fresh agent must answer and act correctly

## Contributing & security

Contributions welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Please report vulnerabilities privately as described
in [SECURITY.md](SECURITY.md).

## License

[MIT](LICENSE). "Claude", "Cursor", "Copilot", "Codex", "Gemini" and other names are trademarks of their owners;
Baton is an independent project and is not affiliated with or endorsed by them.