<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Guillermo Espina</title>
        <link>https://guillermomtze.com/</link>
        <description>Writing by Guillermo Espina, Forward Deployed Engineer at Google Cloud: GenAI, software engineering and developer tooling.</description>
        <lastBuildDate>Thu, 05 Nov 2026 00:00:00 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>Guillermo Espina</title>
            <url>https://guillermomtze.com/apple-icon.png</url>
            <link>https://guillermomtze.com/</link>
        </image>
        <copyright>© 2026 Guillermo Espina</copyright>
        <atom:link href="https://guillermomtze.com/feed.xml" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[I Replaced My Paid Personal CRM with a Git Repo and Two AI Agents]]></title>
            <link>https://guillermomtze.com/articles/personal-crm-with-ai</link>
            <guid isPermaLink="false">https://guillermomtze.com/articles/personal-crm-with-ai</guid>
            <pubDate>Thu, 05 Nov 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[How I turned 829 messy phone contacts into a personal CRM I actually use: one Markdown note per person, a closeness score, a freshness date, and AI agents that log what happens and nudge me every week.]]></description>
            <content:encoded><![CDATA[



<p>I paid for Dex, a personal CRM. It reminds you to catch up with people, and when something happens in their life (a new job, a move, a baby) you log it, so next time you actually remember.</p>
<p>I logged things maybe once a month. I paid every month. So I cancelled it.</p>
<p>The problem wasn’t the app. It was the friction. I still wanted the result: remember what matters to the people in my life, and get a nudge when I go quiet on someone. So I built my own, and let AI do the boring parts. One day later, 829 messy contacts were 552 clean ones, each with a note, a closeness score and a date for when to reach out next.</p>
<hr>
<h2>The design</h2>

<p>Three rules. My phone owns names and numbers. The history is plain text I own. I’m the one who talks to people. The agents remember and suggest; every message goes out from my phone.</p>
<hr>
<h2>Phase 1: Getting the contacts out</h2>
<p>The first plan was the Google People API, called from a GitHub Action. While setting it up I found my old OAuth client secret in my notes repo, plus a refresh token pasted into a setup guide. Not my best moment.</p>
<p>I pulled them out and changed the plan. My contacts already sync to Contacts.app on my Mac, and one line of AppleScript exports all of them:</p>
<pre><code class="language-applescript">tell application "Contacts" to set vc to vcard of every person
</code></pre>
<p>A small Python script turns that export into notes. <code>launchd</code>, the scheduler built into macOS, runs it every Monday morning. No API, no OAuth, no tokens.</p>
<blockquote>
<p><strong>Pro-Tip:</strong> Before you connect an AI agent to anything, look for the version of the integration that needs no credentials. The safest secret is the one that doesn’t exist.</p>
</blockquote>
<hr>
<h2>Phase 2: One note per person</h2>
<pre><code class="language-markdown">---
name: Sam Rivera
closeness: 3
last_contacted: 2026-10-16
next_contact: 2027-01-14
freshness: fresh
---

# Sam Rivera

## About

Friend of [[Lee Alex|Alex]]. Reach out when I'm in Lisbon.

## Timeline

- **2026-10-16**: Coffee in town. Moving to Zurich in January.
</code></pre>
<p>Sam is made up. The frontmatter drives the reminders. <strong>About</strong> is standing context, and names become Obsidian links, so people link to each other. <strong>Timeline</strong> is what happened, and every dated entry counts as contact.</p>
<hr>
<h2>Phase 3: The triage</h2>
<p>829 contacts, and for most of them I had no idea how close we were. I asked Claude for a small page: every contact, buttons from 0 to 6, and an optional box for context.</p>
<figure><img src="https://guillermomtze.com/_next/static/immutable/media/circles-triage.3hx4lz95j05rb.png" alt="The Circles Triage page: a list of contacts with blurred names, each with level buttons from 1 to 6 plus 0, and an optional context box under each one" width="1520" height="2240"><figcaption>Circles Triage. Names replaced and blurred.</figcaption></figure>
<table>
<thead>
<tr>
<th>Level</th>
<th>Meaning</th>
<th>Reach out every</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Inner circle</td>
<td>2 weeks</td>
</tr>
<tr>
<td>2</td>
<td>Close friend</td>
<td>month</td>
</tr>
<tr>
<td>3</td>
<td>Friend</td>
<td>3 months</td>
</tr>
<tr>
<td>4</td>
<td>Acquaintance</td>
<td>6 months</td>
</tr>
<tr>
<td>5</td>
<td>Keep the number, no follow-up</td>
<td>never</td>
</tr>
<tr>
<td>6</td>
<td>In memory</td>
<td>never</td>
</tr>
<tr>
<td>0</td>
<td>Delete</td>
<td>n/a</td>
</tr>
</tbody>
</table>
<p>The first version stopped at 5. Then I scrolled past a relative who passed away, and past dozens of people I keep “just in case” but would never text out of nowhere. The scale had to fit real life.</p>
<p>The biggest upgrade was the keyboard. Number pad for the level, the cursor jumps into the context box, <code>Tab</code> to the next person. It started to feel like inbox zero.</p>
<p>My notes were messy: “DELETE”, “merge with the other one”, “husband of …”, “Cousin?”. That’s fine. I’d say “apply my circles” and Claude did the clerical work: delete the zeros (from my phone too, after a backup), merge duplicates keeping every number, turn “husband of” into links both ways, keep my question marks. A guess stays a guess.</p>
<p>Some of what I found: four cards for the same person, two cards that were both me, and a contact whose number was 1-800-MY-APPLE. Final count: <strong>552 contacts</strong>, all with a level, and about 180 I actually want to stay in touch with.</p>
<hr>
<h2>Phase 4: Freshness</h2>
<p>The script computes <code>last_contacted</code> (newest Timeline entry), <code>next_contact</code> (last contact plus the rhythm for that level) and <code>freshness</code>:</p>
<table>
<thead>
<tr>
<th>Freshness</th>
<th>Share of the rhythm passed</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>fresh</code></td>
<td>under 75%</td>
</tr>
<tr>
<td><code>due-soon</code></td>
<td>75–100%</td>
</tr>
<tr>
<td><code>due</code></td>
<td>100–200%</td>
</tr>
<tr>
<td><code>cold</code></td>
<td>over 200%</td>
</tr>
</tbody>
</table>
<p>Cold means more than twice as long as I’d like. That’s who I should text this week.</p>
<blockquote>
<p><strong>Pro-Tip:</strong> Don’t let the AI do the arithmetic. Put the rules in a script and have the agent run it after every edit. The agent decides <em>what</em> happened; the script decides <em>what it means</em>.</p>
</blockquote>
<hr>
<h2>Phase 5: Its own repo</h2>
<p>The notes started in my main Obsidian repo, next to my journal. Every agent session cloned all of it to log one coffee. Now contacts have their own private repo, cloned back into the same folder in the vault. Links still work, and the agents see my contacts and nothing else.</p>
<p>One surprise: my vault sits in an iCloud folder. Swapping the folder made iCloud create 474 copies called <code>Something 2.md</code>. All identical. All binned.</p>
<hr>
<h2>Phase 6: The agents</h2>
<p><strong>Claude keeps the notes.</strong> I type “saw Sam, he got the job”. It finds Sam, adds a dated entry, recomputes the dates and pushes.</p>
<p><strong>The CRM bot does the nudging.</strong> Every week it reads the repo, picks who’s due or cold (inner circle first) and pings me with a few names and something worth bringing up.</p>

<p>One <code>AGENTS.md</code> at the root of the repo keeps both of them consistent: the note format, which fields each agent can touch, how to log something, and what to never do, like deleting someone with history without asking me.</p>
<p>These notes are about other people. So the repo is private, there are no credentials anywhere, each agent gets the contacts repo and nothing else, and every message goes out from my phone.</p>
<hr>
<h2>The Takeaway</h2>
<p>The AI was the easy part. What made it work:</p>
<ol>
<li><strong>A boring, open data model.</strong> One Markdown file per person beats any database I’d have to export from later.</li>
<li><strong>Clear ownership.</strong> The phone owns details, I own closeness and context, a script owns the dates.</li>
<li><strong>Least privilege.</strong> A separate repo for a separate job. No secrets to leak.</li>
<li><strong>Make the human part fast.</strong> The number pad did more for this project than any model.</li>
</ol>
<p>Want to try it? Start smaller than me. One folder, one file per person you care about, and the date you last spoke at the top. The agents can come later.</p>]]></content:encoded>
            <author>gmotzespina@icloud.com (Guillermo Espina)</author>
        </item>
        <item>
            <title><![CDATA[How to Debug with AI (Without the Guesswork)]]></title>
            <link>https://guillermomtze.com/articles/tailwind-vercel-build-mystery</link>
            <guid isPermaLink="false">https://guillermomtze.com/articles/tailwind-vercel-build-mystery</guid>
            <pubDate>Sun, 29 Mar 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[A “works on my machine” mystery, turned into a lesson in using AI as a high-level partner: theories, documentation and human-led research.]]></description>
            <content:encoded><![CDATA[



<p>I’ve been building software professionally since 2019. I’ve seen so many ways a build can break, but Vercel still managed to surprise me this week.</p>
<p>Everything looked perfect locally. Even a full production build on my Mac was flawless. But the second it hit the server? Total disaster. No spacing, tiny headers, and code blocks that looked like they’d been stripped of all dignity.</p>
<figure><img src="https://guillermomtze.com/_next/static/immutable/media/local-working.3-y7phed5mi4k.png" alt="Localhost - Working" width="891" height="1189"><figcaption>Local: Everything is perfect</figcaption></figure><figure><img src="https://guillermomtze.com/_next/static/immutable/media/vercel-broken.12cjezlbzr22w.png" alt="Vercel - Broken" width="891" height="1189"><figcaption>Vercel: The disaster</figcaption></figure>
<p>Usually, this is where you might start blindly changing code or begging an AI to “just fix it.” Instead, I used this as an opportunity to pair with the AI differently. Here is the playbook for how we solved a silent Tailwind failure by treating the AI as a colleague, not a magic wand.</p>
<hr>
<h2>1. Don’t code. Write a theory.</h2>
<p>The first thing I told the AI was: <strong>“Do not make any changes yet. Troubleshoot, spot what is happening, and write a theory.”</strong></p>
<p>This is the most important step. If the AI can’t explain <em>why</em> it thinks something is broken, any code it writes is just a guess. We spent the first few interactions just building a document in the <code>articles/</code> folder. We mapped out the symptoms and wrote down exactly why we thought the CSS extraction was failing.</p>
<blockquote>
<p><strong>Staff Engineer Pro-Tip:</strong> When a bug is environment-specific, don’t ask the AI to fix it. Ask it to “Analyze the differences between a permissive Mac environment and a strict Linux environment.” The nodes of failure always live in the delta.</p>
</blockquote>
<p>If you can’t document the theory, you aren’t ready to commit the fix.</p>
<hr>
<h2>2. Human-led research is the multiplier</h2>
<p>AI is great at processing what’s in front of it, but it isn’t always a great detective for obscure, environment-specific bugs.</p>
<p>While the AI was analyzing my config, I went out and did the “manual” work. I dug through GitHub issues, StackOverflow, and Vercel’s knowledge base. I found three specific links from people who had seen similar behavior—specifically issues with ESM interop on Linux and how Next.js handles dynamic imports.</p>
<h3>Our Research Log</h3>
<ul>
<li><strong>Next.js Issue #65388:</strong> Tailwind styles missing in production <a href="https://github.com/vercel/next.js/issues/65388">Link</a></li>
<li><strong>Vercel KB:</strong> Deploying MDX Deck <a href="https://vercel.com/kb/guide/deploying-mdx-deck-with-vercel">Link</a></li>
<li><strong>StackOverflow:</strong> Tailwind styles in production Next.js <a href="https://stackoverflow.com/questions/78190252/tailwind-styles-does-not-work-in-the-production-next-js-and-vercel">Link</a></li>
</ul>
<p>I fed those URLs back to the AI. <strong>“Read these and understand whether something similar is impacting us.”</strong></p>
<p>This changed the game. It shifted the AI’s focus from “maybe your CSS is wrong” to “maybe the Vercel build environment is failing to resolve your external config files.”</p>
<hr>
<h2>3. One fix at a time (The Staff Engineer way)</h2>
<p>Once we had three solid theories, the temptation was to try all three at once. I pushed back: <strong>“Let’s do 1 at a time, starting from the one with the highest likelihood. That way we will know what the problem actually was.”</strong></p>
<p>This is discipline. If you change three things and it starts working, you’ve learned nothing. You haven’t fixed the bug; you’ve just obscured it.</p>
<h3>The Debugging Sprint</h3>
<ul>
<li><strong>Phase 1: Syntax Cleanup</strong> — Fix non-standard <code>@screen</code> in JS ⮕ <em>No change</em> ❌</li>
<li><strong>Phase 2: ESM Interop</strong> — Explicitly handle <code>.default</code> exports ⮕ <em>No change</em> ❌</li>
<li><strong>Phase 3: The Big Guns</strong> — Inline the config and refine content paths ⮕ <strong>FIXED</strong> ✅</li>
</ul>
<h3>The “Smoking Gun”</h3>
<p>Here is the syntax that worked locally but crashed the build on Vercel:</p>
<pre><code class="language-js">// ❌ The "Permissive" Mac syntax
'@screen lg': { ... }

// ✅ The "Production-Safe" syntax
[`@media (min-width: ${theme('screens.lg')})`]: { ... }
</code></pre>
<hr>
<h2>4. Turn the fix into a Playbook</h2>
<p>Once the styles snapped back into place, we didn’t just delete the troubleshooting doc. We turned it into a permanent playbook at the top of the file.</p>
<p>I asked the AI to create a “When to use this” section. Now, if this ever happens again, I don’t have to remember the fix. I have a documented process that tells future-me:</p>

<pre><code class="language-markdown">## 📖 When to use this playbook
Use this if you encounter the following:
- Site looks perfect on localhost but broken on Vercel.
- Classes like .prose appear in HTML but have no CSS rules.
- Using Tailwind plugins that rely on external config files.
</code></pre>
<hr>
<h2>The Takeaway</h2>
<p>The “Mystery of the Missing Styles” wasn’t actually about CSS. It was about how Tailwind’s scanner works in a strict Linux environment versus a permissive Mac environment.</p>
<p>But more importantly, it was about how to work with AI. Don’t let it shotgun changes into your codebase. Make it write theories. Feed it your own research. And move one phase at a time until there’s nowhere for the bug to hide.</p>
<p>That’s how you debug without losing your mind—or your CSS.</p>
<hr>]]></content:encoded>
            <author>gmotzespina@icloud.com (Guillermo Espina)</author>
        </item>
        <item>
            <title><![CDATA[How to Run Claude Code Offline with Local Models (LM Studio + Mac)]]></title>
            <link>https://guillermomtze.com/articles/claude-code-offline-local-models</link>
            <guid isPermaLink="false">https://guillermomtze.com/articles/claude-code-offline-local-models</guid>
            <pubDate>Thu, 26 Mar 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[How I set up Claude Code to run entirely on-device with LM Studio and a local model, so it works on a plane, avoids rate limits and keeps costs under control.]]></description>
            <content:encoded><![CDATA[



<p>I was on a 10-hour flight last month, laptop open, working on a side project. No Wi-Fi. No API calls. And yet Claude Code was running on my machine, helping me refactor code, write tests, and scaffold new features — all powered by a local model through LM Studio.</p>
<p>Here’s how I set it up, and why you might want to.</p>
<hr>
<h2>Two reasons to run Claude Code locally</h2>
<h3>1. You’re on a plane (or anywhere without internet)</h3>
<p>This is the obvious one. You’re flying, you’re on a train, you’re at a café with terrible Wi-Fi. You’ve got 4 hours of uninterrupted focus time and a codebase that needs work. Normally Claude Code is useless without a connection. But with a local model, you get the same agentic workflow — file exploration, code edits, tool calls, patch application — running entirely on your machine.</p>
<h3>2. You want to stop burning through your Claude plan</h3>
<p>This one is less obvious but arguably more practical day-to-day.</p>
<p>If you’re on Claude’s Max plan, you’re essentially limitless — but you’re also paying for it. If you’re on a lower tier (Pro), you’ll eventually hit rate limits, and it always happens at the worst time, right in the middle of a flow state.</p>
<p>You can work around this by using the API directly and adding credits to your account, but if you’re using Claude Code heavily, the costs add up fast and it becomes unsustainable.</p>
<p>A better approach: <strong>use a local model for the smaller tasks and save your Anthropic credits for when you actually need them.</strong> Writing boilerplate, scaffolding components, running simple refactors, adding tests for straightforward functions — a local model handles these fine. When you hit something that genuinely requires deep thinking or complex multi-file reasoning, switch back to Claude’s cloud models.</p>
<p>And here’s the thing that surprised me: <strong>if your project is well-structured with a solid CLAUDE.md and your skills/agents files properly set up, even the local model becomes remarkably capable.</strong> The model doesn’t have to be a genius when your project context is doing half the heavy lifting.</p>
<hr>
<h2>What you’ll need</h2>
<ul>
<li><strong>A computer with enough RAM.</strong> LM Studio runs on Mac, Windows, and Linux — this setup is not Mac-only. That said, <strong>Macs with Apple Silicon have a significant advantage</strong> for running local models. On a PC, your model has to fit in your GPU’s VRAM (typically 8–24GB on consumer cards like the RTX 4090). If it doesn’t fit, it either won’t run or crawls at unusable speeds. On a Mac, the CPU and GPU share the same unified memory pool — your entire RAM is available for the model. That means a MacBook Pro with 128GB can load an 80B parameter model that would require multiple expensive GPUs on a PC. If you’re on Windows/Linux with a high-VRAM GPU, everything in this guide still works — just use GGUF model formats instead of MLX.</li>
<li><strong>At least 32GB of memory</strong> (unified memory on Mac, or VRAM + RAM on PC). At 16GB it’ll technically run with small models, but the experience will be rough.</li>
<li><strong>LM Studio</strong> — download it from <a href="https://lmstudio.ai/">lmstudio.ai</a>.</li>
<li><strong>Claude Code</strong> — install via npm:</li>
</ul>
<pre><code class="language-bash">npm install -g @anthropic-ai/claude-code
</code></pre>
<ul>
<li><strong>A good local model</strong> (see recommendations below).</li>
</ul>
<hr>
<h2>Which model should you use?</h2>
<p>This matters more than you’d think. Claude Code is an <em>agentic</em> tool — it doesn’t just generate code, it explores codebases, sequences tool calls, applies patches, and runs commands. You need a model that’s strong at <strong>tool use and code repair</strong>, not just raw intelligence.</p>
<p>After researching the options, here’s how the main contenders stack up for Claude Code specifically:</p>
<table>
<thead>
<tr>
<th>Criteria</th>
<th>Qwen3-Coder-Next (80B)</th>
<th>GLM-4.7-Flash (30B)</th>
<th>Qwen3.5-35B-A3B</th>
<th>Qwen3-Coder-30B</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Agentic tool use</strong></td>
<td>★★★ Best</td>
<td>★★★ Great</td>
<td>★ Weak</td>
<td>★★ Mid</td>
</tr>
<tr>
<td><strong>Code repair (SWE-bench)</strong></td>
<td>★★★ Sonnet 4.5-class</td>
<td>★★★ 59.2%</td>
<td>★★ Mid</td>
<td>★★ Good</td>
</tr>
<tr>
<td><strong>General reasoning</strong></td>
<td>★★ Strong</td>
<td>★ Weakest</td>
<td>★★★ Best</td>
<td>★★ Mid</td>
</tr>
<tr>
<td><strong>Inference speed</strong></td>
<td>★★ Fast (3B active)</td>
<td>★★★ Fastest</td>
<td>★★★ Fast</td>
<td>★ Slower</td>
</tr>
<tr>
<td><strong>RAM needed (Q4)</strong></td>
<td>~51GB</td>
<td>~17GB</td>
<td>~20GB</td>
<td>~18GB</td>
</tr>
<tr>
<td><strong>Claude Code fit</strong></td>
<td>★★★ Best overall</td>
<td>★★★ Best for its size</td>
<td>★ Worst</td>
<td>★★ Mid</td>
</tr>
</tbody>
</table>
<h3>Which model for your hardware?</h3>
<p>Your available memory determines which tier you’re in — and the difference is significant. On a Mac, this is your unified memory (e.g., 32GB, 64GB, 128GB). On a PC, it’s primarily your GPU VRAM, though with partial offloading to system RAM you can stretch further.</p>
<p><strong>64GB or more → Qwen3-Coder-Next (80B).</strong> This is the best local model for Claude Code, period. It was specifically designed for coding agents and tool use, with SWE-Bench Pro performance roughly on par with Claude Sonnet 4.5. At ~51GB (Q4) it fits comfortably with plenty of headroom for context window and your OS. If you have 128GB, you can run it at higher quantization (6-bit or 8-bit) for even better quality, or push the context length well beyond the default 25K tokens.</p>
<p><strong>32–48GB → GLM-4.7-Flash (30B).</strong> At just ~17GB (Q4) it loads fast, runs fast, and punches way above its weight on agentic tasks — 59.2% on SWE-bench Verified and 79.5% on tau2-Bench for multi-step tool use. It also maintains consistent performance across all difficulty levels, unlike the Qwen models which tend to crater on complex multi-file tasks. This is the sweet spot for most people.</p>
<p><strong>24GB → GLM-4.7-Flash at Q4 is your only real option.</strong> It’ll work, but context length will be tight. Keep your tasks small and focused.</p>
<p><strong>16GB → Not recommended.</strong> You can technically squeeze in a small model, but the experience with Claude Code will be frustrating. Better to use cloud mode.</p>
<h3>A note on model formats: MLX vs GGUF</h3>
<p>When you download a model in LM Studio, you’ll see two format options: <strong>GGUF</strong> and <strong>MLX</strong>.</p>
<p><strong>GGUF</strong> is the universal format — it works on Mac, Windows, and Linux. It’s the safe default if you’re not on Apple Silicon.</p>
<p><strong>MLX</strong> is Apple’s machine learning framework, built specifically for the unified memory architecture of M-series chips. MLX models are typically 20–30% faster than GGUF on the same Mac hardware because they’re optimized for how Apple Silicon accesses memory. The speed gap gets even wider with larger models.</p>
<p><strong>If you’re on a Mac with Apple Silicon, always pick the MLX version.</strong> If you’re on Windows or Linux, go with GGUF. In LM Studio, both show up side by side when you search for a model — just pick the right one for your platform.</p>
<hr>
<h2>Setup guide</h2>
<h3>Step 1: Set up LM Studio as a server</h3>
<ol>
<li>Open LM Studio and download your chosen model (e.g., Qwen3-Coder-Next if you have 64GB+, or GLM-4.7-Flash for 32–48GB).</li>
<li>Go to the <strong>Developer</strong> tab (<code>Cmd+2</code>).</li>
<li>Load your model (<code>Cmd+L</code>).</li>
<li>Set the context length to at least <strong>25,000 tokens</strong> — Claude Code is context-hungry. If you have RAM headroom (e.g., 128GB with Qwen3-Coder-Next), push this higher — 64K or more will give Claude Code much more room to work with.</li>
<li>Start the server (<code>Cmd+R</code>). It will be available at <code>http://localhost:1234</code>.</li>
</ol>
<h3>Step 2: Bypass Claude Code’s login screen</h3>
<p>This is the tricky part. Even if you set <code>ANTHROPIC_BASE_URL</code> to your local server, Claude Code still forces a login screen. Setting environment variables alone won’t work — I learned this the hard way.</p>
<p>The fix is to use Claude Code’s official <code>apiKeyHelper</code> feature:</p>
<pre><code class="language-bash"># Create the helper script
mkdir -p ~/.claude
cat > ~/.claude/api-key-helper.sh &#x3C;&#x3C; 'EOF'
#!/bin/bash
echo "lm-studio"
EOF
chmod +x ~/.claude/api-key-helper.sh
</code></pre>
<p>Then add it to <code>~/.claude/settings.json</code>:</p>
<pre><code class="language-json">{
  "apiKeyHelper": "/Users/YOUR_USERNAME/.claude/api-key-helper.sh",
  "env": {
    "CLAUDE_CODE_ATTRIBUTION_HEADER": "0"
  }
}
</code></pre>
<p>Replace <code>YOUR_USERNAME</code> with your macOS username (run <code>whoami</code> to check).</p>
<blockquote>
<p><strong>Important:</strong> Do NOT also set <code>ANTHROPIC_API_KEY</code> as an environment variable when using <code>apiKeyHelper</code> — they conflict and you’ll get an auth warning.</p>
</blockquote>
<blockquote>
<p><strong>Why <code>CLAUDE_CODE_ATTRIBUTION_HEADER: 0</code>?</strong> Claude Code prepends an attribution header to requests that invalidates the KV cache on local models, making inference up to 90% slower. This setting must be in <code>settings.json</code>, not as an env export.</p>
</blockquote>
<h3>Step 3: Set environment variables and launch</h3>
<pre><code class="language-bash">export ANTHROPIC_BASE_URL="http://localhost:1234"
export ANTHROPIC_MODEL="zai-org/glm-4.7-flash"  # matches your loaded model
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
claude
</code></pre>
<p>You should see Claude Code start directly — no login screen.</p>
<hr>
<h2>Switching between local and cloud</h2>
<p>This is where it gets practical. If you’re using local models for smaller tasks and Anthropic for complex ones, you don’t want to be editing config files every time you switch.</p>
<p>I built a launcher script that handles everything:</p>
<ul>
<li><strong><code>claude-launcher local</code></strong> — Checks if LM Studio is running, auto-detects the loaded model, creates the <code>apiKeyHelper</code>, sets all the right env vars, applies the KV cache fix, and launches Claude Code.</li>
<li><strong><code>claude-launcher cloud</code></strong> — Removes <code>apiKeyHelper</code>, cleans up local overrides from <code>settings.json</code>, unsets env vars, and launches Claude Code with normal OAuth login.</li>
<li><strong><code>claude-launcher status</code></strong> — Shows whether LM Studio is online, which model is loaded, and which auth mode is active.</li>
<li><strong><code>claude-launcher</code></strong> (no args) — Interactive menu with all of the above.</li>
</ul>
<p>Here’s what it looks like in practice:</p>
<pre><code>┌─────────────────────────────────────┐
│     Claude Code Launcher  🚀        │
└─────────────────────────────────────┘

  LM Studio: ● online — zai-org/glm-4.7-flash

  1)  🖥  Local mode  (LM Studio)
  2)  ☁️  Cloud mode  (Anthropic)
  3)  📊 Status
  q)  Exit
