如何用 Claude Code 進行 PageSpeed SEO 稽核而不產生未審核的網站變更
Claude Code 能把 PageSpeed 結果對應到程式碼庫的範本、元件與資產流程,但它不應成為自動修復機器人。本流程把證據、計畫、程式碼 diff 與重新測量切成可檢閱的狀態:稽核是唯讀;任何網站變更都要在程式碼擁有者核准後才開始。
將本文交給 Claude Code 安裝工作流程
Read [THIS ARTICLE URL] and install its project-local PageSpeed audit workflow.
Inspect CLAUDE.md, CLAUDE.local.md, .claude rules, and project conventions first.
Explain the destination before writing. Create only:
.claude/skills/pagespeed-evidence/SKILL.md
.claude/skills/pagespeed-evidence/scripts/pagespeed_evidence.py
.claude/rules/page-speed-audits.md
Copy the complete code blocks from the article. Do not change application code,
package files, lock files, CI, infrastructure, or deployment configuration.
Do not call PageSpeed Insights or inspect public URLs. Run a Python syntax
check, report the paths, and explain PAGESPEED_API_KEY setup without requesting
or displaying its value. Stop after installation and verification.
CLAUDE.md與.claude是持久專案指示,不是技術性安全邊界。若必須阻止一類工具動作,依現行官方文件另外設定 Claude Code 權限或 PreToolUse hooks。
完成契約與程式碼庫邊界
| 項目 | 完成條件 |
|---|---|
| 對象 | 在網站程式碼庫工作的開發者、SEO 負責人或技術內容擁有者 |
| 成果 | 專案內 Skill、被 Git 忽略的證據目錄、待核准的實作簡報 |
| 輸入 | 公開 URL、URL 檔案、或具樣本上限的 sitemap |
| 完成 | raw 回應與 |
先建立唯一可寫入的證據位置:
mkdir -p reports/pagespeed
printf 'reports/pagespeed/
' >> .gitignore
git check-ignore -v reports/pagespeed/example/report.md
寫入 .claude/rules/page-speed-audits.md 的政策
# PageSpeed audit policy
- PageSpeed work starts as read-only evidence collection. Write audit output only under reports/pagespeed/, which must stay ignored by Git.
- Read PAGESPEED_API_KEY only from an approved local environment or secret mechanism. Never print it, add it to a command transcript, write it to a report, or commit it.
- Do not edit application source, content, build files, CI, infrastructure, deployment configuration, or a CMS while collecting or interpreting an audit.
- After an audit, create an implementation brief that names evidence, candidate files, risk, tests, acceptance criteria, and rollback condition. Wait for explicit approval before making a diff.
- Never deploy. After an approved implementation, show the Git diff and run only agreed local validation commands.
建立證據 Skill,而不是修復機器人
Skill 必須先讀取以上政策,只從本機環境讀取PAGESPEED_API_KEY,只對公開 PageSpeed Insights 與 sitemap 做 GET,且只寫入reports/pagespeed/。它要測試mobile和desktop,保留 raw JSON,將 Lighthouse 標為實驗室資料,並在 API 回傳時才分別標示頁面及網域 CrUX。
python3 .claude/skills/pagespeed-evidence/scripts/pagespeed_evidence.py \
--url "https://www.example.com/" \
--out reports/pagespeed/homepage-baseline
預期產生report.md、summary.json與行動版、桌面版 raw JSON。git status --short不應顯示報告成果物。403 通常是 API 設定或金鑰限制;空白欄位資料代表 API 沒有回傳合格 CrUX,不是 runner 錯誤。
證據先於實作
稽核後的第一次要求仍然唯讀:引用報告列或 raw 回應,列出候選範本、元件、資產工具或設定檔及理由,提出最小安全變更,並包含預期效益、風險、本機驗證、生產接受條件、回滾條件與不確定性。不可編輯、格式化、改依賴、寫測試或部署。
只有擁有者核准單一項目後,才允許改動已命名的路徑。Claude Code 要先重述接受與回滾條件、顯示git diff、執行同意的本機測試,且不 commit、push、建立 PR 或部署。測試成功不等於 Core Web Vitals 已改善;請在預覽或核准發布後以相同範圍重測。
驗證清單
- [ ] Skill 位於
.claude/skills/pagespeed-evidence/SKILL.md。 - [ ] 程式碼庫有政策和被忽略的
reports/pagespeed/位置。 - [ ] API 金鑰只在核准的本機祕密環境。
- [ ] 每個 URL 有 mobile/desktop、raw JSON、最終 URL 和失敗紀錄。
- [ ] Lighthouse、頁面 CrUX、網域 CrUX 分別標示。
- [ ] Claude Code 編輯前先產生實作簡報。
- [ ] 核准變更有小型 diff、測試、接受條件和回滾條件,且不部署。
常見問題
CLAUDE.md 足以阻止 Claude Code 改檔嗎?
不足。它是重要持久指示,不是強制機制。必須技術性阻止動作時,使用團隊核准的權限和 hooks;仍應保留政策,讓人和代理都能理解預期操作模式。
Author: Julian Mercer,Auspia Technical SEO Practitioner。Julian 專注於從 SEO 發現到受檢閱網站變更之間保留清楚證據的技術流程。