All posts
AI WorkflowsSEOHubSpotMartech

I Built a Custom AI Tool to Automate Internal Linking in a HubSpot Blog

April 8, 2025·7 min read

Since ChatGPT went mainstream, I've felt pressure to evaluate how AI could improve efficiency at work. After testing most of the tools being marketed, my conclusion: the majority are expensive wrappers around the same LLM APIs, or existing workflow automations relabeled as AI. They weren't worth it.

So I decided to try building something myself.

The task I picked was internal linking — a specific, repeatable SEO job we do constantly on our HubSpot blog. It takes hours to do well manually but follows a consistent pattern every time.


Why Internal Linking Matters More Than Most People Realize

The standard explanation is that internal links help users navigate your site. That's true but misses the more consequential reason.

When Google crawls your site, it follows links to discover pages and assign them authority. Every link passes a fraction of the source page's ranking strength to its destination — this is called PageRank flow. A blog post with no internal links pointing to it is effectively an island. Google may crawl it, but it won't treat it as an important page.

Anchor text matters too. The words you use to link carry semantic meaning. Linking to a page with a generic phrase tells Google something different than linking with a specific, descriptive term that matches what the destination page covers. Consistent, relevant anchor text across dozens of posts gradually reinforces what a page is about.

For a company with a large blog archive, pages that accumulate internal links from high-ranking, relevant posts tend to rank better over time. The effect compounds. A post that ranks well becomes a stronger source of PageRank flow, which lifts the pages it links to, which eventually become stronger sources themselves.

Doing this manually means reading every post, matching phrases to a keyword list, checking that you haven't already linked to the same URL from that post, and making the HTML changes without breaking anything. On a blog with hundreds of posts and a growing keyword list, it's the kind of task that gets deprioritized constantly because it's slow and not urgent — even though the long-term SEO payoff is real.


What I Built

The tool is a Python script that connects to HubSpot and Anthropic's Claude API. When I run it:

  • It pulls my most recently published blog posts from HubSpot
  • It loads a keyword-to-URL mapping I maintain in a Google Sheet, exported as a CSV
  • It sends each post to Claude with a prompt asking it to find natural places in paragraph text where those keywords appear
  • It shows me exactly what it wants to change — the anchor text, the destination URL, and its reasoning — before touching anything
  • If I approve, it saves the updated post back to HubSpot as a draft

Nothing goes live automatically. I review every suggestion. The tool finds the opportunities; I decide what gets applied.

It also handles a second problem: keeping the keyword list current. When a new post doesn't have any keywords in the CSV yet, Claude reads it and suggests 2–4 phrases to represent it, ranked by relevance to our core topics. Those get added to the CSV so future posts can link back to it.

Each run costs under $1 in Anthropic API fees.

how it works

HubSpot SEO Internal Link Agent

01

Keyword & URL List

Google Sheets CSV with priority tiers 1–7

02

Fetch Blog Posts

Recent posts or a specific URL via HubSpot API

03

Claude Finds Link Spots

Tier-ranked · p-tags only · no duplicates

04

You Review & Approve

Yes / No / Quit — nothing writes without your approval

05

Saved as Draft

HubSpot draft — you publish when ready

Scan log prevents re-processing · links.csv auto-updates with keywords for new posts

nicklanspa.com

Building It for the First Time

I'd never built a custom app for a work project before. I wasn't confident I could finish one.

My technical background helped — not programming experience specifically, but enough to set up API keys, read error messages without panicking, and think through a workflow before writing any code. Being precise about what the tool needed to do, and what it shouldn't do, turned out to be most of the work. The prompts, the logic, and the iteration all got easier once the goal was well-defined.

I used Claude Code in the terminal. The early version was rough — it occasionally proposed links inside heading tags, had no memory between runs so it re-processed the same posts repeatedly, and sometimes couldn't find exact phrase matches in the HTML. Each failure pointed at something fixable.

The version I run today looks substantially different from where I started. I added a scan log so posts never get re-processed. I added a tiered priority system so the most commercially relevant keywords get placed before generic ones. I added a mode to scan a specific URL rather than always pulling the newest posts. I separated Claude's job (find opportunities, return JSON) from Python's job (apply links to HTML), which solved a whole class of formatting errors.

Every improvement came from running it against real posts and noticing what was wrong.


It's Still Changing

I keep finding small ways to improve it. Some come from friction I notice during a run. Some come from reading about how HubSpot handles draft states, or how Claude processes long HTML. The feedback loop is fast — a bad suggestion just gets skipped at the review step — so testing ideas is low risk.

If you have a task at work that's specific, repeatable, and time-consuming, a custom tool might be worth building. Most processes aren't good candidates. But when a task follows a consistent pattern and has a clear success condition, the combination of an LLM and a few API calls can get you further than you'd expect.

If you want to figure out whether your process is a good candidate, or what building something like this would actually involve, reach out.

how this post was made
Nick's Expertise

Conceived & Researched

  • Topic & strategic angle
  • Real-world examples
  • Data & proof points
AI's Role

Drafted Only

  • Structural outline
  • First draft
Nick's Sign-Off

Rewritten & Approved

  • Sections rewritten
  • Errors corrected
  • Personal approval

The ideas, research, and opinions are Nick's. AI speeds up the writing.

nicklanspa.com

Want to talk through any of this?

I work with B2B SaaS companies as a full-time hire or contractor. If something in this post is relevant to what you are building, reach out.

Get in touch