Guide
Managing AI Agent API Keys Securely With Windows Platform Security
Windows has real, built-in tools for this job. Most guides point you at the wrong one, because Credential Guard sounds like a vault and is not.
Windows platform security for an AI coding agent's API keys comes down to two built-in pieces, not one. Credential Manager, backed by the Data Protection API (DPAPI), stores a named secret encrypted with your Windows login, and you can add or read one from the command line with cmdkey or PowerShell's CredentialManager module. Windows Defender Credential Guard is a different thing entirely: it isolates NTLM hashes and Kerberos tickets so a domain sign-in cannot be stolen, it requires Windows Enterprise or Education, and it does nothing for an OpenAI or Anthropic API key sitting in a .env file. The practical setup is to move keys out of plain environment variables and into Credential Manager or a cross-platform CLI vault, then hand the value to a command only at the moment it runs. Forkbench does not run on Windows today, so this guide covers what Windows itself gives you, independent of any one coding agent or desktop app.
What 'Windows platform security' actually gives you here
Search for Windows platform security and AI agents and you will find a lot of generic advice about antivirus and firewalls. None of it is about the specific problem of keeping an API key away from a coding agent that reads files on your behalf. Windows does have real, relevant tools, but they sit in two different places.
The first is Credential Manager, the built-in store for stored user names and passwords, and the Data Protection API (DPAPI) underneath it, which does the actual encryption. The second is Windows Defender Credential Guard, a much heavier mechanism built for a different job. Confusing the two is the single most common mistake in this space, so this guide treats them separately from the start.
- Credential Manager plus DPAPI: a real, local secrets store for a developer's own keys.
- Credential Guard: domain sign-in protection, not a key vault for your own apps.
- Neither one is specific to AI agents. Both predate the term by a decade or more.
Credential Manager and DPAPI: what they really protect
DPAPI's core function, CryptProtectData, encrypts data using a session key derived from your Windows logon credentials. Microsoft's own documentation is specific about this: only a user with the same logon credentials as the one who encrypted the data can decrypt it, and decryption normally only works on the same computer, except for a roaming profile. That is what makes Credential Manager useful. The secret is unreadable to anyone else on the machine and unreadable if the file is copied elsewhere.
You can add a generic credential from the command line with cmdkey: cmdkey /generic:my-agent-key /user:api /pass prompts you for the value and stores it. One real limit here matters: cmdkey itself cannot print that password back out. It is designed for Windows's own credential prompts and for applications that call the Windows Credential Manager API (CredRead) to retrieve a value programmatically. If you want a script to read the secret back, write a small helper that calls that API, or use PowerShell's CredentialManager module, which wraps it. A key stored this way is not something you cat to a terminal the way you would a .env file, which is itself part of the protection.
The other limit is scope. Credential Manager protects the key at rest, on disk. Once your script reads it and hands it to a command, that command has the plaintext value, the same as with any other secrets store. Windows is not doing anything different from macOS Keychain or a password manager's CLI at that point.
- cmdkey /generic:myagentkey /user:api /pass stores a secret tied to your Windows logon.
- Decryption normally only works for the same user on the same machine.
- Retrieval needs an app or script that calls the Credential Manager API, not a plain read-back.
Why Credential Guard is not the tool for this job
Credential Guard uses virtualization-based security to isolate NTLM password hashes, Kerberos ticket-granting tickets, and credentials that applications store as domain credentials, so that even malware running as an administrator cannot extract them. That is a genuinely strong protection, and it is why ransomware and lateral-movement attacks that rely on 'pass the hash' get blocked on a machine where it is enabled.
It is also the wrong tool for an AI agent's API key. Credential Guard requires Windows Enterprise or Education (Windows Pro is not supported), and it is built around domain-joined machines. Microsoft's own compatibility notes say plainly that the credentials protected by Kerberos and NTLM under Credential Guard are the same ones already in the Active Directory database or the local Security Accounts Manager. A key you generate at an API provider's dashboard and paste into a config file never touches any of that. Enabling Credential Guard changes nothing about where that key lives or who can read it.
If a guide tells you to turn on Credential Guard to protect your OpenAI or Anthropic key, it has confused 'Windows security feature that sounds serious' with 'the actual control that applies here.' Use Credential Manager or a dedicated secrets tool for the key. Save Credential Guard for what it is actually for.
- Credential Guard protects NTLM hashes and Kerberos tickets, not arbitrary application secrets.
- It requires Windows Enterprise or Education and is built around domain-joined machines.
- Turning it on does not move, encrypt, or restrict access to your API key in any way.
What still goes wrong: environment variables and the registry
The default move on Windows is setx MY_KEY "value", which sets a persistent user environment variable. That value is stored in plain text in the registry, under HKEY_CURRENT_USER\Environment, readable by any process running as your user account, including a coding agent that decides to print its environment while debugging something unrelated.
A .env file loaded by a script has the same problem as on any other platform: it is a plain text file an agent can open because it opens files as you. An AI coding agent running on Windows, whether that is Claude Code, Codex CLI, or something else, reads with your permissions and nothing stops it from reading an unprotected file or variable.
This is the gap Credential Manager actually closes. The key moves from something any process can read silently, to something a process has to actively request through an API call, which at minimum means a script you wrote on purpose asked for it.
- setx writes a plain text value to the registry. It is not protected by anything.
- A .env file on Windows is exactly as readable by an agent as one on macOS or Linux.
- Moving a key behind an API call is a small amount of friction with a real payoff.
A practical setup for a Windows AI coding agent
Start by finding what is already exposed. Search your project folders and your shell profile (PowerShell's $PROFILE, or a .bashrc under WSL) for anything that looks like a key, token, or password in plain text. Anything you find there should be treated as already leaked, because a coding agent session may have already read it.
For a single developer on one machine, Credential Manager is enough: store each key as a generic credential, and write a small script or use the CredentialManager PowerShell module to pull it into the one command that needs it. For a team, or for keys that need to work the same way across macOS, Windows, and Linux, a cross-platform CLI vault such as the 1Password CLI is a better fit. Its op run command loads secrets and runs your command in a subprocess with the values available only as environment variables for that process, never written to a file.
Either way, the goal is the same: the key exists in memory for the length of one command, not in a file that sits on disk for months.
- Grep your project and shell profile for plaintext keys, tokens, and passwords first.
- Solo machine: a generic Credential Manager entry, read by a small script.
- Team or cross-platform: a CLI vault's run command, injecting values per process.
- Rotate anything that was ever in a plaintext file or a pushed commit.
What this looks like with no internet connection
DPAPI and Credential Manager are entirely local. Encryption and decryption happen on your machine using your logon credentials, with no network call involved, so this setup keeps working exactly the same with Wi-Fi off. That matters if you are weighing it against a cloud secrets manager, which typically needs a live connection to fetch a value.
A CLI vault like the 1Password CLI is different here: unlocking the vault and syncing new items needs connectivity, though a session that has already authenticated can often still inject previously cached secrets for a short window. If working offline is a hard requirement, Credential Manager or a fully self-hosted, offline password manager is the safer default, not a cloud-synced one.
- Credential Manager and DPAPI need no network connection to encrypt or decrypt.
- A cloud-synced CLI vault generally needs connectivity to unlock or fetch new secrets.
- Pick the local option if your workflow genuinely has no internet access.
Where Forkbench fits, and where it does not
Forkbench is a Mac app that runs coding agents in real terminals and keeps secrets in the macOS Keychain, letting a command use a key by name without the value ever reaching the prompt or the transcript. Windows and Linux support is in development, with no release date yet, so none of that applies on a Windows machine today.
What carries over is the principle, not the product: keep the key out of any file the agent can simply open, and hand it to a process only when that process needs it. On Windows right now, that means Credential Manager for a solo setup or a CLI vault for a team, exactly as described above. If you later move the same workflow to a Mac, the same keys can go into Forkbench's Vault instead.
- Forkbench's Vault is macOS only today. Windows and Linux are in development, no date set.
- The underlying rule is the same on every platform: never a file, always injected per command.
- Claude Code itself stores its own Windows login token in a plain JSON file protected only by your user account's file permissions, not DPAPI, which shows even the agents don't all use the strongest local option by default.
Related: How Forkbench handles your data, Forkbench vs 1Password for AI agents, Why a desktop AI setup needs two separate controls, Enforcing permissions for a local AI agent
Frequently asked
Does Windows have a built-in secrets vault like the macOS Keychain?
Yes. Credential Manager is the Windows equivalent, and the Data Protection API underneath it does the encryption, tied to your Windows logon. It is not AI-specific, but it works for an agent's API key the same way it works for a saved website password.
Does Windows Defender Credential Guard protect my OpenAI or Anthropic API key?
No. Credential Guard isolates NTLM hashes and Kerberos tickets used for domain sign-in. It requires Windows Enterprise or Education and has nothing to do with an API key you generate yourself and store in a file or environment variable.
Can I read a secret back out of Credential Manager from a script?
Not with cmdkey alone, which can create and delete entries but not print the password. Use PowerShell's CredentialManager module, or call the Windows Credential Manager API directly, to retrieve the value in a script.
Does protecting keys this way work without an internet connection?
Credential Manager and DPAPI are fully local and work with no network connection at all. A cloud-synced CLI vault generally needs connectivity to unlock or fetch new secrets, so it is the weaker choice for a fully offline setup.
Can I run Forkbench on Windows to manage these keys?
Not yet. Forkbench is a macOS app today. Windows and Linux support is in development with no announced date, so on Windows you should use Credential Manager or a cross-platform CLI vault directly.