SEO and AI Search 16 min read Published November 2026 By

Build an SEO Keyword Clustering Engine in Claude Code

A keyword clustering skill is a folder inside a Claude Code project that turns a raw keyword list into a cluster map: one row per page you should have, the page you already own for it, and whether that row means a new page, a refresh or a merge. The grouping is done by scripts, so it gives the same answer twice. A table of your existing pages stops it proposing duplicates, and a small set of test cases catches a bad merge before it ever becomes a brief. This post builds that folder, file by file, and says which decisions stay with you.

From a raw keyword list to a map you approve

  1. 01Collectyour keyword export merged with your Search Console queries
  2. 02Embedevery phrase turned into a vector by an embedding provider
  3. 03Groupphrases joined above a similarity floor your test cases set
  4. 04Matcheach group checked against the table of pages you already own
  5. 05Cluster mapone row per page: new page, refresh or merge, with a reason
Fig 01 · The map is the only outputA keyword clustering skill ends in one cluster map, a short table where every row names the page that should answer a group and whether that means a new page, a refresh or a merge, and a person approves it before any brief is written.

A keyword clustering skill, in one answer

To build a keyword clustering skill in Claude Code, you make one folder under .claude/skills/ with a SKILL.md file of instructions, a few scripts that do the counting, a reference table of the pages your site already has, and three or more test cases. Claude reads the instructions when you ask for a cluster map, runs the scripts in order, and hands you a table to approve. It is a set of files you can open, change and keep, not a product you subscribe to.

A keyword clustering skill, stated precisely

Where it lives
one folder under .claude/skills/
Instructions
a SKILL.md Claude reads when you ask for a cluster map
Scripts
the counting, run in order
Reference table
the pages your site already has
Test cases
three or more, with answers you already know
What it hands you
a table to approve, in files you can open, change and keep
Fig 02 · Files you keepA keyword clustering skill is a set of files you can open, change and keep rather than a product you subscribe to, and what it hands you at the end is a table to approve.

The method behind the grouping, meaning first and shared search results for the close calls, is already explained in our guide to automating keyword clustering from a list to a cluster map, and choosing which clusters a business should own at all is part of our SEO playbook for a Content OS. This post argues neither again. What that guide leaves open is the build: where each piece lives, which steps must be code and which can be instructions, and how you know the thing still works after you change it.

Why a Claude Code skill for SEO, and not a chat window

A Claude Code skill for SEO is better than pasting a keyword list into a chat window because the instructions, the scripts and the record of your own pages persist as files, so the second run follows the same rules as the first. In a chat, the model groups the list by reading it, so two runs can disagree, and it cannot know which of your pages already rank. In a Claude Code project, which our Claude Code guides cover from several angles, the grouping is arithmetic a script performs, the page inventory sits in a file the script reads, and every change to either is visible in version history.

What changes when clustering becomes a skill

In a chat windowIn a Claude Code skill

A prompt typed by whoever is on duty

instructions in a file every run follows

The model groups the list by reading it

a script groups it by arithmetic

No idea which of your pages already rank

a page inventory the script reads

A method nobody can see change

every change visible in version history

Fig 03 · The record of your own pagesThe change that matters most is the page inventory: a chat cannot know which of your pages already rank, and a script that reads your own table can.

The second reason is context, and Anthropic's overview of Agent Skills puts numbers on it: a skill's name and description cost about 100 tokens while the skill is idle, the SKILL.md body is meant to stay under 5,000 tokens once it loads, and bundled files cost nothing until they are read. A script is better still: Claude runs it and only its output enters the conversation, never its code. So a skill can carry a long reference table and four scripts without crowding out the actual work.

The third reason is the one that matters for search. Google's page on creating helpful, people-first content describes effort as the extent to which human work went into creating the content "or the systems powering it", and it counts automatically generating pages from feeds, or producing large amounts of text with generative AI without oversight, as little to no effort. A clustering skill is on the right side of that line only if it is built to stop pages, not to multiply them. That is why the most important file in the folder is the one that lists what you already own.

