From b50d0c2247bd0374210b29e1c96b98de697a517d Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 18 Jul 2025 17:35:10 +0900 Subject: [PATCH 1/4] Add support for Claude Code CI detection Detect Claude Code environment when CLAUDECODE=1 is set, allowing tools to output more concise information for LLM consumption, saving the precious context window. Fixes #116 --- src/Ci/ClaudeCode.php | 62 +++++++++++++++++++ src/CiDetector.php | 2 + tests/phpt/Ci/CiDetector_ClaudeCode.phpt | 36 +++++++++++ .../CiDetector_ClaudeCode_not_detected.phpt | 17 +++++ 4 files changed, 117 insertions(+) create mode 100644 src/Ci/ClaudeCode.php create mode 100644 tests/phpt/Ci/CiDetector_ClaudeCode.phpt create mode 100644 tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt diff --git a/src/Ci/ClaudeCode.php b/src/Ci/ClaudeCode.php new file mode 100644 index 0000000..24d4ccd --- /dev/null +++ b/src/Ci/ClaudeCode.php @@ -0,0 +1,62 @@ +get('CLAUDECODE') === '1'; + } + + public function getCiName(): string + { + return CiDetector::CI_CLAUDECODE; + } + + public function isPullRequest(): TrinaryLogic + { + return TrinaryLogic::createMaybe(); + } + + public function getBuildNumber(): string + { + return ''; + } + + public function getBuildUrl(): string + { + return ''; + } + + public function getCommit(): string + { + return ''; + } + + public function getBranch(): string + { + return ''; + } + + public function getTargetBranch(): string + { + return ''; + } + + public function getRepositoryName(): string + { + return ''; + } + + public function getRepositoryUrl(): string + { + return ''; + } +} \ No newline at end of file diff --git a/src/CiDetector.php b/src/CiDetector.php index 13dc528..bf91115 100644 --- a/src/CiDetector.php +++ b/src/CiDetector.php @@ -17,6 +17,7 @@ class CiDetector implements CiDetectorInterface public const CI_BITBUCKET_PIPELINES = 'Bitbucket Pipelines'; public const CI_BUDDY = 'Buddy'; public const CI_CIRCLE = 'CircleCI'; + public const CI_CLAUDECODE = 'Claude Code'; public const CI_CODESHIP = 'Codeship'; public const CI_CONTINUOUSPHP = 'continuousphp'; public const CI_DRONE = 'drone'; @@ -87,6 +88,7 @@ protected function getCiServers(): array Ci\TeamCity::class, Ci\Travis::class, Ci\Wercker::class, + Ci\ClaudeCode::class, ]; } diff --git a/tests/phpt/Ci/CiDetector_ClaudeCode.phpt b/tests/phpt/Ci/CiDetector_ClaudeCode.phpt new file mode 100644 index 0000000..f6dbf7d --- /dev/null +++ b/tests/phpt/Ci/CiDetector_ClaudeCode.phpt @@ -0,0 +1,36 @@ +--TEST-- +Claude Code: Detect properties + +--ENV-- +CLAUDECODE=1 + +--FILE-- +isCiDetected()); + +--EXPECT-- +bool(false) \ No newline at end of file From e520dd34099b18a4106bad40a29a97babcd8ebaa Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 18 Jul 2025 17:37:41 +0900 Subject: [PATCH 2/4] cs --- src/Ci/ClaudeCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ci/ClaudeCode.php b/src/Ci/ClaudeCode.php index 24d4ccd..a623635 100644 --- a/src/Ci/ClaudeCode.php +++ b/src/Ci/ClaudeCode.php @@ -59,4 +59,4 @@ public function getRepositoryUrl(): string { return ''; } -} \ No newline at end of file +} From 45eda999b9155eaa68e27c64c37483a497064cac Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sat, 19 Jul 2025 22:19:26 +0900 Subject: [PATCH 3/4] Update CiDetector.php --- src/CiDetector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CiDetector.php b/src/CiDetector.php index bf91115..9ffe63d 100644 --- a/src/CiDetector.php +++ b/src/CiDetector.php @@ -78,6 +78,7 @@ protected function getCiServers(): array Ci\BitbucketPipelines::class, Ci\Buddy::class, Ci\Circle::class, + Ci\ClaudeCode::class, Ci\Codeship::class, Ci\Continuousphp::class, Ci\Drone::class, @@ -88,7 +89,6 @@ protected function getCiServers(): array Ci\TeamCity::class, Ci\Travis::class, Ci\Wercker::class, - Ci\ClaudeCode::class, ]; } From d9abc46aa06b0c9aa5eac5304f0699c66da334d0 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sat, 19 Jul 2025 22:19:53 +0900 Subject: [PATCH 4/4] Apply suggestions from code review --- tests/phpt/Ci/CiDetector_ClaudeCode.phpt | 2 +- tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpt/Ci/CiDetector_ClaudeCode.phpt b/tests/phpt/Ci/CiDetector_ClaudeCode.phpt index f6dbf7d..05825fd 100644 --- a/tests/phpt/Ci/CiDetector_ClaudeCode.phpt +++ b/tests/phpt/Ci/CiDetector_ClaudeCode.phpt @@ -33,4 +33,4 @@ string(0) "" Repository name: string(0) "" Repository url: -string(0) "" \ No newline at end of file +string(0) "" diff --git a/tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt b/tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt index 48746c7..a80aa6d 100644 --- a/tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt +++ b/tests/phpt/Ci/CiDetector_ClaudeCode_not_detected.phpt @@ -14,4 +14,4 @@ $ciDetector = new \OndraM\CiDetector\CiDetector(); var_dump($ciDetector->isCiDetected()); --EXPECT-- -bool(false) \ No newline at end of file +bool(false)