Your terminal remembers the secrets you type into it

Written November 20, 2026. Claude Code updates almost daily, so commands may change.

Your terminal keeps a diary. Every command you type gets saved to a history file, which is how pressing the up arrow brings back the command you ran yesterday. That’s handy right up until one of those commands had an API key in it. An API key is the password a program uses to talk to a service, and once it’s in a command, it’s sitting in a plain text file in your home folder. Maybe for years.

This came up because of a small Claude Code update on November 17. It added a way to connect Claude Code to another tool without ever typing that tool’s key into a command. It’s a minor feature, but the habit behind it applies to pretty much everything you do in a terminal, AI or not.

So this post covers where the diary lives, the new Claude Code way of adding a tool, the one-space trick that keeps a command out of your history, and what to do if a key has already leaked.

Your terminal keeps a diary

The program you type into is called a shell. On Linux it’s usually bash, and on a Mac it’s zsh. Both save what you type to a file, ~/.bash_history or ~/.zsh_history, so you can search and repeat old commands.

Picture writing your bank PIN on a sticky note, using it once, then dropping the note in a drawer with every other note you’ve ever written. Nobody’s stolen it. But it’s there, and anyone who opens the drawer finds it. Same goes for anything that copies your home folder, like a backup, a synced dotfiles repo or a laptop you hand on.

AI coding agents add a new reader to the drawer. They can read your terminal output and your files when you ask them to help. One developer wrote on DEV Community about debugging with Claude Code and later finding a GitHub token from an earlier test sitting in their shell history. They swapped the token for a new one and built a small tool to hide secrets in terminal output.

What changed in Claude Code

Claude Code can plug into other tools through MCP, the Model Context Protocol. It’s a standard way to give an AI agent a connector, say to GitHub or a database. Many of those connectors need a key.

Until now, Claude Code’s MCP docs showed the key going straight into the command, like this:

claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer YOUR_GITHUB_PAT"

That works, and the key goes straight into your diary. Version 2.1.327, according to the changelog, “Added claude mcp add-json <name> - to read the server’s JSON from stdin, so tokens can stay off the command line”. Stdin (“standard input”) just means the command reads text you feed it, here from a file, instead of you typing everything on one line. The dash at the end is what tells it to do that.

There were already two other ways to keep keys out of commands. For connectors that sign in with OAuth (the “log in with GitHub” style of sign-in), the --client-secret option asks for the secret with the typing hidden. And a shared .mcp.json file can point at a key by name, like ${API_KEY}, instead of containing it.

Adding an MCP server without typing the key

Here’s the new way, step by step. One thing first. The changelog says it’s “not available inside a Claude Code session”, so run these in an ordinary terminal, not by asking Claude to do it. And don’t paste your key into the chat either, because Claude Code keeps conversations as files on your computer too.

Step 1: Put the settings in a file

Open a text editor, for example nano server.json, and paste the connector’s settings with your real key:

{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer YOUR_GITHUB_PAT"}}

Typing it into an editor is the point. The editor doesn’t write to your shell history.

Step 2: Feed the file to Claude Code

cat server.json | claude mcp add-json github -

The command line now only says “read server.json”. The key itself never appears in it.

Step 3: Delete the file

rm server.json

Otherwise you’ve moved the sticky note from one drawer to another. Never leave a file like this inside a project folder that goes to GitHub.

Step 4: Check it worked

Start Claude Code and type /mcp to see whether the GitHub connector is listed and connected.

One trap here. Typing echo '{"...your key..."}' | claude mcp add-json github - looks similar but defeats the whole thing, because the key is right there in the command you typed. It has to come from a file or another program.

The one-space trick

For everything outside Claude Code, there’s an older trick. In bash and zsh you can tell the shell to skip any command that starts with a space. Then export API_KEY=abc123 (note the space at the front) runs but isn’t saved.

It isn’t always switched on. In bash, the setting is called HISTCONTROL. Check it with:

echo $HISTCONTROL

If it says ignorespace or ignoreboth, you’re covered. On Debian, the default settings file already turns it on. If it’s empty, add HISTCONTROL=ignoreboth to your ~/.bashrc.

Macs use zsh, which has its own switch. Run setopt | grep -i histignorespace, and if nothing comes back, add setopt HIST_IGNORE_SPACE to your ~/.zshrc. The zsh manual notes the line hangs around in memory until you type the next command, so pressing the up arrow straight away will still show it.

The trick only keeps the command out of the history file. The key still shows on your screen and in anything that records the session. So it’s a seatbelt, not a vault. Reading secrets from a file, as Claude Code now allows, is the better habit wherever a tool supports it.

[Host: your take. Should tools refuse to take secrets on the command line at all?]

If a key has already leaked

Search your diary first. This works for bash and zsh:

grep -iE "key|token|secret|password" ~/.bash_history ~/.zsh_history

It prints any matching lines, which means it prints the secrets too, so don’t run it while screen-sharing. An error about a missing file just means you use the other shell.

If you find a real key, the instinct is to delete the line. Do that, but do it second. GitHub’s advice for leaked credentials is to “rotate the affected credential immediately”. Rotating means making a new key in the service’s settings and cancelling the old one. GitHub adds that scrubbing the secret from history is “time-intensive and often unnecessary if you’ve already revoked the credential.” Once the old key is cancelled, it doesn’t matter who finds the note.

The rest of this week’s Claude Code changes

Versions 2.1.326 (November 16) and 2.1.327 (November 17) were mostly fixes, but a few other changes are worth knowing about, according to the changelog.

Adding a folder Claude Code hasn’t been told to trust, with --add-dir or /add-dir, now shows the trust prompt first. Version 2.1.329 followed up by having that prompt say where a folder’s hooks (scripts that run automatically) are set up. /install-github-app now asks before it changes a repository. Code Mode can now run while agent teams are switched on.

The one that changes behaviour is for people on a company plan. If your organisation’s policy hasn’t loaded yet, sessions with no mode set now start in auto mode rather than Manual mode. Auto mode lets Claude do more without asking. Once your company’s settings load, their chosen default takes over. If you look after Claude Code for a team, it’s worth reading that entry yourself.

What to watch out for

This change keeps the key out of your history, not off your computer. Claude Code still has to store it somewhere to connect, in its own settings. So keep your home folder backups private, and don’t sync Claude Code’s settings files to a public repo.

We haven’t run the four steps ourselves, because add-json won’t run inside a Claude Code session and this studio runs on one. They follow the docs and the command’s built-in help, but try them with a test connector first if you’re nervous.

And none of this means anything was broken before. It’s a small convenience, and the old commands still work. They just leave a note in the drawer.

After After Dark To Try

  1. Run the grep above on your own history. If anything real turns up, make a new key and cancel the old one before you tidy the file.
  2. Check echo $HISTCONTROL (bash) or setopt | grep -i histignorespace (zsh), and switch the one-space trick on if it’s off.
  3. Next time you add an MCP server to Claude Code, use the file-and-dash method, then delete the file.

Sources

Official (primary sources)

News and explainers

Leave a Reply

Your email address will not be published. Required fields are marked *