[Bug] --agents accepts invalid JSON with exit 0 and no warning, while --settings/--mcp-config reject it
so when i pass a broken or invalid value to --agents, claude code runs like normal anyway — exit 0, nothing printed. but if i pass the same broken json to --settings or --mcp-config, those stop with an error and exit 1. so --agents behaves differently from the other two.
the problem: if my --agents json is malformed (easy to do with shell quoting, or in a CI script), my custom agents never get defined and claude gives me no error or warning about it. it just runs like i never passed any agents. and since it exits 0, my automation thinks everything worked.
i'd expect --agents to at least warn (ideally error, like --settings does) when the json is invalid or the wrong shape, instead of accepting it and moving on. right now a small mistake means my agents just aren't there and claude never tells me.
Environment
- Platform: macOS (Darwin 25.5.0)
- Version: 2.1.215 (Claude Code)
- Terminal: zsh
3 Comments
The inconsistency here is a real operational hazard, especially in CI. The
--settingsand--mcp-configflags error on malformed JSON because those are load-bearing configs where the tool cannot proceed safely without them.--agentsshould follow the same convention.The silent-success behavior means anyone generating the
--agentsvalue programmatically (templating agent definitions from a deploy script, JSON-encoding in bash with variable substitution, etc.) will get a phantom success on broken configs. Your session runs fine, your agents never existed, you find out 20 minutes later when the expected behavior never happens.Two things that would fix this:
--agentsJSON before the session starts, exit 1 on malformed input (same as--settings).The second point is useful even when JSON is valid -- it closes the "did my agent definition actually load" guesswork that is common when debugging agent behavior.
Reproduced on v2.1.233 (macOS).
Steps:
claude -p 'say ok' --agents '{bad json'; echo $?claude -p 'say ok' --settings '{bad json'; echo $?claude -p 'say ok' --mcp-config '{bad json'; echo $?Observed:
--agentsalso silently accepts wrong-shaped but valid JSON (for example--agents '{"reviewer": "not an object"}'or an agent object missingprompt) with exit 0 and no output.Expected:
--agentsshould fail (or at least warn) on malformed or wrong-shaped JSON, matching--settingsand--mcp-config, so scripts do not silently run without the agents they asked for.Assessment: This is intended today rather than a regression —
--agentsdeliberately fails soft: bad JSON or a definition that doesn't match the schema is dropped and only recorded in the debug log (visible with--debug), and this has been the behavior since the flag was added. The docs (https://code.claude.com/docs/en/cli-reference, https://code.claude.com/docs/en/sub-agents) don't say what happens on invalid input. But the expectation is reasonable: the sibling flags validate up front and exit non-zero, and silently running without the requested agents is exactly what automation can't detect. We should make this clearer by validating--agentsat startup the same way--settingsand--mcp-configare validated, printing the parse/schema error to stderr and exiting non-zero (or at minimum emitting a visible warning).🤖 Generated with Claude Code
Confirmed — reproduced on 2.1.233 on Linux.
What I ran:
claude -p "hi" --agents '{invalid json'→ no error, no warning; the session runs exactly as if the flag hadn't been passed (exit 0 with working auth). The invalid value is silently discarded, and the same happens for structurally wrong JSON.claude -p "hi" --settings '{invalid json'→ immediate error, exit 1.claude -p "hi" --mcp-config '{invalid json'→ immediate error, exit 1.So
--agentsreally is inconsistent with the other two config flags, and a shell-quoting mistake in CI means your agents silently don't exist. We agree it should fail fast (or at minimum warn) like--settingsdoes — thanks for the clear report.🤖 Generated with Claude Code