</code></pre>
<p>The full script is published as a GitHub Gist — you can view it below or <a href="https://gist.github.com/gmotzespina/2064a4768eca162a36735567475e7c37">open it on GitHub</a>.</p>
<pre><code class="language-bash">#!/bin/bash
# claude-launcher.sh
# Smart launcher for Claude Code — switch between local (LM Studio) and cloud (Anthropic) modes.
#
# Usage:
#   ./claude-launcher.sh          Interactive menu
#   ./claude-launcher.sh local    Launch with LM Studio
#   ./claude-launcher.sh cloud    Launch with Anthropic account
#   ./claude-launcher.sh status   Show current config &#x26; LM Studio status

set -euo pipefail

# ──────────────────────────────────────────────
# Configuration — edit these to match your setup
# ──────────────────────────────────────────────
LM_STUDIO_URL="http://localhost:1234"
LM_STUDIO_API_KEY="lm-studio"
LOCAL_MODEL=""  # leave empty to use whatever LM Studio is serving, or set e.g. "glm-4.7-flash"

CLAUDE_JSON="$HOME/.claude.json"
CLAUDE_SETTINGS="$HOME/.claude/settings.json"

# ──────────────────────────────────────────────
# Colors
# ──────────────────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m' # No Color

# ──────────────────────────────────────────────
# Helpers
# ──────────────────────────────────────────────
ensure_onboarding_done() {
    # Make sure Claude Code doesn't show the login screen
    if [[ ! -f "$CLAUDE_JSON" ]]; then
        echo '{"hasCompletedOnboarding": true}' > "$CLAUDE_JSON"
    elif ! grep -q '"hasCompletedOnboarding"' "$CLAUDE_JSON" 2>/dev/null; then
        # Add the flag to existing file using a temp file (portable, no jq dependency)
        local tmp
        tmp=$(mktemp)
        # If valid JSON object, inject the key; otherwise overwrite
        if python3 -c "
import json, sys
with open('$CLAUDE_JSON') as f:
    d = json.load(f)
d['hasCompletedOnboarding'] = True
with open('$tmp', 'w') as f:
    json.dump(d, f, indent=2)
" 2>/dev/null; then
            mv "$tmp" "$CLAUDE_JSON"
        else
            rm -f "$tmp"
            echo '{"hasCompletedOnboarding": true}' > "$CLAUDE_JSON"
        fi
    fi
}