The folder, and the SKILL.md for keyword research

The folder holds four kinds of thing: SKILL.md, which says what to do and in what order; a reference/ folder with the facts the skill checks against; a scripts/ folder with the code that does the counting; and an evals/ folder with the cases it must pass. Claude Code's guide to extending Claude with skills puts a project skill at .claude/skills/<skill-name>/SKILL.md and says to commit it so the team gets it too, which is the point: the method belongs to the business, not to one laptop. The project's own instruction file, the one every session reads, is a different thing, covered in our guide to writing a CLAUDE.md file for a content project; a skill is only read when its job comes up.

The SKILL.md for keyword research

clustering-keywords, the SKILL.md

  1. 01name: clustering-keywords, lowercase, hyphens, under 64 characters
  2. 02description: trigger words first, keyword list, cluster map, which page should target this
  3. 03disable-model-invocation: true, so it runs only on its slash command
  4. 04Run each script in order and name the file it writes
  5. 05Read merge rules from reference/, one link deep
Fig 04 · The description decides when it runsThe description is the line that decides whether the skill fires at all, so it puts the words a person actually types first, in the third person, inside the 1,024-character limit.

The SKILL.md for keyword research starts with two fields of frontmatter, and both have hard limits. Anthropic's skill authoring best practices set the name at 64 characters or fewer, in lowercase letters, numbers and hyphens, with the words anthropic and claude reserved, and the description at 1,024 characters or fewer. So clustering-keywords is a legal name and claude-seo-clusters is not. Claude Code adds its own limit on top: the description and any when_to_use text are cut at 1,536 characters in the skill listing, so the key use case goes first.

The description is what decides whether the skill fires, so it names the trigger words a person actually types: keyword list, keyword research export, cluster map, which page should target this. It is written in the third person, as the best-practices guide asks. Below the frontmatter, the body is a numbered checklist that names each script and the file it writes, then stops, well inside the guide's limit of 500 lines. Anything longer, such as the definition of a page type or the rules for a merge, goes into a file in reference/, linked directly from SKILL.md and never from another reference file, because the guide warns that Claude may only preview a file it reaches through a second link.

Two settings in the frontmatter are worth setting on purpose. disable-model-invocation: true stops Claude starting the skill on its own whenever a conversation mentions keywords, so it only runs when someone types /clustering-keywords. And allowed-tools lets the run use the scripts without stopping for a permission prompt on every step, a grant the Claude Code documentation says clears when you send your next message. For a standing rule, Claude Code's permissions documentation notes that permission settings can be checked into version control, so every person running the skill gets the same allowances.

The keyword clustering scripts, and what each one does

A keyword clustering script is needed wherever two runs must give the same answer, which is every step that counts, compares or matches; instructions are kept for the steps that need judgement. The best-practices guide makes the same distinction in its own terms: low freedom, meaning an exact script, for operations that are fragile and must be consistent, and high freedom, meaning text, where several approaches are valid. Grouping four hundred phrases is the first kind. Naming the group is the second. Anthropic's engineering write-up on Agent Skills gives the reason with a plainer example: producing a sorted list by generating tokens costs far more than running a sorting algorithm. Each of those scripts is unpacked on its own, outside a skill, in our walkthrough of semantic keyword clustering in Python, which explains embeddings, cosine similarity and how to pick a clustering algorithm.

Four scripts, each handing one file to the next

Fig 05 · A lookup, not an opinionThe matching script is the one that stops duplicates, because whether a page you already own answers a group is a lookup against your pages table, not something to judge by reading.

Four scripts cover the work, and each writes one file the next one reads.

ScriptReadsWritesWhy it is code, not instructions
collect.pyyour keyword export and Search Consolephrases.csv, de-duplicatedan API with paging and quotas has to be called exactly, every time
embed.pyphrases.csvvectors.npythe same phrase must get the same vector, or groups drift between runs
group.pyvectors.npygroups.csv with a similarity score per paira threshold applied by arithmetic is repeatable; one applied by reading is not
match.pygroups.csv and reference/pages.csvcluster-map.csvwhether a page already owns a phrase is a lookup, not an opinion

