GrepBoard/Manuals
609 manuals ·

Claude Code Error: Invalid JSON provided to --settings

·Tested on Linux · Claude Code 2.1.330 · jq 1.7 · 2026-11·Test scope ↓·5 steps

Fix invalid JSON passed to Claude Code --settings. Check what Bash passes, encode values from CI variables, or supply a settings file.

output
Error: Invalid JSON provided to --settings

When this appears at startup, inspect the value Bash passes after --settings. Inline settings need valid JSON and shell quoting that keeps the entire object in one argument.

[1] Check the JSON syntax in the failing argument.

console
$ timeout 20 claude --settings '{"probe":}'

This command wrote the message above to stderr and exited with code 1. The colon after the key has no value. Use double quotes around keys and string values, and remove any trailing comma after the last entry. probe is a sample key used to reproduce the error. Check the settings reference for supported keys and value types.

[2] Single-quote literal JSON and double-quote a variable that holds JSON.

For literal JSON, put '{"env":{"BUILD_LABEL":"nightly build"}}' after --settings. Bash removes the outer single quotes and passes the inner double quotes as part of the JSON. If you drop the outer quotes, Bash can consume the JSON quotes itself.

If a variable already contains the whole object, pass --settings "$settings_json". An unquoted $settings_json can split JSON containing spaces into several arguments. The form '$settings_json' passes the literal variable name, including the dollar sign. If a CI template supplies the value, check it after the last Bash expansion. Bash quoting rules

[3] Check that the variable contains exactly one JSON object before starting Claude Code.

console
$ settings_json='{"env":{"BUILD_LABEL":"nightly build"}}'$ printf '%s\n' "$settings_json" | jq -e -s 'length == 1 and (.[0] | type == "object")' >/dev/null

If jq is available, substitute the value your CI job supplies in the first line. Exit code 0 means jq read one object. The example returned 0. The same check returned nonzero for both {"probe":} and {} {}. The -s option lets the filter count the parsed values and catch two objects joined together. This check covers syntax and shape. Validate the actual settings keys and values against the settings reference. jq options

[4] Use a JSON encoder for strings supplied by CI.

Quotes and line breaks in a value need JSON escaping. Pass the original string with jq --arg and let jq encode it. Exit the script immediately if generation fails.

conf
build_label='nightly "canary" build'settings_json=$(jq -cn --arg label "$build_label" '{env: {BUILD_LABEL: $label}}') || exit 1

Pass --settings "$settings_json" to your existing command. In this example, BUILD_LABEL is an environment variable for the Claude Code session and its subprocesses. If the real input contains a secret, use the exit status from step 3 and keep the JSON out of CI logs. The env setting

[5] Use a file if quoting across the shell and CI template gets complicated.

Save the object below as job-settings.json in your working directory. Pick a fresh name if you already use that file.

job-settings.json
{  "env": {    "BUILD_LABEL": "nightly build"  }}

Add --settings ./job-settings.json to your existing command. Resolve that relative path from the directory where Claude Code starts. The CLI reference permits regular files up to 2 MiB, and keys supplied with the flag apply to that session. If local permission rules still seem to have no effect after you fix the JSON, check where the local allow rule comes from. CLI flags

Check it with the JSON · YAML formatter and converter tool ↗ — calculated in your browser.

#claude-code#settings#json#bash#ci