Download the PHP package codechap/yii3-claude-code without Composer
On this page you can find all versions of the php package codechap/yii3-claude-code. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii3-claude-code
Yii3 Claude Code
A Yii3 wrapper for the Claude Code CLI with DI integration, immutable fluent API, and multi-turn conversation support.
Works on Linux, macOS, and Windows. Supports both subscription and API key authentication.
Requirements
- PHP 8.2 - 8.5
- Claude Code CLI installed and in your PATH (or configured via
binaryPath)
Installation
Configuration is auto-loaded via Yii3's config-plugin.
Quick start
Authentication
Subscription (default)
If you're logged in via claude auth login, no extra config is needed. The package unsets ANTHROPIC_API_KEY in the subprocess by default to prevent accidental API charges.
API key
Set the API key in your params to use pay-as-you-go billing instead of a subscription:
Or at runtime:
When an API key is provided, it takes priority — the ANTHROPIC_API_KEY environment variable is set in the subprocess instead of being unset.
Note: With an API key, you are billed per token (pay-as-you-go). With a subscription, usage is included in your monthly plan. Verify your auth method with
claude auth status.
Configuration
Override defaults in your application's config/params.php:
Usage
All with* methods are immutable — they return a new instance, leaving the original unchanged.
Model selection
JSON mode
Multi-turn conversations
System prompts
Allowed tools
Working directory
Custom environment variables
Useful when running under a web server where $HOME and $PATH differ from your shell:
Additional CLI flags
Pass arbitrary flags to the claude binary that don't have a dedicated with* method. Three forms are supported:
These are appended after the built-in flags. Run claude --help to see all available flags.
Timeout
Callback
Console command
Requires yiisoft/yii-console.
Use -v for verbose output (session ID and elapsed time).
Response object
| Method | Returns | Description |
|---|---|---|
getResult() |
string |
Extracted response text |
getRawOutput() |
string |
Unprocessed CLI output |
getSessionId() |
?string |
Session ID for multi-turn (JSON mode) |
getElapsedSeconds() |
float |
Wall-clock time in seconds |
isJson() |
bool |
Whether JSON mode was used |
toArray() |
array |
Decode result as JSON (throws ParseException on failure) |
__toString() |
string |
Same as getResult() |
Default CLI flags
Every query invokes the claude binary with these flags:
| Flag | Value | Description |
|---|---|---|
--print |
(always set) | Non-interactive mode — sends prompt via stdin and exits. Cannot be disabled. |
--output-format |
text or json |
Controlled by withJson(). Defaults to text. |
--model |
sonnet |
Configurable via params (model) or withModel(). Defaults to sonnet. |
The resulting command looks like:
Additional flags (--system-prompt, --max-turns, --allowedTools, --resume, --continue) are appended only when their corresponding with* method has been called. For any other CLI flag (e.g. --dangerously-skip-permissions, --effort, --add-dir), use withFlags().
Platform notes
Binary detection
The package auto-detects the claude binary using which (Linux/macOS) or where (Windows). If auto-detection fails — common under web servers with a minimal $PATH — set binaryPath explicitly:
Web server context
When PHP runs under Apache/nginx, the subprocess inherits the web server's environment. This means:
$HOMEpoints to the web server user (e.g.www-data), which won't have Claude authenticated$PATHmay not include the directory whereclaudeis installed
Solutions:
- Set
binaryPathto the full path of theclaudebinary - Use
envSetto pass the correctHOME(for subscription auth) or useapiKey(for API auth)
Recursion prevention
By default, CLAUDECODE and ANTHROPIC_API_KEY are unset in the subprocess to prevent:
- Infinite recursion if your app is itself running inside Claude Code
- Accidental API charges when you intend to use a subscription
This is configurable via envUnset. When apiKey is set, it overrides the ANTHROPIC_API_KEY unset.
Testing
Integration tests that call the real Claude CLI are automatically skipped if the binary is not available.
License
MIT
All versions of yii3-claude-code with dependencies
symfony/console Version ^6.0 || ^7.0
symfony/process Version ^6.0 || ^7.0
yiisoft/friendly-exception Version ^1.1