Metadata-Version: 2.4
Name: keyexec
Version: 0.1.1
Summary: Keep MCP server tokens in the OS credential store and inject them only at launch.
Keywords: mcp,claude-code,secrets,credential-manager,keychain,tokens
Author: Volkan Çiçek
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Project-URL: Repository, https://github.com/volkanncicek/keyexec
Project-URL: Issues, https://github.com/volkanncicek/keyexec/issues
Project-URL: Changelog, https://github.com/volkanncicek/keyexec/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# keyexec

[![PyPI](https://img.shields.io/pypi/v/keyexec)](https://pypi.org/project/keyexec/)
[![Python](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fvolkanncicek%2Fkeyexec%2Fmain%2Fpyproject.toml)](https://pypi.org/project/keyexec/)
[![CI](https://github.com/volkanncicek/keyexec/actions/workflows/ci.yml/badge.svg)](https://github.com/volkanncicek/keyexec/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/volkanncicek/keyexec/blob/main/LICENSE)

Claude Code keeps the tokens you give an MCP server, the `env` and `headers` values of a server added with `claude mcp add`, in plaintext in `~/.claude.json`. keyexec moves them into the operating system's credential store (Windows Credential Manager or the macOS Keychain) and leaves a command in their place, so the config file no longer holds any secret and a token is handed to its server only when the server starts.

It is a launcher, not a password manager: no vault, no sync, no daemon, no runtime dependencies. It protects the file, not your account: any program running as you can still read the credential store ([Security model](#security-model)).

![keyexec in Windows Terminal: the migrate plan for three servers lists each token by name and length only, the apply stores them and names the backup, and doctor finds every entry the rewritten config refers to](https://raw.githubusercontent.com/volkanncicek/keyexec/main/docs/screenshot.png)

**Status:** in daily use on Windows, and checked end to end on macOS, where a Claude Code session connected one stdio and one http server through keyexec.

## How it works

Each token becomes an **entry**: a named item in the credential store, such as `github-token`. `keyexec migrate --apply` stores the token as that entry and rewrites the server to start through keyexec:

```diff
 "github": {
-  "command": "npx",
-  "args": ["-y", "gh-mcp"],
-  "env": { "GITHUB_TOKEN": "ghp_..." }
+  "command": "C:\\Users\\me\\.local\\bin\\keyexec.exe",
+  "args": ["run", "--env", "GITHUB_TOKEN=github-token", "--", "npx", "-y", "gh-mcp"]
 }
```

When Claude Code starts the server, `keyexec run` reads `github-token` from the store, starts `npx -y gh-mcp` with `GITHUB_TOKEN` set, and stays out of the way: it writes nothing to the server's stdio stream, ends the server when it is itself stopped, and returns the server's exit code. An http server gets a `headersHelper` instead, a command whose output Claude Code sends as request headers: `"<keyexec>" headers --header "Authorization=Bearer {acme-authorization}"`.

keyexec reads the user and local scopes in `~/.claude.json`. A repo's `.mcp.json` is not touched; keep its tokens out of the repo by hand.

`run` is not tied to MCP: `keyexec run --env GH_TOKEN=github-token -- gh pr status` gives any command a token without it sitting in your shell profile.

## Quickstart

You need [uv](https://docs.astral.sh/uv/) (it fetches a suitable Python) and Claude Code on Windows or macOS.

```shell
uv tool install keyexec
keyexec migrate              # the plan: which plaintext tokens would move, to which entries; changes nothing
keyexec migrate --apply      # store them, back up the config, rewrite it; asks first
```

Then restart your Claude Code sessions, or reconnect each server from `/mcp`, and check that the servers connect. `keyexec doctor` confirms every entry the config refers to exists:

```text
Config: C:\Users\me\.claude.json
github  [stdio]
  ok       github-token
```

Once the servers work, delete the backup `migrate` named (`~/.claude.json.keyexec-backup-<timestamp>`): it still holds the plaintext tokens, and `doctor` warns until it is gone.

If the plan is empty, no token was found in plaintext. If `--apply` stops because the config changed, Claude Code wrote the file meanwhile; run it again.

To add a server by hand, store the token first, then point the server at keyexec:

```shell
keyexec set github-token     # prompts for the value; never read from argv or a pipe
claude mcp add github -- keyexec run --env GITHUB_TOKEN=github-token -- <server command> [args...]
```

A rotated token is replaced with `keyexec set <entry> --force`; the config does not change.

## Install and upgrade

Install it as a tool rather than running it through `uvx`: `migrate --apply` writes the absolute path of the installed `keyexec` into the config, and a `uvx` cache path can disappear.

Upgrade with `uv tool upgrade keyexec`. It updates the tool in place and works while Claude Code runs. On Windows, `uv tool upgrade` is the only change to make while it runs: `uv tool install --force`, `--reinstall`, and a `uv tool install` that changes where keyexec comes from (a checkout to PyPI, say) can each delete and recreate the tool environment, whose `python.exe` every running server holds open, and leave the tool without its packages. Make those with Claude Code closed.

Releases are built by GitHub Actions and published to PyPI through trusted publishing, with attestations, so no long-lived upload token exists.

## Commands

Besides `migrate` and `doctor`, `set`, `list` and `delete` manage entries by hand, and `run` and `headers` are what a rewritten config calls. The commands that report something print JSON when their output is piped. [docs/cli.md](https://github.com/volkanncicek/keyexec/blob/main/docs/cli.md) lists every command with its flags, and has the JSON formats, the exit codes, and exactly what `migrate` treats as a secret, how it names entries and what it skips.

## Security model

What it protects against: tokens sitting in plaintext in `~/.claude.json`, and leaking from there through backups, dotfile syncs, screenshares, pasted configs, or tools and agents that read the file.

What it does **not** protect against:

- **Any process running as you can read the credential store.** On Windows, Credential Manager entries are readable by every process of the logged-in user without a prompt; on macOS the Keychain may prompt per application, but "Always Allow" removes that barrier. An agent with shell access can read an entry with a few lines of code.
- A running server holds its token in its environment, visible to same-user tools that inspect process environments.
- The migrate backup holds the plaintext tokens until you delete it.
- A secret passed in a server's command-line arguments rather than `env` or `headers` is not moved; `migrate` warns when it sees one.

keyexec makes no network requests and writes no log or file of its own besides the migrate backup. Report a vulnerability privately as described in [SECURITY.md](https://github.com/volkanncicek/keyexec/blob/main/SECURITY.md).

## Troubleshooting

- **A server does not connect after the migration.** Run `keyexec doctor`: a `MISSING` entry is one the store does not hold; store it with `keyexec set <entry>`. To see why a server will not start, run its `command` and `args` from the config in a terminal: keyexec says what is wrong before it starts anything.
- **`keyexec` exits 4.** The credential store refused or is locked; on macOS, unlock the login Keychain. Over SSH the login Keychain usually stays locked: `doctor` and `list`, which read no value, still work, but a server started there cannot get its token. On Linux keyexec refuses to run rather than fall back to a plaintext store.
- **macOS asks for your password.** Entries keyexec wrote are read without a prompt, because the Keychain lets the program that created an item read it. Deleting an entry asks for your login password, and a different Python executable, for instance after a `uv tool upgrade` that replaces it, may be asked to confirm access.
- **A value is refused as too long.** Credential Manager limits the size of one entry; [Platform notes](#platform-notes) has the number.

## Undoing it

For one server: set its `command` back to the first word after `--` in `args`, set `args` to the rest, and put the token back under `env` (for an http server, remove `headersHelper` and put the header back under `headers`). Then `keyexec delete <entry>`. Restoring the backup instead would undo whatever Claude Code wrote since.

For everything: undo each server, delete each entry `keyexec list` shows, then `uv tool uninstall keyexec`.

## Platform notes

**Windows.** Each entry is a generic credential with the target `keyexec:<entry>`, kept on this machine only rather than roaming with a domain profile, and holding at most 2560 bytes; `cmdkey /list` shows the names without the values. When Claude Code exits, or keyexec is killed outright, the server and everything it started end with it.

**macOS.** Each entry is a generic password in the login Keychain with the service `keyexec` and the entry name as account. An update changes the item in place, so an "Always Allow" survives a rotated token. `run` forwards SIGINT, SIGTERM and SIGHUP to the server.

**Linux.** Not supported: keyexec talks to Windows Credential Manager and the macOS Keychain only. [envchain](https://github.com/sorah/envchain) does the same job well on Linux and macOS.

## Development

See [CONTRIBUTING.md](https://github.com/volkanncicek/keyexec/blob/main/CONTRIBUTING.md) for setup and the checks CI runs, and [docs/design.md](https://github.com/volkanncicek/keyexec/blob/main/docs/design.md) for why the code is shaped the way it is.

## Not affiliated with Anthropic

keyexec is an independent tool for Claude Code users. It is not made, endorsed or supported by Anthropic.

## License

[MIT](https://github.com/volkanncicek/keyexec/blob/main/LICENSE)
