Once I'd committed to keeping costs near zero, a pay-per-use API was never really an option. Deciding to use a subscription I was already paying for meant how to hook up AI was almost entirely decided for me — instead of the admin calling an API, it runs the logged-in claude command as a child process. That one decision dragged along where it runs, what a unit of work looks like, and how failures get handled. This post covers that chain reaction, plus three times I got burned wiring it up.
1. Using a subscription decided the approach
1.1 I decided not to use an API key
The principle I set in post #1 was "zero fixed cost." Calling AI through an API means paying per token every time I write a post. More posts means more cost, and that's a cost I can't control.
But I was already paying for a subscription for development work. I can use the same model, with money I've already spent, within its usage limits.
| API Key | Subscription already being paid for | |
|---|---|---|
| Billing | Per token used | No extra charge |
| How to call it | HTTP request | Run a logged-in command |
| Limits | Effectively none | Weekly usage cap |
| Where it can run | Anywhere | Only that logged-in machine |
That last row mattered most. A subscription session is tied to whichever machine you're logged in on. You can't just deploy it to a cloud function and call it from there.
1.2 So AI runs inside the MacBook
Since post #3 already put the admin on my home MacBook, the spot was already reserved. The admin and the AI end up living on the same machine.
That got me one nice thing: when AI output gets written to the DB, it never touches the network. The same process just opens the SQLite file directly.
The flip side is just as clear. If the MacBook is off, there's no AI. Same weakness I flagged at the end of post #3.
2. Where I wired it in
2.1 A state change wakes the AI up
Buttons don't call the AI directly. A button only changes the post's state, and a hook that runs right after the save sees that change and spins up the AI.
flowchart LR
btn["Admin button"] -->|change state| db[("save")]
db --> hook["post-save hook"]
hook -->|run command| cli["claude CLI"]
cli -->|result| db2[("save again")]
I didn't have the button call it directly because I wanted to avoid blocking the save. A single AI step takes anywhere from 15 to 60 seconds, and holding the save request open that whole time makes the UI look frozen. So the hook fires off the AI and doesn't wait around. When the result comes back, it gets saved separately.
Routing everything through state got me something extra: failures stick around as state. If a draft fails, the post just sits frozen at "draft requested," and the run log records why. It doesn't quietly vanish.
2.2 AI does four things
| Task | When it runs | Result |
|---|---|---|
| Topic suggestion | Clicked from the dashboard | A handful of candidates |
| Draft | "Generate draft" on a suggested topic | Body, summary, tags |
| Translation | Turning on the English version | English body |
| Review | Run from the editor | A list of issues |
All four only run when I click them. The original design had a nightly automated run, but that's gone now. Why I cut it is the subject of the next post.
3. Getting data back, not prose
Ask AI to "write a draft" and you get back a piece of writing. The problem is that it's just writing. Pulling out the title, summary, and tags separately means parsing the response, and it breaks the moment the model formats things even slightly differently.
So when I make the request, I send the shape I want along with it. Body goes here, summary goes here, tags as an array. The result comes back in that shape.
Even so, things leaked through. Two real cases I hit:
- The whole response gets wrapped in a code block — drop that in as-is and the entire post turns into code
- A stray closing tag trails after a sentence — something like
...ended here.</markdown>slips into the body
Both got fixed by adding a cleanup layer before the result goes into the post. But I couldn't just strip things blindly. The body might contain a real code block, and some posts legitimately end with a tag. So I only strip closing tags that have no matching opening tag, and only peel off the outer wrapper when there's no other code block nested inside.

4. Three burns
4.1 I used one timeout for everything
At first every step got 2 minutes. Topic suggestion had room to spare. But the draft step kept dying outright. While the model was writing out a few thousand characters, 2 minutes just ran out from under it.
I tried raising it. It still died. That day's run log still shows all three attempts.
| Time | What changed | Time taken | Result |
|---|---|---|---|
| 14:10 | — (120s limit) | 120s | Aborted on timeout |
| 14:16 | Raised limit to 600s | 600s | Timed out again |
| 14:33 | Added a one-line length spec to the prompt | 88s | Succeeded |
The model uses whatever time you give it. Give it 10 minutes, it uses 10 minutes. The fix wasn't time — it was the request. Adding one line to the prompt — Length: 2,500–3,500 characters including spaces — was what actually made it finish.
Even after that, each step writes a different amount, so I still had to set timeouts separately per step.
| Task | Timeout |
|---|---|
| Draft · Translation | 10 min |
| Review | 6 min |
| Topic suggestion | 4 min |
4.2 I clicked everything at once
I clicked "generate draft" on all four suggested topics back to back, and all four failed. Four commands hit the same subscription at the same time.
Now it's one at a time, queued up. Whatever gets clicked later waits until the one before it finishes.
4.3 I ran it from the wrong working directory
This one was the hardest to catch. I asked for topic suggestions and got back stories about recent commits to this very CMS. I'd asked for blog topics and it handed me a status report on my own project.
The cause was running the command from inside the project folder. Project-specific memory that had accumulated in that folder got pulled into the prompt. Running it from a folder that wasn't tied to any project made it disappear.
I ran the exact same prompt twice, without changing a single character. The only thing that differed was which folder the command ran from.
| Run from inside the project folder | Run from a non-project folder | |
|---|---|---|
| 1 | Where concurrent writes break down when running a CMS on SQLite | Adopting PgBouncer: fixing a PostgreSQL bottleneck that hits at 300 concurrent write connections |
| 2 | Latency and security trade-offs of exposing a MacBook externally via Cloudflare Tunnel + Access | Building a zero-downtime deploy pipeline with GitHub Actions: automating even the rollback |
| 3 | Designing timeouts and token costs when running the Claude CLI as a subprocess | How I cut the LLM API timeout rate: queueing/retry/backoff design and the measured improvement |
| 4 | Measuring prompt quality via the diff between AI drafts and human edits | Blocking login brute-force attacks with Nginx rate limiting |
| 5 | The minimum security needed for a static site + local admin setup | Building blog infrastructure from scratch as a solo developer: a record of choices and trial and error |
| Tokens dragged in | 38,294 | 6,323 |
The left column isn't blog topics — it's status updates on my own project. Everything in bold only exists inside this one repo.
5. I didn't give the AI any hands
The last one isn't a bug — it's a deliberate constraint.
When I call the AI, I give it no tools at all. It can't read files, run commands, or take screenshots. It only answers based on what's in the prompt.
I didn't want an unattended process poking around my disk, and writing a draft doesn't require file access anyway.
There's a cost to that, though. The AI runs into things it can't do. Screenshots, real measurements, benchmark results. No tools means it can't produce them.
So instead of letting it make those up, I had it leave them blank.
[[TASK: one line about what's needed]]
If this marker is still there, publishing is blocked. Whoever has access to the actual machine has to fill it in.
That's the AI integration story. But this pipeline actually shrank after I built it. The nightly automated run is gone, and even the review step that used to run automatically now runs by hand.
What I cut and why is next.



