<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Environment Variables on Dev TLDRLSS</title>
        <link>https://dev.tldrlss.com/en/tags/environment-variables/</link>
        <description>Recent content in Environment Variables on Dev TLDRLSS</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Fri, 07 Aug 2026 18:31:00 +0800</lastBuildDate><atom:link href="https://dev.tldrlss.com/en/tags/environment-variables/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Why does a deleted .zshrc environment variable still take effect? Why doesn&#39;t source ~/.zshrc clear old variables? Why does reopening terminal windows keep environment variables? How to completely clear environment variables in IDE built-in terminals and Terminal apps?</title>
        <link>https://dev.tldrlss.com/en/article/2026/08/zshrc-env-clear-mac-terminal-environment-variables/</link>
        <pubDate>Fri, 07 Aug 2026 18:31:00 +0800</pubDate>
        
        <guid>https://dev.tldrlss.com/en/article/2026/08/zshrc-env-clear-mac-terminal-environment-variables/</guid>
        <description>&lt;img src="https://dev.tldrlss.com/global-assets/images/scenario/developer-pitfall-1.jpg" alt="Featured image of post Why does a deleted .zshrc environment variable still take effect? Why doesn&#39;t source ~/.zshrc clear old variables? Why does reopening terminal windows keep environment variables? How to completely clear environment variables in IDE built-in terminals and Terminal apps?" /&gt;&lt;p&gt;Even though you have already deleted an &lt;code&gt;environment variable&lt;/code&gt; (such as &lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt;) from &lt;code&gt;~/.zshrc&lt;/code&gt;, when you check the terminal, it is surprisingly still there!&lt;/p&gt;
&lt;p&gt;Even re-running &lt;code&gt;source ~/.zshrc&lt;/code&gt; is completely useless?&lt;/p&gt;
&lt;h2 id=&#34;how-to-check-if-an-environment-variable-exists-and-which-config-file-wrote-it&#34;&gt;How to Check If an Environment Variable Exists and Which Config File Wrote It?
&lt;/h2&gt;&lt;p&gt;Before cleaning up, you first need to confirm whether the variable still remains in current memory, and which configuration file is automatically loading it.&lt;/p&gt;
&lt;h3 id=&#34;1-check-memory-variables&#34;&gt;1. Check Memory Variables
&lt;/h3&gt;&lt;p&gt;Check if the &lt;code&gt;environment variable&lt;/code&gt; still remains in the current &lt;code&gt;Terminal&lt;/code&gt; memory&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;env &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep -i anthropic
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;2-search-configuration-file-sources&#34;&gt;2. Search Configuration File Sources
&lt;/h3&gt;&lt;p&gt;Comprehensively search &lt;code&gt;Zsh&lt;/code&gt;, &lt;code&gt;Bash&lt;/code&gt;, and system-level configuration files to find which file wrote the variable&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;grep -rn &lt;span class=&#34;s2&#34;&gt;&amp;#34;ANTHROPIC_BASE_URL&amp;#34;&lt;/span&gt; ~/.zshrc ~/.zprofile ~/.zshenv ~/.zlogin ~/.bashrc ~/.bash_profile ~/.profile /etc/zshenv /etc/zprofile /etc/profile /etc/environment 2&amp;gt;/dev/null
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;!--adsense--&gt;
&lt;h2 id=&#34;why-do-old-environment-variables-remain-after-modifying-zshrc&#34;&gt;Why Do Old Environment Variables Remain After Modifying .zshrc?
&lt;/h2&gt;&lt;p&gt;Actually, when you open a terminal, &lt;code&gt;environment variables&lt;/code&gt; are already loaded into the &amp;ldquo;memory&amp;rdquo; of that connection.&lt;/p&gt;
&lt;p&gt;Even if you modify the file or re-execute &lt;code&gt;source ~/.zshrc&lt;/code&gt;, this only &amp;ldquo;reloads&amp;rdquo; the content in the config file and does not automatically purge old variables existing in memory.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;source&lt;/code&gt; &lt;strong&gt;command only overwrites or adds variables, and will not &amp;ldquo;delete&amp;rdquo; variables for you&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;At this point, the simplest solutions are as follows:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Cleanup Method&lt;/th&gt;
          &lt;th&gt;Command / Action&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Open New Window&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;Open a brand new terminal tab&lt;/td&gt;
          &lt;td&gt;The new &lt;code&gt;Shell Process&lt;/code&gt; will re-read the latest &lt;code&gt;~/.zshrc&lt;/code&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Manual Clearance&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;unset ANTHROPIC_BASE_URL&lt;/code&gt;&lt;/td&gt;
          &lt;td&gt;Directly delete the specified &lt;code&gt;environment variable&lt;/code&gt; from current memory&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Reset Shell&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;exec zsh -l&lt;/code&gt;&lt;/td&gt;
          &lt;td&gt;Reload the current &lt;code&gt;Shell&lt;/code&gt; memory state&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;reopening-terminal-windows-still-useless-uncover-the-top-3-culprits&#34;&gt;Reopening Terminal Windows Still Useless? Uncover the Top 3 Culprits
