agentleFS
AnyOrgNameAnyOrgName/php-skills/skills/composer/scripts/SKILL.md

scripts

Skill4 starsChanged 4 months agoMITView on GitHub

Automate project tasks with Composer scripts — named commands, event hooks, and script composition — invoked with composer run-script. Use when the user wants a single script that runs several tools in sequence, such as lint then test then static analysis; the user wants to run a task automatically after a Composer install or update, such as clearing a cache or dumping config; the user wants a short, named command (like test or lint) that runs a longer tooling invocation. Keywords: composer, scripts, event-hooks, automation, tooling.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not use Composer scripts as the primary orchestrator for a complex, multi-stage build with parallelism and dependencies between targets.

    line 62
  2. Distinctive:

    Do not put application runtime logic in a Composer script.

    line 63
  3. Very specific:

    Add one script per tool under scripts, e.g.

    line 77
  4. Very specific:

    Add a "check" script whose array calls @lint, @analyse, and @test in order so one command runs the whole gate.

    line 79
  5. Very specific:

    Call composer check as the single quality step in the CI workflow.

    line 81
  6. Very specific:

    Add a scripts-descriptions block so composer run-script --list explains what each script does for new contributors

    line 85
  7. Very specific:

    When a script needs real PHP logic, reference a static method callable ("App\\Composer\\Hooks::postInstall") instead of packing logic into …

    line 87
  8. Distinctive:

    Not applicable — no I/O, auth, or untrusted input.

    line 114

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- generated: do not edit — source: knowledge/atoms/composer/scripts/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->

Composer Scripts

When to use

  • The user wants a single script that runs several tools in sequence, such as lint then test then static analysis.
  • The user wants to run a task automatically after a Composer install or update, such as clearing a cache or dumping config.
  • The user wants a short, named command (like test or lint) that runs a longer tooling invocation.

When NOT to use

  • Do not use Composer scripts as the primary orchestrator for a complex, multi-stage build with parallelism and dependencies between targets.
  • Do not put application runtime logic in a Composer script; scripts run at the developer or CI command line, never per HTTP request.

Core guidance

  • Compose scripts by referencing them with @ — Build a pipeline by listing sub-commands in an array and calling other scripts with an @ prefix, e.g. a check script that runs @lint, @analyse, and @test.
  • Subscribe automation to lifecycle events — Attach automation to the exact lifecycle event it belongs to, using post-install-cmd, post-update-cmd, or post-autoload-dump rather than expecting developers to run it by hand.
  • Define named scripts under the scripts key — Add commands under the top-level scripts key in composer.json, mapping a name to a command or an array of commands, then run them with composer <name>.

Quick recipe

  1. Add one script per tool under scripts, e.g. "lint", "analyse", and "test", each pointing at its binary in vendor/bin. (verify: composer test runs the test suite on its own)
  2. Add a "check" script whose array calls @lint, @analyse, and @test in order so one command runs the whole gate. (verify: composer check runs lint, analyse, and test in sequence and stops on the first failure)
  3. Call composer check as the single quality step in the CI workflow. (verify: The CI job runs composer check and fails the build if any sub-step exits non-zero)

Best practices

  • Add a scripts-descriptions block so composer run-script --list explains what each script does for new contributors
  • When a script needs real PHP logic, reference a static method callable ("App\\Composer\\Hooks::postInstall") instead of packing logic into a shell string

Anti-patterns

Anti-patternWhy it failsDo instead
Duplicating the same command across scriptsThe duplicated flags drift apart over time, so different entry points run subtly different checks.Define the command once and reference it from aggregate scripts with an @ prefix.
Cramming logic into an inline php -r stringInline code is unreadable, untestable, and breaks across shells due to quoting differences.Move the logic into a class method and reference it as a static-method callable from the script.
Hardcoding secrets into a script commandcomposer.json is committed to version control, so any secret in a script is leaked to everyone with repo access.Read secrets from environment variables inside the script and inject them through the CI secret store.

See references/anti-patterns.md.

Common mistakes

  1. Script name collides with a Composer command — Naming a script after a built-in command like install or update silently overrides that command. Fix: Name scripts with task-specific verbs (test, lint, check) and never reuse a reserved Composer command name.
  2. Post-install hook fails under --no-dev — A post-install-cmd that calls a dev-only tool crashes when production runs composer install --no-dev. Fix: Guard dev-only steps so they skip when the tool is missing, or move them to a dedicated dev-only script not bound to install.
  3. Chained shell command hides a failure — Joining sub-commands with a shell pipe or a stray || true can make a failing step report success. Fix: List sub-commands as separate array entries so Composer stops on the first non-zero exit, and avoid || true on quality gates.

Version notes

  • Composer 2 keeps run-script and adds exec (PHP >=7.4) — Composer 2 continues to run named scripts via composer <name> or composer run-script <name>, and adds composer exec to run vendor binaries without defining a script.

Security

  • Not applicable — no I/O, auth, or untrusted input.

Testing

  • Activation and decision behavior are verified in eval/scenarios/composer/scripts.yaml.

Additional resources

  • references/anti-patterns.md
  • references/core.md
  • references/examples.md
  • references/pitfalls.md
  • references/recipes.md
  • references/version-differences.md

Knowledge graph

Related: composer/dependency-management, psr/psr12-coding-style

<!-- graph-fragment: graph/fragments/composer/scripts.yaml -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.