> ## Documentation Index
> Fetch the complete documentation index at: https://exosphere-auto-translate-docs-20260623-1106.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

title: उदाहरण
description: "Claude Code और Agents SDK के लिए hooks कैसे सेट करें"
icon: book-open
---------------

सामान्य परिदृश्यों के लिए तैयार उदाहरण। प्रत्येक बताता है कि कैसे इंस्टॉल करें और क्या उम्मीद करें।

***

## Claude Code के लिए hooks सेट करना

Failproof AI Claude Code के साथ अपने [hooks system](https://docs.anthropic.com/en/docs/claude-code/hooks) के माध्यम से एकीकृत होता है। जब आप `failproofai policies --install` चलाते हैं, तो यह Claude Code के `settings.json` में hook commands को पंजीकृत करता है जो हर tool call पर चलते हैं।

<Steps>
  <Step title="failproofai इंस्टॉल करें">
    ```bash theme={null}
    npm install -g failproofai
    ```
  </Step>

  <Step title="सभी built-in policies को सक्षम करें">
    ```bash theme={null}
    failproofai policies --install
    ```
  </Step>

  <Step title="सत्यापित करें कि hooks पंजीकृत हैं">
    ```bash theme={null}
    cat ~/.claude/settings.json | grep failproofai
    ```

    आपको `PreToolUse`, `PostToolUse`, `Notification`, और `Stop` events के लिए hook entries दिखनी चाहिए।
  </Step>

  <Step title="Claude Code चलाएं">
    ```bash theme={null}
    claude
    ```

    Policies अब हर tool call पर स्वचालित रूप से चलती हैं। Claude को `sudo rm -rf /` चलाने के लिए कहने का प्रयास करें - यह अवरुद्ध होगा।
  </Step>
</Steps>

***

## Agents SDK के लिए hooks सेट करना

यदि आप [Agents SDK](https://docs.anthropic.com/en/docs/agents-sdk) के साथ बना रहे हैं, तो आप समान hook system को प्रोग्राम के अनुसार उपयोग कर सकते हैं।

<Steps>
  <Step title="अपने प्रोजेक्ट में failproofai इंस्टॉल करें">
    ```bash theme={null}
    npm install failproofai
    ```
  </Step>

  <Step title="अपने agent में hooks कॉन्फ़िगर करें">
    अपने agent process बनाते समय hook commands पास करें। Hooks उसी तरह चलते हैं जैसे Claude Code में - stdin/stdout JSON के माध्यम से:

    ```bash theme={null}
    failproofai --hook PreToolUse   # हर tool से पहले कहा जाता है
    failproofai --hook PostToolUse  # हर tool के बाद कहा जाता है
    ```
  </Step>

  <Step title="अपने agent के लिए एक custom policy लिखें">
    ```javascript theme={null}
    import { customPolicies, allow, deny } from "failproofai";

    customPolicies.add({
      name: "limit-to-project-dir",
      description: "Agent को project directory के अंदर रखें",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        const path = String(ctx.toolInput?.file_path ?? "");
        if (path.startsWith("/") && !path.startsWith(ctx.session?.cwd ?? "")) {
          return deny("Agent project directory तक सीमित है");
        }
        return allow();
      },
    });
    ```
  </Step>

  <Step title="custom policy को इंस्टॉल करें">
    ```bash theme={null}
    failproofai policies --install --custom ./my-agent-policies.js
    ```
  </Step>
</Steps>

***

## विनाशकारी commands को ब्लॉक करें

सबसे सामान्य सेटअप - agents को अपरिवर्तनीय नुकसान करने से रोकें।

```bash theme={null}
failproofai policies --install block-sudo block-rm-rf block-force-push block-curl-pipe-sh
```

यह क्या करता है:

* `block-sudo` - सभी `sudo` commands को अवरुद्ध करता है
* `block-rm-rf` - recursive file deletion को अवरुद्ध करता है
* `block-force-push` - `git push --force` को अवरुद्ध करता है
* `block-curl-pipe-sh` - remote scripts को shell में pipe करने को अवरुद्ध करता है

***

## Secret leakage को रोकें

Agents को tool output में credentials देखने या leak करने से रोकें।

```bash theme={null}
failproofai policies --install sanitize-api-keys sanitize-jwt sanitize-connection-strings sanitize-bearer-tokens
```

ये `PostToolUse` पर चलती हैं - एक tool चलने के बाद, वे output को agent के देखने से पहले साफ करती हैं।

***

## Agents को attention की आवश्यकता होने पर Slack alerts प्राप्त करें

Notification hook का उपयोग करके idle alerts को Slack में भेजें।

```javascript theme={null}
import { customPolicies, allow, instruct } from "failproofai";

customPolicies.add({
  name: "slack-on-idle",
  description: "जब agent input की प्रतीक्षा में हो तो Slack को alert करें",
  match: { events: ["Notification"] },
  fn: async (ctx) => {
    const webhookUrl = process.env.SLACK_WEBHOOK_URL;
    if (!webhookUrl) return allow();

    const message = String(ctx.payload?.message ?? "Agent प्रतीक्षा में है");
    const project = ctx.session?.cwd ?? "unknown";

    try {
      await fetch(webhookUrl, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          text: `*${message}*\nProject: \`${project}\``,
        }),
        signal: AbortSignal.timeout(5000),
      });
    } catch {
      // अगर Slack अप्राप्य है तो कभी भी agent को block न करें
    }

    return allow();
  },
});
```

इसे इंस्टॉल करें:

```bash theme={null}
SLACK_WEBHOOK_URL=https://hooks.slack.com/... failproofai policies --install --custom ./slack-alerts.js
```

***

## Agents को एक branch पर रखें

Agents को branches को switch करने या protected branches में push करने से रोकें।

```javascript theme={null}
import { customPolicies, allow, deny } from "failproofai";