The collecting script has real limits to respect. The Search Analytics query method returns between 1 and 25,000 rows per request, 1,000 by default, and says it returns the top rows rather than every row; the Search Console API usage limits allow 1,200 queries a minute per site and per user. So the script pages through with startRow and treats the result as the most visible queries, not a census. The same method can now leave searches for the business’s own name out of the map, and our explainer on the Search Console API’s branded and multimodal data lists what that split can and cannot return.

If you also want ideas you do not rank for yet, the Google Ads keyword ideas service takes 1 to 20 seed keywords, returns a 12-month average of monthly searches and a competition level, and can return up to 250,000 ideas from a site seed, which is exactly why the next step exists. Budget the calls too: Google's API access levels allow 2,880 operations a day on production accounts at Explorer access and 15,000 at Basic, so a monthly run fits comfortably and a script that loops without a cap does not.

The embedding script needs a provider other than the one that writes. Anthropic's guide to embeddings says plainly that it does not offer its own embedding model and points to Voyage AI, whose general models produce 1,024-number vectors by default and are normalised to length 1, so cosine similarity and the dot product give the same ranking. The grouping script then joins every pair above a similarity floor. That floor is the one number in the folder people are tempted to copy from a blog, and the guide's warning about "voodoo constants" applies directly: write down why the value is what it is, in a comment beside it, and let the test cases in evals/ decide it rather than a figure somebody quoted.

The table of pages you already own

The table of pages you already own is a file in reference/ with one row per published page: its URL, the one phrase it is meant to rank for, and any phrases it has promised to leave to other pages. Clustering without it is how a site ends up with three posts answering one question, because a list of keywords says nothing about what you have already written. With it, every group gets one of three actions: a new page, a refresh of the page that already owns it, or a merge of two pages that turned out to want the same search.

Where the pages table sends each group

One group, checked against your pages
New page

no page you own answers this search

  • marked new
Refresh

a page you own already earns impressions for these phrases

  • page named
  • phrases listed
Merge

two of your pages turn out to want the same search

  • both pages named
Fig 06 · Three answers, one tableOnce it is checked against your own pages, every group gets exactly one of three actions, and a refresh or a merge is how the skill stops a site gaining a third post on one question.

We know this from running our own version on this very post. Before writing a word of it we ran the overlap script that lives in our website's repository against the working title, and it returned our own guide to keyword clustering as the nearest page, with a score of 81.2 against 52.3 for the next nearest post, published four days earlier, whose title already ended "in Claude Code". The skill's job at that moment was not to propose a page. It was to say that the method was taken and that only the build was left, which is the only reason this post is about folders and not about embeddings. Our guides to planning SEO content clusters are filed the same way, each owning one question.

The matching script also reads Search Console: any group that already draws impressions to a page of yours is marked for a refresh, and the reason column says which page and which phrases. What happens to that page next is a job of its own, set out in our guide to automating content refreshes without losing quality. The same table also feeds the next stage, because a row that names its owning page is a row that knows where its internal links go, which is the whole subject of our guide to automating internal linking as a checked step.

What the skill decides, and what it hands to you

The skill settles whatever can be counted and passes on whatever someone must answer for: whether a group earns its own page, which page leads the cluster, how a borderline pair is settled, and whether the topic is one the business really serves. Choosing to publish does not, because it changes what the business says in public and what it will have to keep up to date. An approved row then becomes a brief, and the gate that keeps those briefs from turning into thin pages is the subject of our guide to automating SEO content without search spam.

Who decides each part of the map

The skill decides

A person decides

  1. Grouping and matchingarithmetic and lookups with a right answer for most rows
  2. The reason columnthe skill writes it, a person reads it closely
  3. Which groups get pageschanges what the business says in public
