Metadata-Version: 2.5
Name: tenet-claude-agent-sdk
Version: 0.1.0
Summary: Tenet Guardrails for the Claude Agent SDK: hooks that judge prompts, tool calls and tool results with the Tenet judge
Project-URL: Homepage, https://tenetlabs.com
Project-URL: Documentation, https://docs.tenetlabs.com/guides/claude-agent-sdk
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: claude-agent-sdk,compliance,governance,guardrails,hooks
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Requires-Python: <3.14,>=3.11
Requires-Dist: claude-agent-sdk<0.3.0,>=0.2.187
Requires-Dist: tenet-client<0.8.0,>=0.7.7
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff==0.15.12; extra == 'dev'
Description-Content-Type: text/markdown

# tenet-claude-agent-sdk

Tenet Guardrails for the [Claude Agent SDK](https://docs.claude.com/en/docs/agent-sdk/python).
It provides hook callbacks that judge the user's prompt and every tool call, before and after it
runs, with the Tenet judge. It is built on [`tenet-client`](../tenet-client).

```bash
pip install tenet-claude-agent-sdk
export TENET_API_KEY="sk_tenet_..."
```

## Quickstart

```python
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
from tenet_client import TenetCloudJudgeClient
from tenet_claude_agent_sdk import TenetHooks

judge = TenetCloudJudgeClient.from_env()  # once per process
judge.warmup()
tenet = TenetHooks(judge)

options = ClaudeAgentOptions(
    mcp_servers={"hr": hr_server},
    hooks=tenet.hooks(),
)

async with ClaudeSDKClient(options=options) as client:
    await client.query("find senior Python engineers in NYC")
    async for message in client.receive_response():
        print(message)
```

| Hook | Tenet phase | Held outcome (block, review, judge down) |
|---|---|---|
| `UserPromptSubmit` | `agent_input` | the prompt is blocked before Claude sees it |
| `PreToolUse` | `tool_pre` | `permissionDecision: "deny"`, with the reason; Claude reads it and can recover |
| `PostToolUse` | `tool_post` | the turn ends (`continue: false`) before Claude reasons over the result |
| `Stop` (opt-in) | `agent_output` | Claude is sent back once to revise its reply |

Hooks run in every permission mode, `bypassPermissions` included. When the judge allows a call,
the hook returns `{}` rather than `"allow"`, so your own permission rules and `can_use_tool` still
apply.

## Outcomes and defaults

```python
TenetHooks(
    judge,
    on_block="deny",
    on_review="deny",           # "ask": route the call to can_use_tool / the permission prompt
    on_unavailable="deny",      # judge unreachable or timed out: fail closed
    tool_matcher="mcp__hr__.*", # judge only these tools; None = every tool
    surface_by_tool={"mcp__hr__send_outreach": "candidate_outreach"},
    check_final_reply=False,    # True: also judge the final reply on Stop
)
```

Use `on_review="ask"` to put a person in the loop. The call goes to the SDK's permission flow,
with the verdict's reason, and your `can_use_tool` callback decides. `"ask"` only applies to
`PreToolUse`; other hooks treat it as `"deny"`.

To combine Tenet with your own hooks, pass them in: `tenet.hooks(my_hooks)`. Tenet's matchers are
added after yours.

## Gotchas

- **`PreToolUse` is where you stop data.** `PostToolUse` runs after the tool has run. The SDK cannot
  reliably replace a built-in tool's result, so a held result ends the turn rather than rewriting it.
- **`Stop` fires after the reply exists.** If you stream messages to your user, they may already have
  seen it. Leave `check_final_reply` off unless you buffer the reply until the run completes.
- **Tool phases carry the user's ask** from the same session's `UserPromptSubmit`. If you turn
  `check_prompts` off, the judge only sees the tool arguments.
- **Construct the judge client once.** It holds the token cache and connection pool.

Tested against `claude-agent-sdk` 0.2.187+ (0.2.x) and `tenet-client` 0.7.7+.
