artisan-build/claudecode

A Claude Code SDK for Laravel

dev-main 2025-07-08 13:04 UTC

This package is auto-updated.

Last update: 2025-07-08 13:21:03 UTC


README

Artisan Build Package Claude Code Logo

Claude Code SDK for Laravel

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.

Requirements

  • PHP 8.3+
  • Laravel 11.0+
  • Claude CLI installed (claude command available)
  • Anthropic API key

Installation

composer require artisan-build/claudecode

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=claude-code-config

Set your Anthropic API key in your .env file:

ANTHROPIC_API_KEY=your-api-key-here

Additional 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,Edit

Usage

Basic Usage

use 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();

Using the Task Helper

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();
}

Streaming Responses

ClaudeCode::query('Build a REST API for managing books')
    ->stream(function ($message) {
        echo $message->getTextContent() . "\n";
    });

Session Management

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();

Tool Management

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']
}

Advanced Options

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();

Memberware

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.