{"id":47685652,"url":"https://github.com/datashaman/claude-agent-sdk","last_synced_at":"2026-04-02T14:48:56.688Z","repository":{"id":346726353,"uuid":"1191318025","full_name":"datashaman/claude-agent-sdk","owner":"datashaman","description":"PHP SDK for building autonomous agents powered by Claude","archived":false,"fork":false,"pushed_at":"2026-03-25T09:19:42.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-26T10:46:49.311Z","etag":null,"topics":["agent","ai","anthropic","claude","composer","llm","mcp","php","sdk","streaming"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datashaman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-25T05:54:57.000Z","updated_at":"2026-03-25T08:50:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/datashaman/claude-agent-sdk","commit_stats":null,"previous_names":["datashaman/claude-agent-sdk"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/datashaman/claude-agent-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Fclaude-agent-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Fclaude-agent-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Fclaude-agent-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Fclaude-agent-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datashaman","download_url":"https://codeload.github.com/datashaman/claude-agent-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Fclaude-agent-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31308446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","ai","anthropic","claude","composer","llm","mcp","php","sdk","streaming"],"created_at":"2026-04-02T14:48:55.184Z","updated_at":"2026-04-02T14:48:56.682Z","avatar_url":"https://github.com/datashaman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Claude Agent SDK for PHP\n\nPHP SDK for building autonomous agents powered by Claude. This is the PHP equivalent of the official [TypeScript](https://github.com/anthropics/claude-agent-sdk-typescript) and [Python](https://github.com/anthropics/claude-agent-sdk-python) SDKs.\n\n## Requirements\n\n- PHP 8.2+\n- [Claude CLI](https://docs.anthropic.com/en/docs/claude-code/overview) installed and authenticated\n\n### Web Server Authentication (PHP-FPM)\n\nWhen running under a web server (PHP-FPM with Nginx/Valet/etc.), the Claude CLI cannot access the macOS login keychain used by `claude login`. You must set up a file-based authentication token:\n\n```bash\nclaude setup-token\n```\n\nThis creates a long-lived token tied to your **Claude Code subscription** that works without keychain access. Add the token to your `.env`:\n\n```env\nCLAUDE_CLI_PATH=/path/to/claude\nCLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-...\n```\n\nThe SDK automatically passes `CLAUDE_*` and `ANTHROPIC_*` environment variables to the CLI process, with one important exception:\n\n### Environment Variable Exclusions\n\n`ANTHROPIC_API_KEY` is **excluded by default**. When present, it causes the CLI to use direct API access (pay-per-use) instead of your Claude Code subscription. Since this SDK is designed to drive the Claude CLI with subscription-based auth, passing the API key would bypass your subscription and incur unexpected charges.\n\nDefault exclusions are defined in `ClaudeAgentOptions::DEFAULT_EXCLUDED_ENV_KEYS`.\n\nTo override the exclusion list (e.g. if you explicitly want API key auth):\n\n```php\n$options = ClaudeAgentOptions::create()\n    -\u003eexcludeEnvKeys([]); // pass all env vars through\n```\n\nTo add additional exclusions:\n\n```php\n$options = ClaudeAgentOptions::create()\n    -\u003eexcludeEnvKeys([\n        ...ClaudeAgentOptions::DEFAULT_EXCLUDED_ENV_KEYS,\n        'ANTHROPIC_CUSTOM_VAR',\n    ]);\n```\n\n## Installation\n\n```bash\ncomposer require datashaman/claude-agent-sdk\n```\n\n## Quick Start\n\n### Basic Query\n\n```php\nuse DataShaman\\Claude\\AgentSdk\\Claude;\n\nforeach (Claude::query('What is PHP?') as $message) {\n    if ($message-\u003etype === 'content_block_delta' \u0026\u0026 isset($message-\u003edelta['text'])) {\n        echo $message-\u003edelta['text'];\n    }\n}\n```\n\n### Query with Options\n\n```php\nuse DataShaman\\Claude\\AgentSdk\\Claude;\nuse DataShaman\\Claude\\AgentSdk\\ClaudeAgentOptions;\nuse DataShaman\\Claude\\AgentSdk\\Enum\\PermissionMode;\n\n$options = ClaudeAgentOptions::create()\n    -\u003emodel('claude-sonnet-4-6')\n    -\u003emaxTurns(5)\n    -\u003esystemPrompt('You are a helpful PHP expert.')\n    -\u003epermissionMode(PermissionMode::AcceptEdits);\n\nforeach (Claude::query('Explain generators', $options) as $message) {\n    // Process streaming messages\n}\n```\n\n### Custom Tools\n\nDefine tools using PHP attributes:\n\n```php\nuse DataShaman\\Claude\\AgentSdk\\Attribute\\Tool;\nuse DataShaman\\Claude\\AgentSdk\\Attribute\\Parameter;\nuse DataShaman\\Claude\\AgentSdk\\Claude;\nuse DataShaman\\Claude\\AgentSdk\\ClaudeAgentOptions;\n\n#[Tool(name: 'get_weather', description: 'Get current weather for a city')]\nfunction getWeather(\n    #[Parameter(description: 'City name')]\n    string $city,\n    #[Parameter(description: 'Temperature unit', enum: ['celsius', 'fahrenheit'])]\n    string $unit = 'celsius',\n): array {\n    // Your weather API logic here\n    return ['temp' =\u003e 22, 'unit' =\u003e $unit, 'city' =\u003e $city];\n}\n\n$options = ClaudeAgentOptions::create()\n    -\u003etools(['getWeather']);\n\nforeach (Claude::query('What is the weather in London?', $options) as $message) {\n    // Tool calls are handled automatically\n}\n```\n\n### Session Management\n\n```php\nuse DataShaman\\Claude\\AgentSdk\\ClaudeAgentClient;\nuse DataShaman\\Claude\\AgentSdk\\ClaudeAgentOptions;\n\n$client = ClaudeAgentClient::create(\n    ClaudeAgentOptions::create()-\u003emodel('claude-sonnet-4-6')\n);\n\n// First message\nforeach ($client-\u003esend('Hello!') as $message) {\n    // Process response\n}\n\n// Continue the conversation (same session)\nforeach ($client-\u003esend('Tell me more') as $message) {\n    // Process response\n}\n\n// List all sessions\n$sessions = $client-\u003elistSessions();\n\n// Get messages from a session\n$messages = $client-\u003egetSessionMessages($sessionId);\n```\n\n### MCP Server\n\nCreate an MCP server that exposes tools to Claude:\n\n```php\nuse function DataShaman\\Claude\\AgentSdk\\Mcp\\createSdkMcpServer;\n\n$server = createSdkMcpServer([\n    'getWeather', // Pass tool callables\n]);\n\n$server-\u003erun(); // Starts listening on stdio\n```\n\nConnect to external MCP servers:\n\n```php\n$options = ClaudeAgentOptions::create()\n    -\u003emcpServers([\n        'myserver' =\u003e [\n            'command' =\u003e 'node',\n            'args' =\u003e ['path/to/server.js'],\n        ],\n    ]);\n```\n\n## API Reference\n\n### `Claude::query(string $prompt, ?ClaudeAgentOptions $options = null): Generator\u003cMessage\u003e`\n\nOne-off query that returns a Generator yielding `Message` objects as they stream from the CLI.\n\n### `ClaudeAgentOptions`\n\nImmutable configuration object with fluent builder:\n\n| Method | Description |\n|--------|-------------|\n| `model(string)` | Claude model to use |\n| `maxTurns(int)` | Maximum agent turns |\n| `systemPrompt(string)` | Replace system prompt |\n| `appendSystemPrompt(string)` | Append to system prompt |\n| `tools(array)` | Custom tool callables |\n| `mcpServers(array)` | MCP server configurations |\n| `permissionMode(PermissionMode)` | Permission mode |\n| `allowedTools(array)` | Restrict available tools |\n| `cwd(string)` | Working directory for CLI |\n| `env(array)` | Environment variables (full override) |\n| `excludeEnvKeys(array)` | Env keys to exclude from passthrough (default: `ANTHROPIC_API_KEY`) |\n| `sessionId(string)` | Resume a session |\n| `extendedThinking(array)` | Extended thinking config |\n| `permissionPromptHandler(callable)` | Permission callback |\n\n### `ClaudeAgentClient`\n\nStateful client for multi-turn conversations:\n\n| Method | Description |\n|--------|-------------|\n| `send(string)` | Send a message, returns Generator |\n| `getSessionId()` | Current session ID |\n| `listSessions()` | List all sessions |\n| `getSessionMessages(string)` | Get session history |\n\n### `Message`\n\nReadonly DTO for streaming events:\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `type` | `string` | Event type (message_start, content_block_delta, etc.) |\n| `index` | `?int` | Content block index |\n| `message` | `?array` | Full message (for message_start) |\n| `contentBlock` | `?array` | Content block data |\n| `delta` | `?array` | Delta data for streaming |\n| `sessionId` | `string` | Session ID |\n| `uuid` | `string` | Event UUID |\n\n### Permission Modes\n\n```php\nPermissionMode::Default           // Default CLI behavior\nPermissionMode::AcceptEdits       // Auto-accept file edits\nPermissionMode::BlockEdits        // Block all file edits\nPermissionMode::BypassPermissions // Skip all permission prompts\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatashaman%2Fclaude-agent-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatashaman%2Fclaude-agent-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatashaman%2Fclaude-agent-sdk/lists"}