<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: I4C Studio</title>
    <description>The latest articles on DEV Community by I4C Studio (i4cstudio).</description>
    <link>https://dev.to/i4cstudio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F15547%2F7f84ddb2-b975-4c64-992c-ec9c193c647d.png</url>
      <title>DEV Community: I4C Studio</title>
      <link>https://dev.to/i4cstudio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/i4cstudio"/>
    <language>en</language>
    <item>
      <title>Your coding agent can read .env. Here's where the API keys should live instead.</title>
      <dc:creator>I4C Studio</dc:creator>
      <pubDate>Sat, 24 Oct 2026 03:00:50 +0000</pubDate>
      <link>https://dev.to/i4cstudio/your-coding-agent-can-read-env-heres-where-the-api-keys-should-live-instead-58m5</link>
      <guid>https://dev.to/i4cstudio/your-coding-agent-can-read-env-heres-where-the-api-keys-should-live-instead-58m5</guid>
      <description>&lt;p&gt;I gave Claude Code shell access to a side project last spring and watched it debug a failing OpenAI call the way any of us would: it ran &lt;code&gt;cat .env&lt;/code&gt;. The key was now in the conversation, in the provider's logs, and in the editor's session history on disk. Nothing malicious happened. That is exactly the problem: nothing has to go wrong for a plaintext secret to travel once an agent can read files and run commands.&lt;/p&gt;

&lt;p&gt;I ended up building a small open-source tool to fix this for myself. This post is mostly about the &lt;em&gt;problem&lt;/em&gt; and the options, because the tool only makes sense once you agree on what is broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why &lt;code&gt;.env&lt;/code&gt; stopped being fine
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;.env&lt;/code&gt; file was a reasonable compromise when the only reader was your own process. It is plaintext, but it is gitignored and nothing else looks at it.&lt;/p&gt;

&lt;p&gt;Agents break that assumption in four boring ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;They read it into the prompt.&lt;/strong&gt; Debugging a 401? The agent opens the file. Now the value is in the transcript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They commit it.&lt;/strong&gt; &lt;code&gt;git add -A&lt;/code&gt; after editing &lt;code&gt;.gitignore&lt;/code&gt;, or building &lt;code&gt;.env.example&lt;/code&gt; by copying the real file without blanking values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It shows up in tool output.&lt;/strong&gt; &lt;code&gt;printenv&lt;/code&gt;, a test that prints its config, a debug log with request headers. Stdout goes back to the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It lands in a bug report.&lt;/strong&gt; Agents draft great GitHub issues. Stack traces with &lt;code&gt;Authorization&lt;/code&gt; headers included.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;export OPENAI_API_KEY=...&lt;/code&gt; in &lt;code&gt;.zshrc&lt;/code&gt; is worse, not better. Every process you start inherits it, including the agent and everything it spawns. You replaced a file the agent &lt;em&gt;might&lt;/em&gt; read with an environment it &lt;em&gt;definitely&lt;/em&gt; has.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the OS keychain actually gives you
&lt;/h2&gt;

