1. Go to this page and download the library: Download icdev/claude-agent-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
icdev / claude-agent-sdk-php example snippets
use ClaudeAgent\Options;
use function ClaudeAgent\query;
foreach (query('¿Cuánto es 17 * 23?', new Options(model: 'claude-opus-5')) as $m) {
if ($m['type'] === 'assistant') {
foreach ($m['message']['content'] as $b) {
if ($b['type'] === 'text') echo $b['text'], "\n";
}
}
}
$client = new ClaudeAgent\Client(new Options(model: 'claude-opus-5'));
foreach ($client->query('Recuerda el número 42.') as $m) { /* … */ }
foreach ($client->query('¿Qué número era?') as $m) { /* … */ }
$client->close();
$srv = (new SdkMcpServer('facturacion'))->tool(
'saldo_cliente',
'Devuelve el saldo pendiente de un cliente.',
['type' => 'object', 'properties' => ['cliente_id' => ['type' => 'integer']], '
use ClaudeAgent\{Agent, Plugin, Options, Effort, MemoryScope, PermissionMode};
use ClaudeAgent\Sandbox\{Sandbox, Network, Filesystem};
new Options(
agents: [
'revisor' => new Agent(
description: 'Revisa código PHP en busca de bugs.',
prompt: 'Eres un revisor de PHP. Sé conciso.',
tools: ['Read', 'Grep', 'Glob'],
model: 'sonnet',
effort: Effort::Low,
memory: MemoryScope::Project,
permissionMode: PermissionMode::Plan,
),
],
plugins: [
Plugin::local('/ruta/plugin'),
Plugin::localWithoutMcp('/ruta/otro'), // carga skills/hooks, ignora su .mcp.json
],
sandbox: new Sandbox(
enabled: true,
network: new Network(allowedDomains: ['api.anthropic.com'], strictAllowlist: true),
filesystem: new Filesystem(allowWrite: ['/tmp/work'], denyRead: ['/root/.ssh']),
),
);