jpskill.com
🛠️ 開発・MCP コミュニティ

guardrails

コードの作成、修正、レビュー、デバッグ時に、品質検証を行い、信頼性を向上させるために活用できる、開発ライフサイクルに組み込まれた安全策を提供するSkill。

📜 元の英語説明(参考)

Code quality verification gates wired into the agent lifecycle. Use this skill whenever writing, modifying, reviewing, or debugging code — including new features, bug fixes, refactors, troubleshooting, CI/CD setup, or project bootstrapping. Also use when the user mentions "quality", "testing strategy", "CI pipeline", "guardrails", "debugging", or asks how to improve code reliability. If you're writing code or trying to understand why code isn't working, this skill applies.

🇯🇵 日本人クリエイター向け解説

一言でいうと

コードの作成、修正、レビュー、デバッグ時に、品質検証を行い、信頼性を向上させるために活用できる、開発ライフサイクルに組み込まれた安全策を提供するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o guardrails.zip https://jpskill.com/download/9628.zip && unzip -o guardrails.zip && rm guardrails.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9628.zip -OutFile "$d\guardrails.zip"; Expand-Archive "$d\guardrails.zip" -DestinationPath $d -Force; ri "$d\guardrails.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して guardrails.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → guardrails フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Guardrails

エージェントがチェックに合格するまで処理を進めるのを阻止する検証ゲートです。エージェントはすでに、lint、テスト、型チェック、セキュリティスキャンが何かを知っています。このスキルは、これらの概念を再教育するものではありません。代わりに、以下を指定します。

  • いつ 各チェックがエージェントのライフサイクルで実行されるか(進行を阻止するフック)
  • 行き詰まったときに何をすべきか(再試行ではなく診断エスカレーション)
  • 何に触れてはいけないか(構成保護、高リスクアクションゲーティング)
  • どのように知識を蓄積するか(教訓、エージェントツールライブラリ)

これらは、コーディングエージェントが指示なしには示さないであろう動作です。それ以外のすべて、つまり、どのリンターを使用するか、単体テストをどのように構成するかは、エージェントがトレーニングからすでに知っており、プロジェクトの既存の構成から発見します。

バンドルされたリソース: references/tool-building.md には、診断ツールと表記カタログが、実例付きで含まれています。references/language-defaults.md は、エコシステムごとのツール選択のためのルックアップテーブルです。これらは、指示されたときに読み、積極的に読まないでください。


スコープ

すべてのチェックがすべてのプロジェクトに適用されるわけではありません。共通のベースはどこにでも適用されます:lint、format、types、SAST、依存関係監査、シークレットスキャン、デッドコード検出、重複コード検出、カバレッジ、単体テスト。それを超えて、プロジェクトタイプごとにレイヤーを追加します。

  • バックエンド / API: 統合テスト。通常:property-based、contract、performance。
  • フロントエンド: 統合テスト。通常:screenshot、E2E、accessibility。
  • フルスタック: 統合テスト。通常:screenshot、E2E、contract、accessibility。
  • ライブラリ / SDK: 通常:property-based、mutation。
  • データパイプライン: 統合テスト。通常:property-based、performance。
  • インフラストラクチャ / IaC: 統合テスト(plan/apply validation)。

プロジェクトが成熟するにつれてスケールアップします。プロトタイプには共通のベースが必要です。ユーザーにサービスを提供する本番システムには、フルスイートが必要です。

共通のベース: lint、format、types、SAST、依存関係監査、シークレットスキャン、デッドコード検出、重複コード検出、カバレッジ、単体テスト。エコシステムごとのデッドコードおよび重複コードツールは、references/language-defaults.md にリストされています。


ライフサイクルフック

上記のすべては単なるガイダンスであり、エージェントはそれに従うかもしれないし、従わないかもしれません。以下のフックは、ガードレールを現実にするものです。それらは、チェックに合格するまでエージェントが処理を進めるのを阻止します。この区別は重要です。20msで実行され、ビルドを失敗させるlintルールは、エージェントに具体的で明確なフィードバックを与えます。スキルファイル内の散文的な指示は、コンテキストウィンドウにあり、他のすべてのものと注意を奪い合います。