ensure_settings_dir() {
    mkdir -p "$HOME/.claude"
}

check_lm_studio() {
    # Returns 0 if LM Studio is responding, 1 otherwise
    if curl -s --connect-timeout 2 "$LM_STUDIO_URL/v1/models" > /dev/null 2>&#x26;1; then
        return 0
    else
        return 1
    fi
}

get_lm_studio_models() {
    # Get loaded LLM model names from LM Studio
    local response
    response=$(curl -s --connect-timeout 2 "$LM_STUDIO_URL/api/v0/models" 2>/dev/null) || return 1
    python3 -c "
import json
try:
    data = json.loads('''$response''')
    for m in data.get('data', []):
        if m.get('state') == 'loaded' and m.get('type') == 'llm':
            print(m.get('id', 'unknown'))
except:
    pass
" 2>/dev/null
}

pick_lm_studio_model() {
    local models=()
    while IFS= read -r line; do
        [[ -n "$line" ]] &#x26;&#x26; models+=("$line")
    done &#x3C; &#x3C;(get_lm_studio_models)

    if [[ ${#models[@]} -eq 0 ]]; then
        echo "no model loaded"
        return 1
    elif [[ ${#models[@]} -eq 1 ]]; then
        echo "${models[0]}"
    else
        echo -e "\n  ${BOLD}Available LM Studio models:${NC}" >&#x26;2
        for i in "${!models[@]}"; do
            echo -e "  ${BOLD}$((i+1)))${NC}  ${models[$i]}" >&#x26;2
        done
        echo "" >&#x26;2
        read -rp "  Choose model [1-${#models[@]}]: " choice &#x3C;/dev/tty
        if [[ "$choice" =~ ^[0-9]+$ ]] &#x26;&#x26; (( choice >= 1 &#x26;&#x26; choice &#x3C;= ${#models[@]} )); then
            echo "${models[$((choice-1))]}"
        else
            echo -e "  ${RED}Invalid choice, using first model.${NC}" >&#x26;2
            echo "${models[0]}"
        fi
    fi
}

# ──────────────────────────────────────────────
# Launch modes
# ──────────────────────────────────────────────
launch_local() {
    echo -e "${BLUE}${BOLD}🖥  Local Mode (LM Studio)${NC}"
    echo ""

    # Check if LM Studio is running
    if ! check_lm_studio; then
        echo -e "${RED}✗ LM Studio is not responding at ${LM_STUDIO_URL}${NC}"
        echo -e "  Make sure LM Studio is running and the server is started."
        echo ""
        read -rp "Wait and retry? (y/n) " choice
        if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
            echo -e "  Waiting for LM Studio..."
            for i in {1..30}; do
                if check_lm_studio; then
                    echo -e "  ${GREEN}✓ Connected!${NC}"
                    break
                fi
                sleep 2
                printf "."
            done
            echo ""
            if ! check_lm_studio; then
                echo -e "${RED}  Timed out. Please start LM Studio and try again.${NC}"
                exit 1
            fi
        else
            exit 1
        fi
    fi

    echo -e "${GREEN}✓ LM Studio is running${NC}"
    echo ""

    ensure_onboarding_done
    ensure_settings_dir

    # Create the apiKeyHelper script — this is what actually bypasses the login screen
    local key_helper="$HOME/.claude/api-key-helper.sh"
    cat > "$key_helper" &#x3C;&#x3C; EOF
#!/bin/bash
echo "$LM_STUDIO_API_KEY"
EOF
    chmod +x "$key_helper"

    # Set env vars for this session
    export ANTHROPIC_BASE_URL="$LM_STUDIO_URL"
    export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

    # Do NOT set ANTHROPIC_API_KEY — it conflicts with apiKeyHelper
    unset ANTHROPIC_API_KEY 2>/dev/null || true

    # Set model — use LOCAL_MODEL if pinned, otherwise let user pick from LM Studio
    if [[ -n "$LOCAL_MODEL" ]]; then
        export ANTHROPIC_MODEL="$LOCAL_MODEL"
    else
        local model_name
        model_name=$(pick_lm_studio_model)
        export ANTHROPIC_MODEL="$model_name"
    fi
    echo -e "  Model: ${BOLD}${ANTHROPIC_MODEL}${NC}"

    # Write settings with apiKeyHelper + attribution header fix
    python3 -c "
import json, os

path = '$CLAUDE_SETTINGS'
d = {}
if os.path.exists(path):
    try:
        with open(path) as f:
            d = json.load(f)
    except:
        pass

# Set apiKeyHelper to bypass login
d['apiKeyHelper'] = '$key_helper'

# Set attribution header fix for KV cache performance
env = d.setdefault('env', {})
env['CLAUDE_CODE_ATTRIBUTION_HEADER'] = '0'

with open(path, 'w') as f:
    json.dump(d, f, indent=2)
" 2>/dev/null

    echo -e "  ${GREEN}Launching Claude Code → LM Studio${NC}"
    echo -e "  ─────────────────────────────────"
    echo ""

    exec claude "$@"
}

launch_cloud() {
    echo -e "${BLUE}${BOLD}☁️  Cloud Mode (Anthropic)${NC}"
    echo ""

    # Clear any local overrides
    unset ANTHROPIC_BASE_URL 2>/dev/null || true
    unset ANTHROPIC_API_KEY 2>/dev/null || true
    unset ANTHROPIC_MODEL 2>/dev/null || true
    unset CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 2>/dev/null || true

    # Remove apiKeyHelper + attribution header from settings so Claude uses normal OAuth
    if [[ -f "$CLAUDE_SETTINGS" ]]; then
        python3 -c "
import json
with open('$CLAUDE_SETTINGS') as f:
    d = json.load(f)

# Remove local-mode keys
d.pop('apiKeyHelper', None)

env = d.get('env', {})
env.pop('CLAUDE_CODE_ATTRIBUTION_HEADER', None)
if not env:
    d.pop('env', None)

with open('$CLAUDE_SETTINGS', 'w') as f:
    json.dump(d, f, indent=2)
" 2>/dev/null
    fi

    # Clean up the helper script
    rm -f "$HOME/.claude/api-key-helper.sh"

    echo -e "  ${GREEN}Launching Claude Code → Anthropic API${NC}"
    echo -e "  ─────────────────────────────────────"
    echo ""

    exec claude "$@"
}

show_status() {
    echo -e "${BLUE}${BOLD}📊 Claude Code Launcher — Status${NC}"
    echo ""

    # LM Studio
    if check_lm_studio; then
        local lm_models=()
        while IFS= read -r line; do
            [[ -n "$line" ]] &#x26;&#x26; lm_models+=("$line")
        done &#x3C; &#x3C;(get_lm_studio_models)
        echo -e "  LM Studio:  ${GREEN}● running${NC} at ${LM_STUDIO_URL} — ${#lm_models[@]} model(s): ${BOLD}${lm_models[*]}${NC}"
    else
        echo -e "  LM Studio:  ${RED}● not running${NC} at ${LM_STUDIO_URL}"
    fi

    # Current env
    if [[ -n "${ANTHROPIC_BASE_URL:-}" ]]; then
        echo -e "  Base URL:   ${YELLOW}${ANTHROPIC_BASE_URL}${NC}"
    else
        echo -e "  Base URL:   ${GREEN}Anthropic default (cloud)${NC}"
    fi

    # Onboarding flag
    if [[ -f "$CLAUDE_JSON" ]] &#x26;&#x26; grep -q '"hasCompletedOnboarding": true' "$CLAUDE_JSON" 2>/dev/null; then
        echo -e "  Onboarding: ${GREEN}✓ bypassed${NC}"
    else
        echo -e "  Onboarding: ${YELLOW}not set (may show login screen)${NC}"
    fi

    # apiKeyHelper
    if [[ -f "$CLAUDE_SETTINGS" ]] &#x26;&#x26; grep -q '"apiKeyHelper"' "$CLAUDE_SETTINGS" 2>/dev/null; then
        echo -e "  Auth:       ${YELLOW}apiKeyHelper (local mode)${NC}"
    else
        echo -e "  Auth:       ${GREEN}OAuth / Anthropic account${NC}"
    fi

    # Settings
    if [[ -f "$CLAUDE_SETTINGS" ]]; then
        echo -e "  Settings:   ${GREEN}✓ exists${NC} at ${CLAUDE_SETTINGS}"
    else
        echo -e "  Settings:   ${YELLOW}not found${NC}"
    fi

    echo ""
}

show_menu() {
    echo ""
    echo -e "${BOLD}┌─────────────────────────────────────┐${NC}"
    echo -e "${BOLD}│     Claude Code Launcher  🚀        │${NC}"
    echo -e "${BOLD}└─────────────────────────────────────┘${NC}"
    echo ""

    # Quick status line
    if check_lm_studio; then
        local lm_models=()
        while IFS= read -r line; do
            [[ -n "$line" ]] &#x26;&#x26; lm_models+=("$line")
        done &#x3C; &#x3C;(get_lm_studio_models)
        echo -e "  LM Studio: ${GREEN}● online${NC} — ${#lm_models[@]} model(s): ${lm_models[*]}"
    else
        echo -e "  LM Studio: ${RED}● offline${NC}"
    fi
    echo ""

    echo -e "  ${BOLD}1)${NC}  🖥  Local mode  (LM Studio)"
    echo -e "  ${BOLD}2)${NC}  ☁️  Cloud mode  (Anthropic)"
    echo -e "  ${BOLD}3)${NC}  📊 Status"
    echo -e "  ${BOLD}q)${NC}  Exit"
    echo ""
    read -rp "  Choose [1/2/3/q]: " choice

    case "$choice" in
        1) launch_local ;;
        2) launch_cloud ;;
        3) show_status ;;
        q|Q) exit 0 ;;
        *) echo -e "  ${RED}Invalid choice${NC}"; show_menu ;;
    esac
}

# ──────────────────────────────────────────────
# Main
# ──────────────────────────────────────────────
case "${1:-}" in
    local)   shift; launch_local "$@" ;;
    cloud)   shift; launch_cloud "$@" ;;
    status)  show_status ;;
    help|-h|--help)
        echo "Usage: $(basename "$0") [local|cloud|status|help]"
        echo ""
        echo "  local    Launch Claude Code with LM Studio"
        echo "  cloud    Launch Claude Code with Anthropic account"
        echo "  status   Show configuration and LM Studio status"
        echo "  (none)   Interactive menu"
        ;;
    *)       show_menu ;;
