A Laravel package that provides a seamless integration with Claude Code, allowing you to execute AI-powered coding tasks directly from your Laravel application.
Warning
This package is currently under active development, and we have not yet released a major version. Once a 0.* version has been tagged, we strongly recommend locking your application to a specific working version because we might make breaking changes even in patch releases until we've tagged 1.0.
- PHP 8.3+
- Laravel 11.0+
- Claude CLI installed (
claudecommand available) - Anthropic API key
composer require artisan-build/claudecodePublish the configuration file:
php artisan vendor:publish --tag=claude-code-configSet your Anthropic API key in your .env file:
ANTHROPIC_API_KEY=your-api-key-hereAdditional configuration options:
CLAUDE_CLI_PATH=claude
CLAUDE_TIMEOUT=120
CLAUDE_MODEL=claude-3-5-sonnet-20241022
CLAUDE_PERMISSION_MODE=auto
CLAUDE_ALLOWED_TOOLS=Read,Write,Edituse ArtisanBuild\ClaudeCode\Facades\ClaudeCode;
// Simple query
$response = ClaudeCode::query('Write a function to calculate factorial')
->get();
// With options
$response = ClaudeCode::query('Analyze this codebase and suggest improvements')
->withModel('claude-3-5-sonnet-20241022')
->withWorkingDirectory('/path/to/project')
->allowTools(['Read', 'Grep', 'Glob'])
->execute();use ArtisanBuild\ClaudeCode\Support\ClaudeCodeTask;
$task = ClaudeCodeTask::create('Refactor the UserController')
->inDirectory(base_path('app/Http/Controllers'))
->allowTools(['Read', 'Edit', 'Write'])
->run();
if ($task->isSuccessful()) {
echo $task->getResult();
} else {
echo "Error: " . $task->getError();
}ClaudeCode::query('Build a REST API for managing books')
->stream(function ($message) {
echo $message->getTextContent() . "\n";
});use ArtisanBuild\ClaudeCode\Support\ClaudeCodeSession;
$session = new ClaudeCodeSession(app(ClaudeCode::class));
// First prompt
$session->prompt('Create a new Laravel model for Product');
// Follow-up prompt (maintains context)
$session->prompt('Now create a migration for this model');
// Get all responses
$allMessages = $session->getMessages();
$lastResponse = $session->getLastResponse();use ArtisanBuild\ClaudeCode\Support\ClaudeCodeTools;
// Use predefined tool sets
$response = ClaudeCode::query('Analyze the codebase')
->allowTools(ClaudeCodeTools::readOnlyTools())
->execute();
// Check what tools were used
$task = ClaudeCodeTask::create('Update all tests')
->allowTools(ClaudeCodeTools::fileTools())
->run();
if ($task->hasUsedTools()) {
$toolNames = $task->getUsedToolNames(); // ['Read', 'Edit', 'Write']
}use ArtisanBuild\ClaudeCode\Support\ClaudeCodeOptions;
$options = ClaudeCodeOptions::create()
->systemPrompt('You are a Laravel expert. Follow PSR-12 standards.')
->maxTurns(10)
->model('claude-3-5-sonnet-20241022')
->permissionMode('auto')
->workingDirectory(base_path())
->allowedTools(['Read', 'Write', 'Edit', 'Bash']);
$response = ClaudeCode::query('Implement user authentication')
->withOptions($options)
->execute();This package is part of our internal toolkit and is optimized for our own purposes. We do not accept issues or PRs in this repository.
