My MCP JWT Token Was in Plain Sight in the Claude Code Chat

While I was rewriting a WordPress draft, I happened to glance at the screen and saw my JWT token (the credential used to log in to WordPress) displayed right there in the chat.

Wait… what… ( ゚д゚)

When I hurriedly checked, I found I hadn’t handled it properly. I’m sure some of you are thinking, “I also put API keys straight into files,” or “Can the AI see them?”, so I looked into what happened this time and how far you can protect against it.

Sponsored links

What happened

Tracing the flow, it went like this:

  • While rewriting a WordPress post, Claude (Claude Code) read ~/.mcp.json (the MCP settings file)
  • The contents of the file, JWT token included, went into the conversation context as is
  • The session got long, and context compaction (the feature that summarizes a conversation when it gets long) ran
  • When the summary was generated, the JWT token value was written into the summary as is
  • The next session started with the token in plain sight from the very beginning

I thought I had written a rule saying, “Don’t display it,” but I never imagined the token would leak through a different route: the summary. That was a blind spot. By the way, this “context compaction” runs automatically in long chats.

I used to think it was a quietly helpful feature, but lately I think that when a chat gets long, it’s better to start a new chat to save tokens. I set things up so conversation logs are automatically saved in Obsidian, acting as the chat’s memory, and I think it’s better to open a new chat after talking for a while.

And you wouldn’t expect that, when using Claude through the VS Code extension, the compaction would become the leak route, right?

I tested whether restricting file permissions would protect it

I tried the fixes that came to mind, one by one.

“This should protect it…” I said, talking it over with the AI.

Test ①: if I restrict the file’s permissions to just me, can it no longer be read?

Using the file permission command on Unix-like operating systems, I changed the settings file so that only its owner could read and write it. I thought that would put my mind at ease, but…

Result: it was read. Claude runs as me (the user) after all, so it can read every file I can read. Thinking about it, that’s obvious, but restricting file permissions only protects against other users. It meant nothing against an AI I’m running myself.

Test ②: if I store it in the macOS Keychain, can it no longer be read?

Using the standard macOS command for managing the Keychain, I registered the token as a Keychain item. I thought this would surely work.

I tried this too, and the result was the same: it could be read. Items saved this way have no ACL (access control list), so they can be accessed without fingerprint authentication. “Not again…” I felt quietly deflated.

Test ③: what about a Keychain item that requires fingerprint authentication?

This one finally couldn’t be read. However, a dialog asking for fingerprint authentication appears on the screen, so Claude can’t operate automatically anymore either.

In other words, it’s a trade-off: the more you raise security, the more you lose the convenience of automatic posting itself. The more you protect it, the more the “leave it to AI” part you wanted disappears. Quite an ironic result.

I ran into a fundamental dilemma

Put in order, the structure looked like this:

  • Maximum security (with fingerprint authentication) → Claude can’t read it = no automatic posting either
  • Automation first (a file, or a Keychain item without authentication) → Claude can read it = it gets processed on Anthropic’s servers

What made it even trickier is that even if you write a rule saying “don’t show it in the conversation,” the moment Claude reads the file, it has already been processed on Anthropic’s servers. “Not visible on screen” and “not passed to the server” are completely different things. At first, I mixed these up. I had assumed that as long as it wasn’t displayed, it was safe.

Claude casually slipped up too

This was the least funny punchline: while I was asking for advice on what to do, Claude said this to me:

“Then let’s update the JWT key. Please paste the new token here.”

…Wait, if I paste it, it ends up displayed in the chat anyway, right? (;´Д`A

I was seriously asking for advice about managing keys safely, and it casually tried to get me to paste the token into the chat. It was an indescribable experience: the AI itself proved, by slipping up, the very point that automation’s convenience and security contradict each other.

The answer I settled on was to edit the json file directly in an editor like VS Code and never show it to Claude at all, and to set things up so the json file wouldn’t be read either.

The reality that doesn’t change even if you do every fix

FixEffect
Reissue the JWT keyOnly disables the old key that leaked. The new key ends up in the same situation
Restrict file permissionsOnly protects against other users. Meaningless against Claude
Write a ruleOnly means “don’t display it on screen.” Processing on Anthropic’s servers doesn’t change
Don’t print the value with PythonSame as above

Even if you do all of them, the fact that the key is processed on Anthropic’s servers doesn’t change.

Best practices for now (what I found out)

  • 1Password CLI: injects the value at runtime after fingerprint authentication. Apparently the value doesn’t stay in a file and doesn’t go into Claude’s context either d( ̄  ̄)
  • permissions.deny: write a read-deny setting in the settings file so Claude can’t read the file in the first place (the effect on automatic posting needs checking)
  • envFile support: even if you put it in an env file in the future, it still sits in Claude’s files, so I wonder if the best way is to keep keys in the password storage of your local Mac or Windows credentials. There’s still room to think about this.

The fundamental conclusion

After all the research and experiments, where I ended up was this: “leaving automation to Claude” = you have no choice but to start from the premise of “trusting Anthropic to some extent.”

This is essentially the same as passing secrets to GitHub Actions or passing API keys to AWS Lambda. As long as it’s processed on someone’s server, whether you trust that service becomes the final deciding factor. This time I realized again that using automation conveniently comes down to exactly that.

The practical compromise I settled on

  • Reissued the JWT token (edited directly in VS Code, never shown to Claude)
  • Also restricted the file permissions, more or less as a bonus
  • Wrote a rule in my WordPress operations manual: “don’t display the JWT in the conversation”
  • Decided to trust Anthropic’s privacy policy and use it

There was no perfect solution. But I think using it while understanding “what’s happening and where the limits are” is completely different from using it without knowing, so I hope this helps fellow learners who also leave automation to AI. If you use Claude or MCP, take a look at your own settings files once.

Oh, by the way, above I wrote, “I wonder if the best way is to keep keys in the local Mac’s credentials,” and after that I actually moved the keys into the Mac’s Keychain and set things up so Claude never sees them. Here’s the follow-up ♪( ´▽`)

Claude Code Security: I Moved Every Key to the macOS Keychain

☕ Enjoyed this post?

I'm a Japanese blogger who spent 8 years relearning English from scratch.
If this post helped you, a coffee would mean a lot — thank you for reading!

Leave a Reply

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

ABOUT US
Suitman
An office worker in Japan who has worked in three fields: education, manufacturing and sales. I started learning English at 35 and, after 8 years of keeping at it, passed Eiken Grade Pre-1. VERSANT score: 59. I write about work tips, Excel, AI, English and cameras, all based on my own experience. ▶ More about me