Key takeaways

  • A token-overlap keyword clusterer fits in about twenty lines of Python but misses plurals and synonyms.
  • Embeddings and search result overlap group better but add dependencies, tuning and cost.
  • An AI agent can call seogeoaeo.ai's Keyword Clusterer over MCP for 3 credits a run and return clusters with suggested page paths.

Keyword clustering in Python takes about twenty lines if you group by shared words, and much more if you want grouping by meaning or by Google results. If you work with an AI coding agent, there is a shorter path: let the agent call seogeoaeo.ai's Keyword Clusterer over MCP and spend your effort on reading the groups instead of maintaining the code.

Both routes are below, so you can pick the one that suits your setup.

The twenty-line version

The simplest useful method is token overlap: split each keyword into words, drop filler words, and put a keyword in the first group whose core words it shares.

STOP = {"for", "the", "a", "to", "of", "best", "how", "what", "is"}

def tokens(kw):
    return {w for w in kw.lower().split() if w not in STOP}

def cluster(keywords, min_shared=2):
    groups = []
    for kw in keywords:
        t = tokens(kw)
        for g in groups:
            if len(t & g["core"]) >= min(min_shared, len(t)):
                g["keywords"].append(kw)
                break
        else:
            groups.append({"core": t, "keywords": [kw]})
    return [g["keywords"] for g in groups]

kws = ["running shoes", "best running shoes", "trail running shoes",
       "running shoes for beginners", "dress shoes", "email marketing"]
for g in cluster(kws):
    print(g)

On that list it prints three groups: the four running shoe phrases together, then "dress shoes" and "email marketing" on their own. It is a starting point, not a finished tool. It ignores plurals, so "shoe" and "shoes" do not match, and it depends on the order of your list.

Going further in Python

Approach What you add Trade-off
Token overlap (above) Nothing Misses synonyms
TF-IDF plus a clustering algorithm scikit-learn Needs tuning for the number of groups
Sentence embeddings An embedding model Groups by meaning, but harder to explain each group
Search result overlap A SERP data source Closest to how Google sees intent, but costs per lookup

Each step up adds a dependency, a cost or a tuning problem. For a one-off content plan, that is often more engineering than the question deserves.

The agent version

seogeoaeo.ai runs its SEO tools from the browser, from a REST API, and from any MCP client with a workspace API key, including Claude Code, Cursor and Codex. Its Keyword Clusterer takes a newline-separated list of up to 20,000 characters, groups it by token overlap and returns a suggested parent page path for each cluster. A run costs 3 credits.

A typical session in Claude Code looks like this:

  1. Ask the agent to collect your keywords from a CSV or a doc into one list.
  2. Have it run the Keyword Deduplicator first, which merges exact duplicates and flags hyphen and plural variants. The clusterer's page recommends this.
  3. Have it run the Keyword Clusterer on the cleaned list.
  4. Ask it to turn each cluster into a row: focus keyword, suggested path, and the other keywords as headings.

The method is token overlap, like the script above, but with no code for you to maintain. It uses no embeddings, language model or live search results, so the grouping stays explainable.

Reading the clusters

Whichever route you take, the output is a draft. Go through the groups with the agent and check three things.

  • One intent per group. "Running shoes for beginners" and "buy running shoes" share words, but one reader wants advice and the other wants a shop. Split them if the page cannot serve both.
  • Groups that should merge. Two small groups can be the same question in different words. Shared-words methods miss these, so look for them by eye.
  • Pages you already have. A cluster that matches an existing URL means an update, not a new article.

An agent is good at this step too: give it your sitemap and ask it to flag clusters that map to existing pages.

When to write the code anyway

Write your own Python when you need grouping by meaning, when you want results-based clustering against your own SERP data, or when clustering is one step in a larger pipeline you already run. Dedicated tools that compare Google results, such as Keyword Insights, are also the better fit when synonyms hide intent.

For the common case, a list that needs to become a page plan today, the agent route is quicker. Plans start at $29 a month on the seogeoaeo.ai pricing page, and agent runs cost the same as browser runs.

Frequently asked questions

How do I cluster keywords in Python?

Split each keyword into words, drop filler words, and group keywords that share their core words. For grouping by meaning, add sentence embeddings.

Can Claude Code cluster keywords?

Yes. Connected to seogeoaeo.ai over MCP with a workspace API key, it can run the Keyword Deduplicator and Keyword Clusterer and turn the groups into a page plan.

Does seogeoaeo.ai use AI to cluster keywords?

No. Its Keyword Clusterer groups by token overlap, with no embeddings, language model or live search results.

Sources

  1. Keyword Clustererseogeoaeo.ai
  2. seogeoaeo.ai full referenceseogeoaeo.ai
  3. seogeoaeo.ai pricingseogeoaeo.ai