Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?

Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The allow-plugins Constraint and Composer CLI Limitations

Composer 2.2 introduced a mandatory requirement for the allow-plugins configuration section. This shift was designed to enhance security by preventing malicious plugins from executing arbitrary code during package installation. However, this change has created a friction point for developers attempting to manage their project configurations via command-line interfaces (CLI). Specifically, the composer config command, while powerful for setting scalar values like booleans or strings, fails when confronted with the complex nested structure required by allow-plugins.

When you attempt to push settings into the config section using composer config, you are essentially asking Composer to treat the value as a simple key-value pair. The allow-plugins field, however, is not just a boolean flag; it is an associative array where keys are plugin package names and values are booleans indicating whether they are trusted.

Because of this structural difference, commands like composer config --json 'allow-plugins' [...] or attempts to use the --append flag will result in errors such as "is not defined" or "invalid value." The CLI parser expects a scalar for a direct key assignment, but it receives a nested object structure. Even if you try to pass a JSON string directly to the config command, Composer interprets the input based on the top-level key provided, and it does not automatically nest that data under the config subsection of your composer.json.

Understanding the Configuration Hierarchy

To understand why these commands fail, one must look at how Composer merges configuration. The file you are trying to modify looks like this:

{
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist"
    }
}

The goal is to add the allow-plugins array directly inside that config object. When you run a command like composer config --json 'config.allow-plugins' '{...}', you might assume this works because of the dot notation. While Composer does support dot notation for nesting, the issue lies in how the --append and raw JSON inputs are processed.

The --append flag is specifically designed to add items to an array (like adding a new plugin dependency to require-dev). It is not designed to initialize a new nested object structure or to set a key inside a subsection that doesn't exist in the expected format. Furthermore, simply passing a JSON string without ensuring the destination path exists and accepts that specific shape often leads to the "invalid value" error you encountered.

The Correct Approach: Manual or Tool-Assisted Injection

Currently, there is no single CLI command that cleanly initializes the config.allow-plugins array in one go without risking corruption of existing configuration or triggering validation errors on the nested structure. The most reliable method remains editing the composer.json file directly using a text editor or a dedicated JSON manipulation tool. This ensures that the syntax is correct and that the nesting under the config key is preserved exactly as Composer expects it for version 2.2+.

If you are managing multiple projects or need to automate this setup across a monorepo, consider writing a small script to generate the necessary JSON patches. You can use tools like jq to safely merge objects without worrying about CLI argument parsing limitations:

# Using jq to safely update the config section
jq '.config.allow-plugins = {"composer/installers": true}' composer.json > temp.json && mv temp.json composer.json

This approach bypasses Composer's CLI parsing logic entirely, handing you a pre-validated JSON structure that can be committed immediately. It avoids the pitfalls of trying to force a complex object into a scalar-oriented command flag.

Why This Limitation Exists

The restriction isn't arbitrary; it stems from how Composer validates its configuration schema. The config section in composer.json is strictly typed. When allow-plugins became mandatory, the schema enforcement tightened. CLI commands are optimized for quick modifications (adding a plugin, changing a repository URL), not for restructuring complex nested objects that require deep validation of the inner array keys and values.

Attempting to bypass this via string manipulation with composer config --json often fails because Composer validates the resulting structure against its internal schema before applying changes. If the input doesn't perfectly match the expected nested format, or if the command attempts to append to a non-existent structure incorrectly, validation errors are thrown immediately.

For projects where this configuration is critical, manual intervention via composer.json remains the standard practice until Composer's CLI expands its capabilities to handle deep-object initialization more gracefully. If you are integrating this into a build pipeline, ensure your CI/CD steps explicitly write the allow-plugins block to the file rather than relying on dynamic config commands that might fail silently or with obscure error messages.

Our network