# phpClaw

> Open-source PHP AI agent engine with tools, memory, security guards and a ReAct loop, with adapters for Laravel, Symfony, WordPress and other PHP platforms.

phpClaw is an open-source, MIT-licensed AI agent engine for PHP 8.1+ that adds a tool-calling agent to an existing PHP application through a Composer package or an uploaded CMS plugin. It runs on your own server and sends prompts only to the LLM provider you choose. It ships eight first-party adapters for Laravel, Symfony, WordPress, Drupal, Joomla, Magento, PrestaShop and OpenCart, and also runs in plain PHP.

## What It Is

phpClaw is an agent runtime for PHP developers. A single `Claw::builder()->build()->send()` call runs a ReAct loop (reason, act, observe) in which the model can call registered tools, read their results and continue until it has an answer or reaches the iteration cap. The core package has no framework dependencies, needing only PHP 8.1+ with curl, json and mbstring. Responses return the text, provider, model and token counts.

## Agent Building Blocks

Any PHP class implementing a tool interface can be exposed to the model. Built-in tools include code search, file read and write, allowlisted shell, HTTP and read-only database queries. Skills written in Markdown or arrays are loaded on demand by the model. Pipelines chain prompt, agent and structured-output steps, and graphs run multi-agent workflows with loops, branching, and human pause and resume. Structured output validates replies against a JSON Schema and retries failures. Mutating tools can require human approval before running.

## Providers, Memory and Security

Providers are auto-detected from environment variables: Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek and Ollama, plus a custom OpenAI-compatible endpoint, with optional fallback providers. Memory drivers include file, array, Redis, a namespace router and framework-native stores. Eight guards run by default, covering prompt injection, code injection, destructive SQL, role switching, homoglyphs, unicode, message length and PII. Shell access is allowlist-only, and file tools are sandboxed to a workspace. The docs also describe 54 lifecycle events for logging and metrics.

## MCP and Setup

The `phpclaw/phpclaw-mcp` package exposes a tool registry as a Model Context Protocol server over stdio or Streamable HTTP, so clients such as Claude Desktop, Claude Code, Cursor, Windsurf and Zed can call the tools. Setup is typically a Composer require, one provider API key and a framework-native CLI command such as `php artisan phpclaw`. The project's README states that it is not a RAG framework and has no embeddings or vector stores. The maintainers also offer custom tool and adapter development through an enterprise page.

## Features
- ReAct agent loop with iteration cap
- Custom tools via a simple interface
- Built-in tools: code search, file read/write/edit, shell allowlist, HTTP, read-only database query, zip packager
- Eight default security guards including prompt-injection and PII detection
- Pluggable memory drivers (file, array, Redis, router, framework-native)
- Pipelines and graphs for chains and multi-agent workflows
- Human approval gates for mutating tools
- Structured output with JSON Schema validation and retry
- Markdown and array skills loaded on demand
- Streaming responses
- Provider auto-detection and fallback providers
- 54 lifecycle hook events
- MCP server over stdio and Streamable HTTP
- Eight framework and CMS adapters with native CLI

## Integrations
Laravel, Symfony, WordPress, Drupal, Joomla, Magento, PrestaShop, OpenCart, Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek, Ollama, Redis, Claude Desktop, Claude Code, Cursor, Windsurf, Zed, Packagist

## Platforms
WEB, API, DEVELOPER_SDK, CLI

## Pricing
Open Source, Free tier available

## Links
- Website: https://phpclaw.ai/
- Documentation: https://phpclaw.ai/docs
- Repository: https://github.com/phpclaw-php/phpclaw-monorepo
- EveryDev.ai: https://www.everydev.ai/tools/phpclaw
