fix(php): remove no-op Psalm flags, document PHPStan AgentDetector#1
Merged
Conversation
Psalm: remove --monochrome and --show-snippet=false from text format recommendations — both are no-ops when using --output-format=text (text format never outputs ANSI colors or code snippets). PHPStan: document the 2.x AgentDetector that injects a ~600-byte preamble when it detects AI agent env vars (CLAUDECODE, CURSOR_TRACE_ID, etc.), as this is a significant undocumented source of token overhead.
There was a problem hiding this comment.
Pull request overview
Updates the PHP tooling guidance (php.md) to reduce no-op flags and document output overhead sources that matter for AI agent usage.
Changes:
- Removed redundant Psalm flags (
--monochrome,--show-snippet=false) when using--output-format=text. - Added documentation about PHPStan 2.x
AgentDetectorand its fixed preamble overhead in agent environments. - Updated the AGENTS.md / CLAUDE.md template snippet to match the revised Psalm command.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tested all 6 PHP tools (PHPStan, Psalm, PHPUnit, PHPCS, PHP-CS-Fixer, Rector) on a real Laravel 12 codebase to validate the recommended flags.
Psalm — remove
--monochromeand--show-snippet=false:--monochrome: proved identical output with and without when using--output-format=text— thetextformatter never emits ANSI codes--show-snippet=false: proved identical output with and without when using--output-format=text— snippets only appear in the defaultconsoleformatPHPStan — document AgentDetector (2.x):
PHPStan 2.x ships an
AgentDetector(PHPStan\Internal\AgentDetector) that checks env vars (CLAUDECODE,CURSOR_TRACE_ID,OPENCODE, etc.) and injects:[identifier=...]suffixes on each error line inrawformatFor 3 errors: 1420 bytes with agent detection vs 478 bytes without — 197% overhead from the preamble alone. This is the single largest source of token overhead in PHPStan output when running inside AI agents, and it applies regardless of
--error-format.Test plan
--show-snippet=falseis a no-op ontextformat (diff of outputs is empty)--monochromeis a no-op ontextformat (diff of outputs is empty)phpstan.phar(src/Internal/AgentDetector.php)CLAUDECODEenv var is unset