Fig 07 · The reason is the handoverThe reason column sits between the two ends: the skill writes it, and a person uses it to decide, so a row whose reason a stranger could not follow is marked needs a look.

The handover point is a single file. The skill writes cluster-map.csv with a status column set to proposed on every row, and nothing downstream reads a row until a named person has changed it to approved, refresh or drop. That rule is better enforced than remembered. A Claude Code hook on PreToolUse can block a tool call outright by exiting with code 2, so a brief-writing step that tries to read an unapproved row simply does not run. Instructions ask; a hook refuses.

The reasons column is the part worth reading carefully. A good reason names the nearest existing page, how near it is, and what a person should check; a bad one restates the action. If the skill cannot write a reason a stranger would understand, the group is not ready, and the honest output is a row marked needs a look, not a confident guess. Our post on where the automated part should end draws the same line for content in general.

Testing it, then letting it run without you

You test a clustering skill by writing at least three cases where you already know the right answer, before you write the long instructions, and by running them again after every change. Anthropic's best-practices guide asks for exactly that order: build three evaluations that test the gaps you saw when Claude worked without the skill, measure that baseline, then write just enough instructions to pass them. It also asks you to test with every model you plan to use, because guidance that is enough for one model may be too thin for a faster one.

Testing a clustering skill, round by round

01Run the cases

three sets of phrases with known answers, checked against the map

02Find the failure

the case that came back wrong

03Change one file

the floor, the instructions or the pages table

Run all three cases again, because the fix for one case is often what breaks another.
Fig 08 · Every fix reruns every caseA change to the similarity floor, the instructions or the pages table goes back through all three test cases, because a fix for one case is often what breaks another.

For clustering, the three cases almost write themselves. One pair that must stay apart because the searcher wants a different page, such as a price and a how-to. One pair that must join although the words differ, such as a plural and a question form of the same need. And one phrase that your table says you already own, which must come back as a refresh and never as a new page. Each case is a small file in evals/, and a short script compares the map against them. When a case fails, you change the floor, the instructions or the table, and you run all three again.

Once the cases pass, the same skill runs without anyone at the keyboard. Claude Code's guide to running it programmatically covers claude -p with --output-format json and --json-schema, which returns the map's summary in a structured_output field, and it notes that a skill invoked by typing /clustering-keywords in the prompt is expanded before the run. It recommends --bare for scripted runs so the result does not depend on whatever is installed on that machine, and it says to check the field exists before using it, because a declined run returns none. Flags like these change between releases, which is one reason our AI news for content automation follows Claude Code and Search Console. A long research pass can go to a subagent, which runs in its own context window, so the main run keeps room for the map.

The schedule is the part n8n is good at. A Schedule Trigger can fire monthly, on a chosen day and hour, and an Execute Command node can start the run.

Read that node's page before you plan around it: it runs commands on the machine hosting n8n, it is disabled by default from n8n 2.0, and it is not available on n8n Cloud, so this step needs a self-hosted instance or a small server that n8n calls instead. Our comparison of Claude Code and n8n, and when to use both covers that split in full.

A worked example: a dental clinic's list and one bad merge

Here is the first month for an illustrative dental clinic, a composite rather than a client, with a keyword export of a few hundred phrases and a website of about thirty pages. The clinic's practice manager owns the approval column, and the dentist is asked about anything clinical.

The dental clinic’s first run, and the fix

  • >/clustering-keywords on the clinic’s keyword export
  • ·grouped teeth whitening cost with teeth whitening at home
  • ·test case keep apart failed before the map was shown to anyone
  • +a comment on the similarity floor saying which case forced it
  • +reference/merge-rules.md: a price phrase never joins a do-it-yourself phrase
  • +a row in the pages table for the clinic’s treatment page
  • ·all three test cases passed and the map proposed fewer pages
  • cluster-map.csv, every row proposed, waiting for the practice manager
Fig 09 · Caught by a test, not by eyeThe bad merge in version one never reached a person, because the first test case was that exact pair, and three file changes later the map proposed fewer pages, not more.