customPolicies.add({
  name: "stay-on-branch",
  description: "Agent को अन्य branches check out करने से रोकें",
  match: { events: ["PreToolUse"] },
  fn: async (ctx) => {
    if (ctx.toolName !== "Bash") return allow();
    const cmd = String(ctx.toolInput?.command ?? "");
    if (/git\s+checkout\s+(?!-b)/.test(cmd)) {
      return deny("वर्तमान branch पर रहें। यदि आवश्यक हो तो -b के साथ एक नई branch बनाएं।");
    }
    return allow();
  },
});
```

***

## Commits से पहले tests की आवश्यकता करें

Agents को commit करने से पहले tests चलाने के लिए remind करें।

```javascript theme={null}
import { customPolicies, allow, instruct } from "failproofai";

customPolicies.add({
  name: "test-before-commit",
  description: "Agent को commit करने से पहले tests चलाने के लिए remind करें",
  match: { events: ["PreToolUse"] },
  fn: async (ctx) => {
    if (ctx.toolName !== "Bash") return allow();
    const cmd = String(ctx.toolInput?.command ?? "");
    if (/git\s+commit/.test(cmd)) {
      return instruct("Commit करने से पहले tests चलाएं। पहले `npm test` या `bun test` का उपयोग करें।");
    }
    return allow();
  },
});
```

***

## Production repo को lock down करें

एक project-level config को commit करें ताकि आपकी team के हर developer को समान policies मिलें।

अपने repo में `.failproofai/policies-config.json` बनाएं:

```json theme={null}
{
  "enabledPolicies": [
    "block-sudo",
    "block-rm-rf",
    "block-force-push",
    "block-push-master",
    "block-env-files",
    "sanitize-api-keys",
    "sanitize-jwt"
  ],
  "policyParams": {
    "block-push-master": {
      "protectedBranches": ["main", "release", "production"]
    }
  }
}
```

फिर इसे commit करें:

```bash theme={null}
git add .failproofai/policies-config.json
git commit -m "Add failproofai team policies"
```

जिस हर team member के पास failproofai installed है वह स्वचालित रूप से इन नियमों को उठा लेगा।

***

## Convention policies के साथ एक org-wide quality standard बनाएं

सबसे प्रभावशाली सेटअप: `.failproofai/policies/` को अपने repo में commit करें अपने project के अनुरूप policies के साथ। हर team member को स्वचालित रूप से ये मिलते हैं — कोई install commands नहीं, कोई config changes नहीं।

<Steps>
  <Step title="Directory बनाएं और policies जोड़ें">
    ```bash theme={null}
    mkdir -p .failproofai/policies
    ```

    ```js theme={null}
    // .failproofai/policies/team-policies.mjs
    import { customPolicies, allow, deny, instruct } from "failproofai";

    // अपनी team की preferred package manager को enforce करें
    // (या इसके बजाय built-in prefer-package-manager policy को enable करें)
    customPolicies.add({
      name: "enforce-bun",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        if (ctx.toolName !== "Bash") return allow();
        const cmd = String(ctx.toolInput?.command ?? "");
        if (/\bnpm\b/.test(cmd)) return deny("npm की बजाय bun का उपयोग करें।");
        return allow();
      },
    });

    // Agent को commit करने से पहले tests चलाने के लिए remind करें
    customPolicies.add({
      name: "test-before-commit",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        if (ctx.toolName !== "Bash") return allow();
        if (/git\s+commit/.test(ctx.toolInput?.command ?? "")) {
          return instruct("Commit करने से पहले tests चलाएं।");
        }
        return allow();
      },
    });
    ```
  </Step>

  <Step title="Git में commit करें">
    ```bash theme={null}
    git add .failproofai/policies/
    git commit -m "Add team quality policies"
    ```
  </Step>

  <Step title="Improvement जारी रखें">
    जैसे-जैसे आपकी team को नए failure modes का सामना करता है, policies जोड़ें और push करें। हर कोई अपने अगले `git pull` पर update प्राप्त करता है। ये policies एक living quality standard बन जाती हैं जो आपकी team के साथ बढ़ती हैं।
  </Step>
</Steps>

***

## अधिक उदाहरण

Repo में [`examples/`](https://github.com/failproofai/failproofai/tree/main/examples) directory में शामिल हैं:

| File                         | यह क्या दिखाता है                                                                  |
| ---------------------------- | ---------------------------------------------------------------------------------- |
| `policies-basic.js`          | Starter policies - production writes, force-push, piped scripts को block करें      |
| `policies-notification.js`   | Idle notifications और session end के लिए Slack alerts                              |
| `policies-advanced/index.js` | Transitive imports, async hooks, PostToolUse output scrubbing, Stop event handling |
