Even though you have already deleted an environment variable (such as ANTHROPIC_BASE_URL) from ~/.zshrc, when you check the terminal, it is surprisingly still there!
Even re-running source ~/.zshrc is completely useless?
How to Check If an Environment Variable Exists and Which Config File Wrote It?
Before cleaning up, you first need to confirm whether the variable still remains in current memory, and which configuration file is automatically loading it.
1. Check Memory Variables
Check if the environment variable still remains in the current Terminal memory
env | grep -i anthropic
2. Search Configuration File Sources
Comprehensively search Zsh, Bash, and system-level configuration files to find which file wrote the variable
grep -rn "ANTHROPIC_BASE_URL" ~/.zshrc ~/.zprofile ~/.zshenv ~/.zlogin ~/.bashrc ~/.bash_profile ~/.profile /etc/zshenv /etc/zprofile /etc/profile /etc/environment 2>/dev/null
Why Do Old Environment Variables Remain After Modifying .zshrc?
Actually, when you open a terminal, environment variables are already loaded into the “memory” of that connection.
Even if you modify the file or re-execute source ~/.zshrc, this only “reloads” the content in the config file and does not automatically purge old variables existing in memory.
The
sourcecommand only overwrites or adds variables, and will not “delete” variables for you
At this point, the simplest solutions are as follows:
| Cleanup Method | Command / Action | Description |
|---|---|---|
| Open New Window | Open a brand new terminal tab | The new Shell Process will re-read the latest ~/.zshrc |
| Manual Clearance | unset ANTHROPIC_BASE_URL |
Directly delete the specified environment variable from current memory |
| Reset Shell | exec zsh -l |
Reload the current Shell memory state |
Reopening Terminal Windows Still Useless? Uncover the Top 3 Culprits
Why is it that sometimes even after opening a brand new terminal window, old environment variables still linger around?
In this case, the problem is no longer in ~/.zshrc, but inherits from the “Parent Process”!
When you launch a terminal from a software application, the child process directly copies the parent process environment variable snapshot.
If you encounter such persistent environment variables, it is usually due to the following three common reasons:
| Type | Cause | Solution |
|---|---|---|
| IDE Built-in Terminal | VS Code, Cursor, or Antigravity recorded an environment variable snapshot upon startup |
Press Cmd + Q to completely quit IDE and reopen it |
| Terminal Software Not Closed | Terminal or iTerm2 on Mac only closed windows (Cmd + W), main application runs in background |
Press Cmd + Q to completely quit Terminal software |
| tmux | tmux background Server runs continuously, new tabs keep inheriting settings from launch |
Run tmux kill-server to stop background service |
Reopening Software Still Ineffective? Check Third-Party Tools and System-Level Settings
If all three tricks above fail and environment variables stubbornly appear in Terminal, higher-level system settings or third-party tools may be working behind the scenes.
Higher system permissions or wrapper scripts will restore environment variables automatically upon each launch
In this case, you can use the following two main detection commands:
| Detection Target | Command | Description |
|---|---|---|
| System Global Variables | launchctl getenv ANTHROPIC_BASE_URL |
Check if third-party proxy tools use launchctl setenv to set global variables |
| Command Wrapper Scripts | type claude |
Check if current command is original executable or wrapped in a wrapper script with default variables |
Standard Troubleshooting Steps for Completely Clearing Environment Variables
Next time you modify or delete environment variables in ~/.zshrc, remember to first confirm: Does current terminal inherit old Parent Process settings?
Follow this troubleshooting sequence to easily find the root cause and resolve the issue:
- First execute
unset VARIABLE_NAMEor open a brand new terminal window. - If using
IDElikeVS CodeorCursor, pressCmd + Qto completely restartIDE. - If using
tmux, runtmux kill-serverto reset background service. - Check
launchctl getenvandtypecommands to troubleshoot system levels and wrapper scripts.