esac
</code></pre>
<hr>
<h2>What to expect (honest take)</h2>
<p>Local models are not Claude. Let’s be clear about that.</p>
<p><strong>What works well locally:</strong> Scaffolding, boilerplate generation, simple refactors, writing tests for well-defined functions, code review, renaming and restructuring. Basically any task where the intent is clear and the scope is contained.</p>
<p><strong>What you should save for Anthropic’s models:</strong> Complex multi-file reasoning, architectural decisions, debugging subtle issues, anything that requires deep thinking across a large context. When you need these, switch to cloud mode and use the real thing.</p>
<p><strong>The multiplier:</strong> A well-structured project makes a huge difference. If you have a solid CLAUDE.md, well-defined skills files, and proper agent configuration, even a smaller local model can produce solid results. The model doesn’t need to be brilliant when your project context is telling it exactly what conventions to follow, what patterns to use, and how your codebase is organized. Invest in your project scaffolding — it pays off whether you’re running locally or in the cloud.</p>
<p><strong>Speed and context:</strong> Local inference is noticeably slower than cloud. On a 32–48GB Mac with GLM-4.7-Flash, expect 25–32K context. On a 64GB+ Mac with Qwen3-Coder-Next, you can push to 64K+ which makes a real difference for larger codebases. Either way, keep your tasks focused and you’ll be fine.</p>
<hr>
<h2>TL;DR</h2>
<ol>
<li><strong>Pick the right model for your RAM:</strong> Qwen3-Coder-Next (64GB+) for Sonnet-class performance, GLM-4.7-Flash (32–48GB) for the best bang-per-gigabyte.</li>
<li><strong>Use <code>apiKeyHelper</code></strong> to bypass Claude Code’s login screen (env vars alone won’t work).</li>
<li><strong>Set <code>CLAUDE_CODE_ATTRIBUTION_HEADER: 0</code></strong> in <code>settings.json</code> to avoid a 90% speed penalty.</li>
<li><strong>Use a launcher script</strong> to toggle between local and cloud modes without editing files.</li>
<li><strong>Use local for small tasks, Anthropic for complex ones</strong> — this is the sustainable way to use Claude Code without burning through your plan or your wallet.</li>
</ol>
<p>The next time you board a flight, open your laptop, and code. No Wi-Fi required.</p>
<hr>]]></content:encoded>
            <author>gmotzespina@icloud.com (Guillermo Espina)</author>
        </item>
    </channel>
</rss>