phpstan-trace

phpstan-trace is a skill for Claude Code, Codex from kayw-geek/phpstan-type-trace. It costs 143 tokens per session (2,243 once invoked), scanned C, original, MIT.

A workflow for tracing how PHPStan or Larastan inferred a variable's type at a particular PHP source location. Larastan extends PHPStan for Laravel projects and framework-specific behavior.

In plain words
What is it for?
Use it before fixing a non-trivial PHPStan or Larastan error when reading the source alone does not explain the inferred type.
Why use it?
It explains confusing type errors when the type is shaped across scopes, generics, or third-party extensions.

Skill for Claude CodeCodex

Part of the phpstan-type-trace plugin — 1 skill shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/kayw-geek/phpstan-type-trace/phpstan-trace
Any agent
npx skills add kayw-geek/phpstan-type-trace --skill phpstan-trace
Clone the repo
git clone --depth 1 https://github.com/kayw-geek/phpstan-type-trace

Made for: Claude Code, Codex.

Or install phpstan-type-trace, the plugin that ships this one along with the rest of its 1 skill.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for phpstan-trace

README.md
[![agentmods](https://agentmods.dev/badge/skills/kayw-geek/phpstan-type-trace/phpstan-trace.svg)](https://agentmods.dev/skills/kayw-geek/phpstan-type-trace/phpstan-trace)
Your own site
<a href="https://agentmods.dev/skills/kayw-geek/phpstan-type-trace/phpstan-trace"><img src="https://agentmods.dev/badge/skills/kayw-geek/phpstan-type-trace/phpstan-trace.svg" alt="Measured on agentmods" height="20"></a>
Per session 143 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,243 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00143 $0.02243
Opus 5 $0.00072 $0.01122
Sonnet 5 $0.00029 $0.00449
Haiku 4.5 $0.00014 $0.00224

Measured 3d ago against content hash d18eff140f39, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

phpstan-trace scanned grade C with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Harvests environment variableshighData exfiltration

Enumerating or grepping the environment for keys collects credentials unrelated to what the mod says it does.

- The CLI runs `phpstan` internally on the target file with a dump environment variable set; it does **not** modify your source or your phpstan config.
skills/phpstan-trace/SKILL.md · 176 lines

How it starts

The opening of the file, as written. The whole thing — 176 lines — stays where its author put it; the contents beside it link to each section on GitHub.

phpstan-trace

Inspect the full type-inference chain of a variable at a PHP source location.

When to use

Invoke this skill before attempting to fix a PHPStan type error when any of these signals are present:

  • The variable is touched in 2+ scopes (passed into a closure, callback, helper, or array map).
  • A third-party extension is plausibly involved: larastan Eloquent magic attributes ($user->name, $model->created_at), webmozart/assert or beberlei/assert guards, doctrine collections, dynamic-return-type extensions (e.g. Model::query()).
  • The enclosing method is longer than ~30 lines OR the file exceeds ~100 lines.
  • The error involves generics, array{...} shapes, or template parameters that don't match what you expect from reading the signature.
  • You already read the source and the inferred type at the error line still doesn't make sense.
  • The error is Cannot access property X on string, ... expects Foo, Foo|null given, ... always evaluates to true/false, or a similar "where did this type come from?" message in any of the above contexts.

The CLI returns every event (parameter binding, assign, compound-op, narrowing, read) that shaped the variable from function entry up to the failing line — so you can see where the wrong type came in, instead of guessing.

When NOT to use

Skip the CLI and just read the source if all of these hold:

  • The file is short (< 100 lines) AND the method is short (< 30 lines).
  • The error message names a single line and the variable is assigned/parameter-bound in plain sight nearby.
  • No third-party extension is shaping the type (vanilla PHP, no Eloquent magic, no assert library).
  • The fix is obviously a missing ?? default, a missing null guard, or a typo in a property name.

Also skip for non-type errors: Call to undefined method, Class X not found, Access to undefined constant — these don't need a type-inference chain.

Rule of thumb: if you'd confidently write the fix in under 30 seconds from reading the source, skip the trace. If you'd be guessing, run it.

Read the full file on GitHub · 176 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 176 lines · 143 tokens per session scan C d18eff140f39

Subscribe to this mod's changes

phpstan-trace is a skill published in the GitHub repository kayw-geek/phpstan-type-trace (20 stars, last pushed 3mo ago), licensed MIT. It adds 143 tokens to every session and 2,243 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it C with 1 finding (harvests environment variables). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

vigilante-issue-implementation-on-php

Implement a GitHub issue end-to-end when Vigilante dispatches work for a PHP repository with Composer, static analysis, and security guidance.

aliengiraffe/vigilante · 39 tokens

wp-coding-standards

Use when setting up PHPCS with WordPress Coding Standards (WPCS), configuring phpcs.xml.dist, running phpcs/phpcbf, fixing sniff violations, adding PHPCS to CI (GitHub Actions), configuring IDE integration, or verifying a plugin meets WP.org code style requirements. Covers squizlabs/phpcodesniffer…

mralaminahamed/wp-dev-skills · 303 tokens

wp-i18n-workflow

Use when managing the full translation workflow for a WordPress plugin — registering text domain with loadplugintextdomain, wrapping strings with (), e(), eschtml(), escattr(), n(), x(), ex(), nx(), generating POT with wp i18n make-pot, compiling .po to .mo (wp i18n make-mo / msgfmt) and .json (wp i18n make-json)…

mralaminahamed/wp-dev-skills · 303 tokens

laravel-eloquent

Eloquent and query-layer engineering rules for Laravel — eliminating N+1, choosing a pagination strategy, short atomic transactions, casts and scopes on the model, where raw SQL is allowed, and how migrations declare the schema those queries depend on. Use when writing or reviewing Eloquent models, migrations, query…

Foysal50x/skills · 93 tokens

laravel-testing

Test strategy for a layered Laravel application — which test style fits each layer, hand-written fakes over mocks, real-database tests for Query Classes and Repositories, pure tests for Value Objects, and feature tests that assert authorization, payload shape and query counts. Use when writing or reviewing Laravel…

Foysal50x/skills · 83 tokens

webman

Expert skill for the webman framework (a long-lived, in-memory PHP framework based on workerman). Covers routing, controllers, middleware, database/Redis, custom processes, timers, coroutines (v2), plugin development, and guarding against memory leaks and cross-request state pollution under the resident process model.…

zjkal/webman-skill · 111 tokens