テストランナーの検出

エンフォースメントシステムは、ターゲットプロジェクトに2つのコマンドを必要とします。1つは高速、もう1つはフルです。

高速チェック — 数秒で実行されます。すべてのエージェント停止時に発火します。対象:format check、lint、type check、単体テスト。

フルスイート — すべてのコミットの前に実行されます。対象:高速チェックのすべてに加えて、統合テスト、property tests、シークレットスキャン、デッドコード検出、重複コード検出、カバレッジフロア。

発見し、押し付けない。 すべてのエコシステムには独自の慣習があります:npm scripts (npm testnpm run test:unit)、Makefile targets (make testmake check)、Go commands (go test ./...)、pytest (pytest tests/unit)、bun scripts、Cargoなど。SessionStart中に、package.json scripts、Makefile targets、CI workflow steps、およびREADME instructionsを調べて、プロジェクトがすでに使用しているものを探します。プロジェクトの既存のランナーに適応し、その横に新しいランナーを作成しないでください。

テストランナーがまったく存在しない場合は、プロジェクトのネイティブツールを使用して作成します。ツールの選択については、references/language-defaults.md を参照してください。ランナーは、失敗時にゼロ以外の終了コードで終了する必要があります。

SessionStart

エージェントの起動時に発火します。何かに触れる前に、検出とベースラインを行います。

  • gitの状態(HEAD SHA、ワーキングツリーの状態)をセッションのベースラインとして記録します。
  • 既存のガードレールを発見します:構成ファイル、CIパイプライン、テストディレクトリを調べます。プロジェクトタイプ(Scopeセクション)を特定し、どのチェックが適用されるかを判断します。
  • 既存のテストファイルを読んで、命名、構造、アサーションスタイル、モック、フィクスチャなどの慣習を学びます。それらに合わせます。
  • LESSONS_LEARNED.md が存在する場合は読みます。プロジェクト固有の教訓を適用します。
  • script/agent-tools/ を確認します。ディレクトリと説明コメントを読んで、以前のセッションからどのような診断ツールが利用可能かを知ります。

既存の慣習に従う。 プロジェクトにツールやパターンがすでに存在する場合は、このスキルと矛盾する場合でも、それらに従います。明示的なユーザーの承認なしに、ツールやフレームワークを切り替えないでください。

Stop

エージェントが制御を返すたびに発火します。検証なしに成功を宣言することを防ぎます。

  • 高速チェックを実行します。失敗した場合はブロックします。
  • 本番コードが変更された場合は、テストも変更されたことを確認します。テストされていないコードは、「正しく見える」かどうかに関係なく、検証されていないコードです。

スラッシングサーキットブレーカー。 高速チェックが失敗し、エージェントがすでに同じ修正を2回試行している場合、3回目の直接的な修正を試行することはできません。

  1. 1回目の試行が失敗した後: 直接的な修正を試みます。通常。
  2. 2回目の試行が失敗した後: 停止します。診断ツールを作成するか、表記に切り替えます(references/tool-building.md を読んでください)。2回の失敗した試行は、エージェントの問題のモデルが間違っていることを意味します。同じコードを再度読み取ると、同じ間違ったモデルが生成されます。新しい情報または異なる表現がループを中断します。
  3. 3回目の試行が失敗した後(診断付き): 完全に停止します。ユーザーに報告します:何が失敗しているか、何が試みられたか、診断で何が明らかになったか、なぜ収束しないのか。

ブレーカーは、ユーザーが新しい指示を提供するとリセットされます。有用な診断を script/agent-tools/ に永続化します。

完了チェック。 高速チェックに合格した後、タスクリストを確認します。計画された作業項目が残っており、ブロックされていない場合は、次のスライスに進みます。引き渡さないでください。引き渡すのは、すべての項目が完了したか、サーキットブレーカーが作動したか、コンテキストが不足している場合のみです(その場合は、完了したスライスをコミットし、残りの項目を報告します)。

スライスで作業しますが、ジョブを完了します。 V