&lt;p&gt;Every desktop OS ships an encrypted credential store, and each one solves a different problem than a file does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;macOS Keychain&lt;/strong&gt; encrypts items with a key derived from your login password. Each item has an access control list, and another app asking for it triggers a prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windows Credential Manager&lt;/strong&gt; uses DPAPI, tied to your Windows account. A copy of the disk without your credentials cannot decrypt it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linux Secret Service&lt;/strong&gt; (GNOME Keyring, KDE's ksecretservice, KeePassXC) stores an encrypted collection that unlocks with your login via PAM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Be honest about the limit: none of this stops a process &lt;em&gt;running as you&lt;/em&gt; from asking for a value. What it stops is every accidental path above. Nothing to &lt;code&gt;cat&lt;/code&gt;, nothing to commit, nothing in &lt;code&gt;printenv&lt;/code&gt;. The plaintext exists only in the memory of the process that asked.&lt;/p&gt;

&lt;h2&gt;
  
  
  The options, without the marketing
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Encrypted at rest&lt;/th&gt;
&lt;th&gt;Visible to an agent with a shell&lt;/th&gt;
&lt;th&gt;Good for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.env&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;cat .env&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Throwaway prototypes, test keys&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shell profile export&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;printenv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Nothing real&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;direnv&lt;/td&gt;
&lt;td&gt;No (&lt;code&gt;.envrc&lt;/code&gt; is plaintext)&lt;/td&gt;
&lt;td&gt;Yes, once you &lt;code&gt;cd&lt;/code&gt; in&lt;/td&gt;
&lt;td&gt;Per-project config, not secrets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1Password / Bitwarden CLI&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Only via &lt;code&gt;op read&lt;/code&gt; after sign-in&lt;/td&gt;
&lt;td&gt;Teams already on the vault&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloud secret manager&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Only via SDK with cloud creds&lt;/td&gt;
&lt;td&gt;Production runtime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OS keychain via a CLI&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Only via an explicit, gated call&lt;/td&gt;
&lt;td&gt;Dev machines running agents&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;direnv gets recommended a lot here and it is a great tool for the wrong job. Its exports become ambient in every process started from that directory, which is the property you are trying to remove.&lt;/p&gt;

&lt;p&gt;Password-manager CLIs are a fine answer if your team already runs one. Cloud managers are the right home for production secrets and the wrong tool for the key your editor needs on a laptop.&lt;/p&gt;

&lt;p&gt;The keychain sits in the middle: local, encrypted, already installed, no account. What it lacks is one interface across three operating systems and any concept of an agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that matters: how the value reaches the agent
&lt;/h2&gt;

&lt;p&gt;This is the design decision I got wrong first. Storage is the easy half. The real question is: &lt;strong&gt;which tool call does the agent make, and does the value pass through the model?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With q-ring wired in as an MCP server, the agent gets tools instead of a file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;exec_with_secrets&lt;/code&gt; runs a command with the secret injected into the child's environment, captures stdout/stderr, &lt;strong&gt;redacts any known secret value from the output&lt;/strong&gt;, and returns the exit code plus scrubbed logs. The model sees &lt;code&gt;Exit code: 0&lt;/code&gt; and the migration output, never the connection string. One honest limit: the scrubber matches verbatim values only. A key the child has base64-encoded, hex-dumped or printed in part passes through; widening it to encoded forms and 16-character slices is tracked in &lt;a href="https://github.com/I4cTime/q-ring/issues/121" rel="noopener noreferrer"&gt;q-ring #121&lt;/a&gt; and &lt;a href="https://github.com/I4cTime/q-ring/issues/122" rel="noopener noreferrer"&gt;#122&lt;/a&gt;. The default restricted profile also refuses to run &lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;python&lt;/code&gt;, &lt;code&gt;sh&lt;/code&gt; and other binaries that could forward the environment somewhere else.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;has_secret&lt;/code&gt;, &lt;code&gt;inspect_secret&lt;/code&gt; and &lt;code&gt;list_secrets&lt;/code&gt; answer "does it exist" and "when does it expire" with metadata only.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;get_secret&lt;/code&gt; does return the value, because sometimes the agent genuinely needs it. But it is a deliberate call, it goes through key-level policy first (deny lists, or &lt;code&gt;--requires-approval&lt;/code&gt; keys that wait for a human &lt;code&gt;qring approve KEY --for 900&lt;/code&gt;), and every read lands in a hash-chained audit log stamped with the client name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The honest limit again: once &lt;code&gt;get_secret&lt;/code&gt; has handed a value to a client that also has a network tool, no local secrets manager can take it back. So production keys get denied to &lt;code&gt;get_secret&lt;/code&gt; and exposed only through &lt;code&gt;exec_with_secrets&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five minutes to switch
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add &lt;span class="nt"&gt;-g&lt;/span&gt; @i4ctime/q-ring     &lt;span class="c"&gt;# or brew install i4ctime/tap/qring&lt;/span&gt;
qring doctor                    &lt;span class="c"&gt;# confirms the keychain is reachable&lt;/span&gt;
qring &lt;span class="nb"&gt;set &lt;/span&gt;OPENAI_API_KEY        &lt;span class="c"&gt;# prompts on stderr, never echoes, never in shell history&lt;/span&gt;
qring import .env &lt;span class="nt"&gt;--skip-existing&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; .env
qring &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; pnpm &lt;span class="nb"&gt;test&lt;/span&gt;         &lt;span class="c"&gt;# injects into the child, redacts output&lt;/span&gt;
qring setup claude              &lt;span class="c"&gt;# or: cursor, kiro; writes the MCP config&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then give keys a lifetime (&lt;code&gt;--ttl&lt;/code&gt;), check &lt;code&gt;qring audit --key OPENAI_API_KEY&lt;/code&gt; when something feels off, and &lt;code&gt;qring validate KEY&lt;/code&gt; before you spend an hour debugging a key that was rotated last week.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it does not fit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Headless Linux / SSH&lt;/strong&gt; has no keyring daemon. You can wrap commands in &lt;code&gt;dbus-run-session&lt;/code&gt; with &lt;code&gt;gnome-keyring-daemon&lt;/code&gt;, or opt into an encrypted file backend (&lt;code&gt;QRING_BACKEND=file&lt;/code&gt;, AES-256-GCM, never activates on its own).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI&lt;/strong&gt; should use the CI system's own secret store. q-ring is useful there only for &lt;code&gt;qring ci:validate&lt;/code&gt;, which checks declared secrets are present and live.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The point
&lt;/h2&gt;

&lt;p&gt;The threat is not a clever attacker. It is a helpful assistant doing exactly what you asked, with a filesystem full of plaintext. Move the plaintext somewhere that requires an explicit, logged call, and route the common case through a path where the model never sees the value at all.&lt;/p&gt;

&lt;p&gt;q-ring is AGPL-3.0, no account, no cloud, no telemetry. Full write-up with the Linux/Windows specifics is in the &lt;a href="https://qring.i4c.studio/guides/where-to-store-api-keys-for-ai-coding-agents" rel="noopener noreferrer"&gt;guide on the site&lt;/a&gt;, and the &lt;a href="https://qring.i4c.studio/docs/mcp" rel="noopener noreferrer"&gt;MCP setup docs&lt;/a&gt; cover Cursor, Kiro, Claude Code and VS Code. Source is on &lt;a href="https://github.com/I4cTime/q-ring" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. If you think the threat model is wrong, I would genuinely like to hear where.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with help from an AI assistant and checked against the q-ring source and docs by me.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>ai</category>
      <category>devtools</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
