NielsNumbers's avatar

Experimenting with Claude AI for Coding in PHPStorm and the Console

Hey Laracasts Team,

this is a request for a video that explores how Claude AI can be used to assist in Laravel/PHP development — both inside PHPStorm and directly in the console.

It doesn’t have to be a polished course. More like: “Let’s try this together and see what happens.” Things you could cover:

  • Setting up and using Claude in PHPStorm
  • Calling the API from a CLI tool or simple PHP script
  • Trying it for refactoring, writing tests, or generating snippets
  • Trying AI Agents from
  • Seeing where it helps and where it fails

Sometimes it’s more valuable to watch someone explore a new tool than to see a perfect tutorial.

Would love to see something like this and join the discussion in the comments.

Thanks, Adam

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! Here’s a practical guide addressing each of Adam’s points about experimenting with Claude AI for Laravel/PHP development, both inside PHPStorm and via the console.


1. Setting Up and Using Claude in PHPStorm

While there isn’t an official Claude AI plugin for PHPStorm as of now, you can integrate Claude with PHPStorm in two main ways:

  • Using an HTTP Client inside PHPStorm:
    PHPStorm has a built-in HTTP client where you can send API requests directly from .http files.

    • Obtain your Claude API Key (Anthropic docs).

    • Create a file named claude.http in your project root:

      ### Send prompt to Claude API
      POST https://api.anthropic.com/v1/messages
      Authorization: Bearer YOUR_CLAUDE_API_KEY
      Content-Type: application/json
      X-API-Key: YOUR_CLAUDE_API_KEY
      
      {
        "model": "claude-3-opus-20240229", 
        "messages": [
          {"role": "user", "content": "Refactor this PHP function for readability: ..."}
        ],
        "max_tokens": 512
      }
      
    • Modify the prompt and re-run as needed with Ctrl+Enter.

  • Using AI-powered Plugin Alternatives:
    Consider installing generic AI assistant plugins (such as CodeGPT or similar), which can usually be configured with custom endpoints and may work with Claude’s API if you provide the endpoint and key.


2. Calling the Claude API from a CLI Tool or Simple PHP Script

Here’s a simple PHP CLI script using GuzzleHTTP to send prompts to Claude:

<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();

$response = $client->post('https://api.anthropic.com/v1/messages', [
    'headers' => [
        'Authorization' => 'Bearer YOUR_CLAUDE_API_KEY',
        'Content-Type' => 'application/json',
        'X-API-Key' => 'YOUR_CLAUDE_API_KEY',
    ],
    'json' => [
        'model' => 'claude-3-opus-20240229',
        'messages' => [
            ['role' => 'user', 'content' => 'Write a Laravel validation rule for an email address.'],
        ],
        'max_tokens' => 512,
    ],
]);

$body = json_decode($response->getBody(), true);

echo $body['content'][0]['text'] ?? 'No response' . PHP_EOL;
  • Make sure you install Guzzle:
    composer require guzzlehttp/guzzle
    

3. Trying it for Refactoring, Writing Tests, or Generating Snippets

You can craft prompts for Claude such as:

  • "Rewrite this function to be more readable:"
  • "Write a PHPUnit test for the following method:"
  • "Generate a Laravel migration for a posts table"

Claude’s response can be copied back into PHPStorm or your codebase.


4. Trying AI Agents

Most agent-based workflows are still experimental but are beginning to appear in tools like Continue or OpenDevin.
You may clone and run their open source tools, some of which can be configured for Claude API endpoints.


5. Where it Helps and Where it Fails

Helps:

  • Quick code generation and boilerplate (migrations, factories, tests)
  • Code explanation and exploring unfamiliar code
  • Initial refactoring suggestions

Fails:

  • Understanding deep business/domain context
  • Producing idiomatic PHP/Laravel code in complex scenarios
  • Long form code generation (Claude has improved, but context-window/length limits still apply)

Conclusion

A great video could be a simple "screen share" session:

  • Crafting prompts, iterating, and copy/pasting results
  • Trying a real-world refactor
  • Writing and then running tests Claude generates
  • Sharing thoughts and examining what Claude gets right vs. wrong

If you'd like prebuilt snippets or a more starter-friendly CLI tool, let me know!

Please or to participate in this conversation.