Skip to main content

Claude Code Integration

Add Treeship verification to your Claude Code (Anthropic) agents to create tamper-proof records of every action.

Setup

pip install treeship-sdk anthropic

Basic Integration

Wrap your Claude Code agent’s tool calls with Treeship attestations:
from anthropic import Anthropic
from treeship_sdk import Treeship

client = Anthropic()
ts = Treeship()

def run_agent_with_verification(user_message: str):
    # Run Claude Code
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=4096,
        messages=[{"role": "user", "content": user_message}]
    )
    
    # Attest the action
    attestation = ts.attest(
        agent="claude-code-agent",
        action=f"Processed: {user_message[:100]}",
        inputs_hash=ts.hash({
            "user_message": user_message,
            "model": "claude-sonnet-4-20250514"
        })
    )
    
    return {
        "response": response.content[0].text,
        "verification_url": attestation.verify_url
    }

Tool Use Verification

For agents using tools, attest each tool execution:
def execute_tool_with_verification(tool_name: str, tool_input: dict):
    # Execute the tool
    result = execute_tool(tool_name, tool_input)
    
    # Attest the tool execution
    attestation = ts.attest(
        agent="claude-code-agent",
        action=f"Tool: {tool_name}",
        inputs_hash=ts.hash(tool_input),
        metadata={
            "tool_name": tool_name,
            "success": result.success
        }
    )
    
    return result, attestation.verify_url

MCP Server Integration

If you’re using Model Context Protocol (MCP) servers with Claude Code:
from treeship_sdk import Treeship

ts = Treeship()

class VerifiedMCPServer:
    def __init__(self, server_name: str):
        self.server_name = server_name
    
    async def call_tool(self, tool_name: str, arguments: dict):
        # Execute MCP tool
        result = await self.mcp_client.call_tool(tool_name, arguments)
        
        # Attest the MCP call
        ts.attest(
            agent=f"mcp-{self.server_name}",
            action=f"MCP tool: {tool_name}",
            inputs_hash=ts.hash(arguments)
        )
        
        return result

Verification Page

After integration, every action creates a verification URL like:
https://treeship.dev/verify/claude-code-agent/abc123
Share this with clients to prove exactly what your agent did.

Next Steps