Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(seo-cockpit): run claude-seo's runtime with its own data folder

Agrici Danielc24f1c4e7d00
diff --git a/plugins/seo-cockpit/hooks/lib/root.ts b/plugins/seo-cockpit/hooks/lib/root.ts
index ed7470b..19c9526 100644
--- a/plugins/seo-cockpit/hooks/lib/root.ts
+++ b/plugins/seo-cockpit/hooks/lib/root.ts
@@ -76,3 +76,23 @@ export function latestVersion(names: readonly string[]): string | null {
return versions.length === 0 ? null : [...versions].sort(compareVersions).at(-1) ?? null
}
+
+/**
+ * The environment claude-seo's runtime.py must see, so it finds the Python
+ * environment claude-seo set up, not one keyed to whichever plugin is calling.
+ *
+ * runtime.py picks its folder from CLAUDE_PLUGIN_DATA, which Claude Code sets
+ * per plugin; inherited from this mod's process it names the wrong plugin.
+ * - An install (`<home>/.claude/plugins/cache/<mkt>/claude-seo/<ver>`): point
+ * it at claude-seo's own data folder, `<home>/.claude/plugins/data/claude-seo-<mkt>`,
+ * where `/seo setup` puts the environment.
+ * - A checkout or a custom folder: clear both variables, so runtime.py uses
+ * its own standalone rule (the checkout's `.venv`).
+ */
+export function runtimeEnvOf(seoRoot: string): Record<string, string> {
+ const match = /^(.*)[\\/]plugins[\\/]cache[\\/]([^\\/]+)[\\/]claude-seo[\\/][^\\/]+[\\/]?$/.exec(seoRoot)
+
+ return match === null || match[1] === undefined || match[2] === undefined
+ ? { CLAUDE_PLUGIN_DATA: '', CLAUDE_PLUGIN_ROOT: '' }
+ : { CLAUDE_PLUGIN_DATA: `${match[1]}/plugins/data/claude-seo-${match[2]}`, CLAUDE_PLUGIN_ROOT: seoRoot }
+}
diff --git a/plugins/seo-cockpit/hooks/register.ts b/plugins/seo-cockpit/hooks/register.ts
index 21cd2ce..88b0d24 100644
--- a/plugins/seo-cockpit/hooks/register.ts
+++ b/plugins/seo-cockpit/hooks/register.ts
@@ -4,7 +4,7 @@ import { auditFromPrompt, bandText, compactInstructions, economyModel, isSeoAgen
import { COLORS, htmlPage } from './lib/charts'
import { doctorText, spendText } from './lib/format'
import { classify, type PaidCall } from './lib/paid'
-import { candidatesOf, joinPath, latestVersion, MARKER } from './lib/root'
+import { candidatesOf, joinPath, latestVersion, MARKER, runtimeEnvOf } from './lib/root'
import { chooseTarget, hostOf, rowOf, ROWS, siteOfAudit, statusLine } from './lib/overview'
import { auditModel, emptyModel, gscModel, mapsModel, rankingsModel, spendModel, TABS, vitalsModel, type TabId, type TabModel } from './lib/tabs'
import { combine, isUnpriced, parseCheck, usd, type Verdict } from './lib/verdict'
@@ -108,7 +108,7 @@ async function findRoot($: EngineInterface, ctx: Ctx): Promise<string | null> {
/** Runs one of claude-seo's stdlib-only scripts with the configured Python. */
async function runScript($: EngineInterface, ctx: Ctx, seoRoot: string, script: string, args: readonly string[]) {
- return $.process.run([ctx.python, joinPath(seoRoot, 'scripts', script), ...args], { timeoutMs: 20_000 })
+ return $.process.run([ctx.python, joinPath(seoRoot, 'scripts', script), ...args], { timeoutMs: 20_000, env: runtimeEnvOf(seoRoot) })
}
/** Writes a guarded call's cost to the ledger. Never throws: the call already ran. */
@@ -278,7 +278,7 @@ async function restoreAudit($: EngineInterface, ctx: Ctx): Promise<void> {
/** Runs a claude-seo script through its managed runtime (for scripts that need its packages) and parses the JSON it prints. */
async function runtimeJson($: EngineInterface, ctx: Ctx, seoRoot: string, script: string, args: readonly string[]): Promise<{ data: unknown; error: string | null }> {
try {
- const { exitCode, stdout, stderr } = await $.process.run([ctx.python, joinPath(seoRoot, 'scripts', 'runtime.py'), 'run', script, ...args], { timeoutMs: 90_000 })
+ const { exitCode, stdout, stderr } = await $.process.run([ctx.python, joinPath(seoRoot, 'scripts', 'runtime.py'), 'run', script, ...args], { timeoutMs: 90_000, env: runtimeEnvOf(seoRoot) })
try {
return { data: JSON.parse(stdout), error: null }
diff --git a/plugins/seo-cockpit/tests/logic.test.ts b/plugins/seo-cockpit/tests/logic.test.ts
index 87fde96..3f1021a 100644
--- a/plugins/seo-cockpit/tests/logic.test.ts
+++ b/plugins/seo-cockpit/tests/logic.test.ts
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'claude-code/testing'
import { lastDays, spark, spendText } from '../hooks/lib/format'
import { classify, mcpParts, merchantEndpoints, segmentsOf } from '../hooks/lib/paid'
-import { candidatesOf, latestVersion, parentOf } from '../hooks/lib/root'
+import { candidatesOf, latestVersion, parentOf, runtimeEnvOf } from '../hooks/lib/root'
import { combine, isUnpriced, parseCheck } from '../hooks/lib/verdict'
describe('classify', () => {
@@ -121,6 +121,15 @@ describe('root', () => {
expect(latestVersion(['2.5.0-rc1', '2.5.0', '2.4.9'])).toBe('2.5.0')
})
+ test('runtime.py gets claude-seo\'s own data folder, never the calling plugin\'s', () => {
+ expect(runtimeEnvOf('/home/u/.claude/plugins/cache/agricidaniel-claude-seo/claude-seo/2.4.1')).toEqual({
+ CLAUDE_PLUGIN_DATA: '/home/u/.claude/plugins/data/claude-seo-agricidaniel-claude-seo',
+ CLAUDE_PLUGIN_ROOT: '/home/u/.claude/plugins/cache/agricidaniel-claude-seo/claude-seo/2.4.1',
+ })
+ // A checkout: clear both, so runtime.py uses the checkout's own environment.
+ expect(runtimeEnvOf('/home/u/Desktop/Skills/Public/claude-seo')).toEqual({ CLAUDE_PLUGIN_DATA: '', CLAUDE_PLUGIN_ROOT: '' })
+ })
+
test('parentOf trims trailing slashes', () => {
expect(parentOf('/a/b/')).toBe('/a')
})