← All integrations
CLAUDE AGENT SDK · NATIVE TOOL HOOKS · PYPI v0.1.0

Verifiable decision evidence for Claude agent actions.

Keep your Claude Agent SDK tools and MCP connections. LoopGrid attaches decision-scoped policy and approval evidence to native tool hooks, prevents unauthorized execution and records the verified evidence of what ran and what happened afterward.

loopgrid-claude-agent==0.1.0 · Python 3.12 and Claude Agent SDK 0.2.165 validated · LoopGrid SDK 0.8.0 · Core 0.8.1-design-partner.

DECISION EVIDENCE FLOW
01Application authority + decision
02Versioned policy verdict
03Human review when required
04PreToolUse authorization
05PostToolUse + actual receipt
06Signed evidence + independent verification

Claude remains native. Evidence becomes verifiable. LoopGrid Core signs and chains the captured record; the host supplies trustworthy reviewer and downstream-outcome evidence.

01 · INSTALL

Install the native Claude Agent SDK integration.

pip install loopgrid-claude-agent==0.1.0

For Python 3.11+, this package depends on claude-agent-sdk>=0.2.165,<0.3 and loopgrid>=0.8.0,<0.9. Point it at a LoopGrid Core workspace; no changes to Claude's model or MCP tools are required. The published source repository ↗ includes sandbox examples and a security contract.

02 · QUICKSTART

Bind one authorized action to Claude's native hooks.

Your trusted application starts the decision with the exact tool name and expected arguments. The policy verdict belongs to your application, not to Claude's response. The example below assumes a running LoopGrid Core and a workspace you have already created.

from loopgrid import LoopGrid
from loopgrid_claude_agent import LoopGridClaudeAgent

workspace_id = "YOUR_EXISTING_WORKSPACE_ID"
core = LoopGrid(base_url="http://127.0.0.1:8000", workspace_id=workspace_id)
bridge = LoopGridClaudeAgent(client=core, workspace_id=workspace_id, agent_id="refund-agent")

decision_id = bridge.start_decision(
    decision_type="refund_simulation",
    agent={"id": "refund-agent", "version": "1"},
    authority={"acting_for": "sandbox", "scope": ["refund:simulate"]},
    model={"provider": "anthropic", "name": "claude-agent-sdk"},
    context={"prompt_version": "refund-v1"},
    proposed_action={
        "tool": "mcp__loopgrid_sandbox__sandbox_refund",
        "arguments": {"amount": 25},
    },
    policy={"policy_id": "refund-policy", "version": "1", "decision": "auto_allowed"},
)["decision_id"]

hooks = bridge.hooks(decision_id)
# Provide your application's in-process MCP server to the native SDK options.
options = hooks.options(mcp_servers={"loopgrid_sandbox": your_mcp_server})

your_mcp_server is a placeholder for the in-process MCP server your application provides. For full workspace setup, a real MCP sandbox tool and signed verification assertions, see the complete Claude runtime example ↗. It requires authenticated Claude API access and available credits.

from claude_agent_sdk import ClaudeSDKClient

async with ClaudeSDKClient(options=options) as agent:
    await agent.query("Simulate the authorized refund once using the sandbox tool.")
    async for message in hooks.observe_messages(agent.receive_response()):
        pass

# Separately verify an actual receipt from the downstream sandbox ledger.
bridge.record_observed_outcome(
    decision_id,
    observer="sandbox-ledger",
    receipt_id=verified_receipt["id"],
    outcome=verified_receipt,
)
record = bridge.get_decision(decision_id)
print(record["verification"]["valid"])

verified_receipt must come from your actual sandbox or system-of-record response. Do not treat Claude's message as independent proof of an external action. Use the deterministic Core-backed hook example ↗ when you want to test without Claude API credits.

03 · NATIVE TOOL LIFECYCLE

Enforce before execution. Record what happened after.

01Trusted decision and policy

start_decision() creates decision-scoped authority, arguments and versioned policy evidence in Core.

02Pre-tool enforcement

PreToolUse matches the exact tool name and committed arguments. Unknown, unapproved or repeated calls are denied before execution.

03Tool result or failure

PostToolUse and PostToolUseFailure correlate tool-call IDs with the resulting evidence. Model output is captured separately.

04Observed downstream outcome

record_observed_outcome() accepts a host-verified receipt after tool-result evidence is persisted; it does not infer success from model text.

05Independent verification

LoopGrid Core produces Ed25519-signed, SHA-256-chained evidence for inspection, export and independent verification.

04 · POLICY + HUMAN REVIEW

Bring delegated authority and approval to tool execution.

A decision may be auto_allowed, human_approval_required, or blocked. For sensitive actions, your application authenticates the reviewer and records the review with record_human_review(), or supplies a host-owned asynchronous approval_handler returning a ReviewVerdict. A model-generated approval claim cannot substitute for a real reviewer.

Blocked or missing approvalExecution denied before the tool runs.
Rejected reviewAction denied; human-rejection evidence recorded.
Approved reviewOnly the exact authorized tool call may proceed within its call budget.
Argument mismatch or replayAction denied; no second side effect is authorized.

Review the native hook / evidence contract ↗ and trust model ↗ for deployment details.

05 · DURABILITY + RECOVERY

Persist authorization and reconcile uncertain outcomes.

The optional local SQLite mode preserves consumed authorizations and execution claims across worker restarts. It protects against repeated execution attempts and records post-execution evidence-write failures as reconciliation work rather than falsely marking an action complete.

from loopgrid_claude_agent import LoopGridClaudeAgent

bridge = LoopGridClaudeAgent.with_sqlite(
    client=core,
    workspace_id=workspace_id,
    agent_id="refund-agent",
    sqlite_path="./loopgrid-claude-authorizations.db",
)

pending = bridge.pending_reconciliations()
SQLite durability is designed for workers sharing the same local database. Distributed hosts must provide coordinated authorization storage. If the action ran but the evidence write failed, verify the downstream outcome before any retry; do not fabricate a completion event.
06 · RELEASE VALIDATION

Tested security behavior and signed LoopGrid Core evidence.

Windows SDK tests59/59 automated tests passed with Claude Agent SDK 0.2.165 and Python 3.12
Real Core evidenceCore 0.8.1-design-partner · deterministic SDK hook callbacks · evidence_complete · signed verification valid
Security tests6/6 Core-backed scenarios: blocked, missing/rejected approval, approved action, wrong arguments and evidence-write failure
DurabilitySQLite restart, single authorized sandbox execution, replay denial and downstream reconciliation passed against Core
DistributionGitHub Actions release, PyPI Trusted Publishing and clean public PyPI installation passed

These security and Core-backed tests use deterministic native hook inputs and safe simulated actions. The separate model-driven Claude → MCP runtime test has not yet completed because the Anthropic account lacked API credits. See the full validation record ↗ for exact test scope.

CLAUDE AGENT SDK + LOOPGRID

Keep Claude's tool runtime. Add verifiable decision evidence.

Link the policy, human review, exact tool call, verified downstream receipt and signed evidence to one decision.