Why not use .env to store token for .mcp.json?
During today's live demo of the shared MCP config and ${VARIABLE} expansion, asked a great question:
Why set the token with "export ONBOARDING_TOKEN=fake-my-key-1234" in the terminal? Why not store it in an .env file?
Short answer: you can keep it in a .env file, but you have to load it into your terminal first. Claude Code doesn't load .env by itself to fill in ${ONBOARDING_TOKEN}.
How to do it (Mac or Linux terminal):
1. In your project folder, add this line to a file called .env:
ONBOARDING_TOKEN=fake-my-key-1234
2. Load the file into your terminal:
set -a; source .env; set +a
3. Check that it worked. You should see your token:
printenv ONBOARDING_TOKEN
4. In the same terminal tab, start Claude Code:
claude
If Claude Code was already running, exit and start it again.
⚠️ Remember to add .env to your .gitignore, so your token is never committed
Want a live demo of it in our next session? Vote below to let me know!
The replay of the live session will be published on Friday. If the .mcp.json is still confusing for you, watch it again!
Yes I want to see it live!
No it's ok I got it
0 votes
0
0 comments
Hsin-chih Lee
4
Why not use .env to store token for .mcp.json?
The CCAF Success Bootcamp
skool.com/claude-certified
A community for non-technical professionals to build Credibility with AI through the CCAF credential. Guarantee to pass on your 1st try + CPN option.
Leaderboard (30-day)
Powered by