In version one, the grouping script put "teeth whitening cost" and "teeth whitening at home" in the same group. The words overlap almost entirely, so the similarity score was high. But one searcher is pricing a treatment at the clinic and the other is looking for a kit they can use without visiting one, and a single page cannot serve both without failing one of them. The draft map proposed one page called "Teeth whitening: costs and options". The first test case in evals/ was exactly that pair, marked keep apart, so the check failed before anyone saw the map.

The fix took three changes, all in files. The similarity floor went up, with a comment saying which case forced it. A line went into reference/merge-rules.md saying that a price phrase and a do-it-yourself phrase never join, whatever the score. And the pages table gained a row, because the clinic already had a treatment page that should own the price phrase, so that group became a refresh of an existing page rather than a new URL. All three cases passed on the second run and the map shrank, which is the usual direction for a skill that is working.

The practice manager then read the map in about the length of a coffee. She approved most rows, dropped two that served people outside the clinic's area, and marked one needs the dentist, a group about a procedure the clinic does not offer. The skill surfaced a question only the business could answer, and did not answer it for them.

What a clustering skill costs to keep running

Unlike the tools priced in our guide to what content automation software costs, a clustering skill has no subscription. It costs three things to keep running: the model usage of each run, the embedding provider's usage, and an hour or so a month of a person reviewing the map. With --output-format json, a scripted run reports total_cost_usd, and the Claude Code documentation is careful to call it a client-side estimate that can differ from the bill, so log it per run and compare it with the invoice. Embedding usage is priced per token on the provider's own page, and a few hundred short phrases is a small job. A clustering skill like this is one of the parts a Claude Code content automation system can include, built and documented with the rest and running on the client’s own account.

What a clustering skill costs to keep running

Monthly upkeep

  • Model usage reported per run as total_cost_usd, an estimate
  • Embedding usage a small job for a few hundred short phrases
  • Reviewing the map about an hour a month of a person
  • Keeping the table true a row for every page published or retired

Rough shares — a shape, not a measurement

Fig 10 · The table is the real costThe largest cost of a clustering skill is keeping the pages table true, because a table that still lists a retired page makes the skill propose a refresh of something that no longer exists.

The larger cost is upkeep. The pages table drifts the moment a page is published or retired without a row being changed, and a table that is wrong is worse than none, because the skill then reports a refresh of a page that no longer exists. And the reference files need the same care as code: our guide to documenting a content automation system covers keeping instruction files true after the person who wrote them moves on.

If you would rather have it built into your own repository, with the table, the scripts and the test cases set up and handed over, that is part of how we approach automating the SEO side of a website and of the wider SEO content automation we build, and our website SEO pricing page says how that work is quoted. Either way, the folder sits in your accounts and keeps working without us.

Frequently asked questions

Can a Claude Code skill call the Search Console API?

Yes, a Claude Code skill can call the Search Console API through one of its scripts, using your own credentials, because Claude Code runs on your machine with the same network access as any other program there. The script should page through results with startRow, since one request returns at most 25,000 rows and only the top ones, and stay under the API's limit of 1,200 queries a minute per site.

Does the skill need embeddings, or can Claude group the keywords itself?

The skill should use embeddings for the grouping, because a script comparing vectors gives the same groups every run, while a model reading a list can group it differently each time. Claude is better used for naming each group and writing its reason. Anthropic does not offer its own embedding model, so the embedding script calls a separate provider such as Voyage AI.

Should the skill live in the project folder or in my home folder?

A clustering skill belongs in the project folder, under .claude/skills/, because it depends on that site's own pages table and test cases, and committing it there gives the whole team the same method. A skill in your home folder loads in every project on your machine, which suits a general habit, not a method tied to one website.

Why can't the skill's name include the word claude?

The name cannot include the word claude because Anthropic reserves both "anthropic" and "claude" in skill names, alongside a 64-character limit and lowercase letters, numbers and hyphens only. A plain descriptive name such as clustering-keywords works, and Anthropic's guide suggests the verb-plus-ing form so the name says what the skill does.