&lt;/h2&gt;&lt;p&gt;Why is it that sometimes even after opening a brand new terminal window, old &lt;code&gt;environment variables&lt;/code&gt; still linger around?&lt;/p&gt;
&lt;p&gt;In this case, the problem is no longer in &lt;code&gt;~/.zshrc&lt;/code&gt;, but inherits from the &amp;ldquo;Parent Process&amp;rdquo;!&lt;/p&gt;
&lt;p&gt;When you launch a terminal from a software application, the child process directly copies the parent process environment variable snapshot.&lt;/p&gt;
&lt;p&gt;If you encounter such persistent &lt;code&gt;environment variables&lt;/code&gt;, it is usually due to the following three common reasons:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Type&lt;/th&gt;
          &lt;th&gt;Cause&lt;/th&gt;
          &lt;th&gt;Solution&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;IDE Built-in Terminal&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;VS Code&lt;/code&gt;, &lt;code&gt;Cursor&lt;/code&gt;, or &lt;code&gt;Antigravity&lt;/code&gt; recorded an environment variable snapshot upon startup&lt;/td&gt;
          &lt;td&gt;Press &lt;code&gt;Cmd + Q&lt;/code&gt; to completely quit &lt;code&gt;IDE&lt;/code&gt; and reopen it&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Terminal Software Not Closed&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;Terminal&lt;/code&gt; or &lt;code&gt;iTerm2&lt;/code&gt; on Mac only closed windows (&lt;code&gt;Cmd + W&lt;/code&gt;), main application runs in background&lt;/td&gt;
          &lt;td&gt;Press &lt;code&gt;Cmd + Q&lt;/code&gt; to completely quit &lt;code&gt;Terminal&lt;/code&gt; software&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;tmux&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;tmux&lt;/code&gt; background &lt;code&gt;Server&lt;/code&gt; runs continuously, new tabs keep inheriting settings from launch&lt;/td&gt;
          &lt;td&gt;Run &lt;code&gt;tmux kill-server&lt;/code&gt; to stop background service&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;!--adsense--&gt;
&lt;h2 id=&#34;reopening-software-still-ineffective-check-third-party-tools-and-system-level-settings&#34;&gt;Reopening Software Still Ineffective? Check Third-Party Tools and System-Level Settings
&lt;/h2&gt;&lt;p&gt;If all three tricks above fail and &lt;code&gt;environment variables&lt;/code&gt; stubbornly appear in &lt;code&gt;Terminal&lt;/code&gt;, higher-level system settings or third-party tools may be working behind the scenes.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Higher system permissions or wrapper scripts will restore environment variables automatically upon each launch&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In this case, you can use the following two main detection commands:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Detection Target&lt;/th&gt;
          &lt;th&gt;Command&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;System Global Variables&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;launchctl getenv ANTHROPIC_BASE_URL&lt;/code&gt;&lt;/td&gt;
          &lt;td&gt;Check if third-party proxy tools use &lt;code&gt;launchctl setenv&lt;/code&gt; to set global variables&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Command Wrapper Scripts&lt;/strong&gt;&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;type claude&lt;/code&gt;&lt;/td&gt;
          &lt;td&gt;Check if current command is original executable or wrapped in a &lt;code&gt;wrapper&lt;/code&gt; script with default variables&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;standard-troubleshooting-steps-for-completely-clearing-environment-variables&#34;&gt;Standard Troubleshooting Steps for Completely Clearing Environment Variables
&lt;/h2&gt;&lt;p&gt;Next time you modify or delete &lt;code&gt;environment variables&lt;/code&gt; in &lt;code&gt;~/.zshrc&lt;/code&gt;, remember to first confirm: Does current terminal inherit old &lt;code&gt;Parent Process&lt;/code&gt; settings?&lt;/p&gt;
&lt;p&gt;Follow this troubleshooting sequence to easily find the root cause and resolve the issue:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First execute &lt;code&gt;unset VARIABLE_NAME&lt;/code&gt; or open a brand new terminal window.&lt;/li&gt;
&lt;li&gt;If using &lt;code&gt;IDE&lt;/code&gt; like &lt;code&gt;VS Code&lt;/code&gt; or &lt;code&gt;Cursor&lt;/code&gt;, press &lt;code&gt;Cmd + Q&lt;/code&gt; to completely restart &lt;code&gt;IDE&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If using &lt;code&gt;tmux&lt;/code&gt;, run &lt;code&gt;tmux kill-server&lt;/code&gt; to reset background service.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;launchctl getenv&lt;/code&gt; and &lt;code&gt;type&lt;/code&gt; commands to troubleshoot system levels and wrapper scripts.&lt;/li&gt;
&lt;/ol&gt;
</description>
        </item>
        
    </channel>
</rss>