(原文はここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Guardrails

Verification gates that block the agent from proceeding until checks pass. The agent already knows what linting, testing, type checking, and security scanning are. This skill doesn't re-teach those concepts. Instead, it specifies:

  • When each check runs in the agent lifecycle (hooks that block progress)
  • What to do when stuck (diagnostic escalation instead of retrying)
  • What not to touch (config protection, high-risk action gating)
  • How to accumulate knowledge (lessons learned, agent tool library)

These are the behaviors a coding agent wouldn't exhibit without being told. Everything else — which linter to use, how to structure a unit test — the agent already knows from training and discovers from the project's existing config.

Bundled resources: references/tool-building.md contains the diagnostic tool and notation catalogs with worked examples. references/language-defaults.md is a lookup table for tool selection by ecosystem. Read these when directed, not proactively.


Scope

Not every check applies to every project. The common base applies everywhere: lint, format, types, SAST, dependency audit, secrets scan, dead code detection, duplicate code detection, coverage, unit tests. Beyond that, add layers by project type:

  • Backend / API: integration tests. Usually: property-based, contract, performance.
  • Frontend: integration tests. Usually: screenshot, E2E, accessibility.
  • Full-stack: integration tests. Usually: screenshot, E2E, contract, accessibility.
  • Library / SDK: Usually: property-based, mutation.
  • Data pipeline: integration tests. Usually: property-based, performance.
  • Infrastructure / IaC: integration tests (plan/apply validation).

Scale up as the project matures. A prototype needs the common base. A production system serving users needs the full suite.

Common base: lint, format, types, SAST, dependency audit, secrets scan, dead code detection, duplicate code detection, coverage, unit tests. Dead code and duplicate code tools by ecosystem are listed in references/language-defaults.md.


Lifecycle Hooks

Everything above is just guidance — the agent might follow it, might not. The hooks below are what make guardrails real. They block the agent from proceeding until checks pass. The distinction matters: a lint rule that runs in 20ms and fails the build gives the agent concrete, unambiguous feedback. A prose instruction in a skill file sits in the context window competing for attention with everything else.

Test Runner Discovery

The enforcement system needs two commands in the target project — one fast, one full:

Fast check — Runs in seconds. Fires on every agent stop. Covers: format check, lint, type check, unit tests.

Full suite — Runs before every commit. Covers: everything in the fast check plus integration tests, property tests, secrets scan, dead code detection, duplicate code detection, coverage floor.

Discover, don't impose. Every ecosystem has its own convention: npm scripts (npm test, npm run test:unit), Makefile targets (make test, make check), Go commands (go test ./...), pytest (pytest tests/unit), bun scripts, Cargo, etc. During SessionStart, find what the project already uses by inspecting package.json scripts, Makefile targets, CI workflow steps, and README instructions. Adapt to the project's existing runner — don't create a new one alongside it.

If no test runner exists at all, create one using the project's native tooling. Consult references/language-defaults.md for tool selection. The runner must exit non-zero on failure.

SessionStart

Fires when the agent boots up. Discovery and baseline before touching anything.

  • Record git state (HEAD SHA, working tree status) as a session baseline.
  • Discover existing guardrails: inspect config files, CI pipelines, test directories. Identify the project type (Scope section) and determine which checks apply.
  • Read existing test files to learn conventions — naming, structure, assertion style, mocking, fixtures. Match them.
  • Read LESSONS_LEARNED.md if it exists. Apply project-specific lessons.
  • Check for script/agent-tools/. Read the directory and description comments to know what diagnostic tools are available from previous sessions.

Defer to existing conventions. When the project has tooling or patterns in place, follow them — even when they conflict with this skill. Do not switch tools or frameworks without explicit user approval.

Stop

Fires every time the agent returns control. Prevents declaring success without verification.

  • Run the fast check. Block if it fails.
  • If production code changed, verify tests also changed. Untested code is unverified code, regardless of whether it "looks right."

Thrashing circuit breaker. If the fast check fails and the agent has already attempted the same fix twice, it cannot try a third direct fix:

  1. After attempt 1 fails: Try a direct fix. Normal.
  2. After attempt 2 fails: Stop. Build a diagnostic tool or switch to a notation (read references/tool-building.md). Two failed attempts means the agent's model of the problem is wrong — re-reading the same code produces the same wrong model. New information or a different representation breaks the loop.
  3. After attempt 3 fails (with diagnostic): Stop entirely. Report to the user: what's failing, what was tried, what the diagnostic revealed, why it isn't converging.

The breaker resets when the user provides new direction. Persist useful diagnostics to script/agent-tools/.

Completion check. After the fast check passes, check your task list. If planned work items remain and you are not blocked, continue to the next slice — do not hand off. Hand off only when: all items are done, the circuit breaker fired, or context is running low (in which case, commit completed slices and report remaining items).

Work in slices, but finish the job. Verify frequently — a good slice is 1-3 production files plus tests. An agent that writes 15 files then discovers a type error in file 3 has wasted 4-15. But verifying a slice is not completing the task. Do not hand off to the user until all planned work items are done or you are explicitly blocked.

Commit (PreToolUse + git hooks)

Fires on any git commit, whether from the agent or a human. Same enforcement for both.

  • Run the full suite. Block if it fails.
  • Secrets scan on staged files.
  • Verify commit message follows project conventions.
  • Integration/deployment check: Verify the change is reachable, not just correct. Code that passes tests but isn't wired into the application is a deployment gap. Confirm: new modules imported? Routes registered? Migrations included? Entry points updated? If nothing invokes the new code, that's a failure even with passing tests.

Tool Building and Notation

When direct fixes fail, the agent needs new information or a different problem representation. Read references/tool-building.md for the full catalog of diagnostic tools, notations, and three worked examples.

The circuit breaker (Stop hook) mandates reading this reference after 2 failed attempts. But the best use is proactive: recognize the problem shape during planning and build scaffolding before writing code. Common patterns:

  • Modifying a function's interface → build a call site inventory first
  • Complex conditional logic (>3 booleans or >4 branches) → build a decision matrix
  • State machine behavior → build a state transition table
  • Data transformation pipeline → trace sample values through each stage
  • Unfamiliar codebase area → build a codebase index before editing

Diagnostic tools often graduate into permanent infrastructure — reproduction scripts become test cases, schema checkers become health checks, dependency mappers feed the integration check. Building a diagnostic tool is not a detour; it's often the most direct path to completing the task.


Config Protection

The agent does not edit its own guardrail configuration. An agent under pressure to make tests pass has an incentive to weaken the tests rather than fix the code. Block the agent from modifying: test scripts, lint/format/type config, CI definitions, pre-commit config, and coverage thresholds. If config needs changing, propose it to the user.


High-Risk Action Gating

Some operations have blast radius beyond the current code change. Even if the user's request implies them, the agent stops and asks because these are irreversible or affect systems beyond the codebase:

  • Destructive data operations (DROP TABLE, deleting records, truncating logs)
  • Permission and access changes (auth rules, IAM policies, CORS)
  • Deployment actions (pushing to production, triggering deploys, scaling)
  • Bulk or irreversible operations (mass updates, migrations, force-pushes)
  • Financial or billing changes (anything committing to spend)

Describe the operation and blast radius, then wait for confirmation.


Lessons Learned

The agent accumulates project-specific knowledge across sessions. Without a persistent record, each session starts from zero and risks repeating the same mistakes.

Maintain LESSONS_LEARNED.md in the project root. Append an entry when encountering: a guardrail failure requiring multiple attempts, a non-obvious project convention, a surprising tool behavior, a deployment gap tests didn't catch, a thrashing episode, or a diagnostic tool that proved useful. Each entry: Date, Context, What happened, Resolution, Rule (concise directive for future sessions).

Commit to version control. If a lesson reveals a missing guardrail, propose adding one — don't just document the workaround.


Agent Responsibilities (Not Hookable)

Behaviors the agent follows because the reasoning is sound, not because a hook enforces them.

Planning: Define completion criteria — what "done" looks like for this task (files changed, tests added, routes wired, etc.). Decide testing layers before writing code. Check problem shape against the proactive table in references/tool-building.md. Assess security relevance.

Code writing: Format and type-check incrementally. If the same type error reappears after one fix, that signals a structural misunderstanding — switch to a notation rather than continuing to guess.

Handoff / PR: Report what was verified, which layers were skipped and why, security findings, and coverage delta. Do not present work as complete if any hook failed.