How do I stop the skill from running when I have not asked for it?

Set disable-model-invocation to true in the skill's frontmatter, and Claude will only run it when someone types its slash command. That suits a clustering skill, which reads files, calls APIs and writes a new map, and should run when a person decides it is time rather than whenever a conversation happens to mention keywords.

Can n8n Cloud start a Claude Code clustering run?

Not with the Execute Command node, because n8n's own page for that node says the Cloud plan does not offer it, and self-hosted instances from version 2.0 ship with it switched off. A cloud workflow can still trigger the run on a schedule by calling a small server or a self-hosted machine that starts claude -p, and then read the structured result back.

How many test cases does a clustering skill need before I trust it?

Start with at least three test cases, the number Anthropic's skill guide asks for, chosen so each one tests a different way clustering goes wrong: two phrases that must stay apart, two that must join, and one your site already owns. Add a case every time a reviewer overrules the map for a reason that will come up again.

Where to start

Before writing any code, write the three test cases. Pick two phrases from your own list that must stay apart, two that must join, and one you already have a page for, and write down what the right answer is for each. Then make the folder with an empty SKILL.md and a pages table of every URL you have published and the one phrase each is meant to win. Those two files, the cases and the table, are what make the rest of the skill trustworthy, and both take an afternoon. The scripts are the easy part once you know what they must get right.

About the author

Shreyas Dave is the founder of Paper Eagle AI, and he still runs it. He designs Content Operating Systems for businesses with real expertise — the knowledge architecture, the content strategy and the automation that runs them, built in Claude Code and n8n, with Zapier or Make.com where they fit better. He writes from systems he has built and runs himself, including the ones behind Paper Eagle AI’s own publishing. Read more about Shreyas and how Paper Eagle AI started, or follow Shreyas Dave on LinkedIn, where he writes about content automation as he builds it.

Disclosure

This post was written by Shreyas Dave, founder of Paper Eagle AI. We sell content automation services, which is the category this article is about, so we have a commercial interest in you concluding that a system beats ad-hoc effort — read it knowing that. No tool vendor was involved in writing it, nobody paid for a mention, and there are no affiliate links anywhere on this site. Where a third-party figure appears, it’s attributed to the publisher it came from; anything we couldn’t source is written as a direction rather than a number.

Paper Eagle AI builds Content Operating Systems that turn a business’s knowledge and expertise into consistent, multi-platform content, and we deliver them as content automation services. Working as a content automation specialist, we capture what a business knows and how it sounds, set the strategy, and build the workflows that research, draft, repurpose and publish — with a named person approving every piece before it goes out. Every build runs through discovery, design, build and handoff. The system lives in the client’s own accounts, it is documented, the team is trained to run it, and the business owns it outright. We don’t write content on a retainer, and we don’t build lead generation, CRM or sales automation.

One source of thinking becomes native content for every platform a business publishes on: the founder’s LinkedIn and the company page, YouTube and Shorts, Instagram and Reels, TikTok, Reddit, Medium, newsletters, and the company’s own website, written to be found in Google and understood by AI search. Our multi-platform content automation page shows how they share one source, and our case studies document the systems behind our own publishing, file by file. You can follow the work on the company’s own channels: Paper Eagle AI on Instagram, Paper Eagle AI on YouTube, the Paper Eagle AI company page on LinkedIn, Paper Eagle AI on Substack, Paper Eagle AI on Reddit and Paper Eagle AI on Medium. Paper Eagle AI is also listed where clients can review its work: Paper Eagle AI on Clutch, Paper Eagle AI on GoodFirms and the Paper Eagle AI Google Business Profile.

Keep reading

Every keyword list turning into another near-duplicate page?

If your site keeps gaining posts that answer the same question, the missing piece is usually a record of what you already own. Tell us how your keyword research reaches a brief today, and we will show you where a clustering skill would sit in that path and what it would stop.

Start a Conversation