Skip to content

Strip PHPStan agent-detector env vars when spawning PHPStan#149

Closed
SanderRonde wants to merge 2 commits intomasterfrom
cursor/phpstan-configuration-file-d48f
Closed

Strip PHPStan agent-detector env vars when spawning PHPStan#149
SanderRonde wants to merge 2 commits intomasterfrom
cursor/phpstan-configuration-file-d48f

Conversation

@SanderRonde
Copy link
Copy Markdown
Owner

Summary

Implements the suggestion from issue #148 (comment): when the extension spawns PHPStan, environment variables used by PHPStan’s AgentDetector are cleared so analysis is not affected when the editor (e.g. Cursor) sets CURSOR_TRACE_ID, CURSOR_AGENT, etc.

Changes

  • Added shared/phpstanSpawnEnv.ts with the same variable list as PHPStan’s detector (AI_AGENT, CURSOR_TRACE_ID, CURSOR_AGENT, GEMINI_CLI, CODEX_SANDBOX, AUGMENT_AGENT, OPENCODE_CLIENT, OPENCODE, CLAUDECODE, CLAUDE_CODE, REPL_ID) and a helper to remove them from an env object.
  • Process.spawnWithRobustTimeout now builds spawnEnv from process.env merged with caller options.env, strips those keys, and passes env to both the Windows exec path (which previously omitted env) and the spawn path.
  • getVersion uses the same stripping for its spawn call.

Fixes the need for users to manually unset these variables in wrapper scripts when running PHPStan from Cursor-related environments.

Closes #148

Open in Web Open in Cursor 

cursoragent and others added 2 commits March 29, 2026 22:41
PHPStan's AgentDetector reads editor/agent environment variables
(e.g. CURSOR_TRACE_ID, CURSOR_AGENT), which can break analysis when
the extension runs inside Cursor. Clear the same vars PHPStan checks
for all PHPStan child processes, including the Windows exec code path
that previously inherited the full environment without overrides.

Also apply stripping to the version probe spawn for consistency.

Co-authored-by: Sander Ronde <awsdfgvhbjn@gmail.com>
- Format phpstanSpawnEnv and import order in getVersion
- Narrow workspace root path before getBinComand (no-unsafe-argument)

Co-authored-by: Sander Ronde <awsdfgvhbjn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: extension fails to parse new agent-instructions

2 participants