Skip to content
Latchkey

GitHub Actions "Unable to process file command 'env' ... Invalid format"

A step wrote a value containing newlines to GITHUB_ENV with the simple name=value form, so every line after the first is parsed as its own malformed file command and the runner rejects the write.

What this error means

A step that appends to "$GITHUB_ENV" fails with "Unable to process file command 'env' successfully" followed by "Invalid format", naming the stray line. The variable is never set for later steps.

Actions log
Error: Unable to process file command 'env' successfully.
Error: Invalid format '  "scope": "read"'

Common causes

Multiline value with name=value

The name=value form only supports single-line values. A value with embedded newlines (JSON, a certificate, multi-line output) makes every line after the first an invalid env file command.

Command output piped straight into GITHUB_ENV

Piping a command that emits multiple lines (or trailing newlines) directly into "$GITHUB_ENV" without a delimiter produces the same parse failure.

How to fix it

Use the heredoc delimiter form

Write name<<DELIM, the value, then DELIM on its own line, using a delimiter that cannot appear in the value.

.github/workflows/ci.yml
- run: |
    {
      echo "CONFIG<<EOF"
      cat config.json
      echo "EOF"
    } >> "$GITHUB_ENV"

Collapse to a single line when possible

  1. For a single-line value, strip newlines before writing, e.g. tr -d "\n".
  2. Pick a random delimiter (uuidgen) when the value might contain EOF.
  3. Quote the path as "$GITHUB_ENV" so spaces do not break the redirect.

How to prevent it

  • Always use the heredoc form for any value that may contain newlines.
  • Use a unique delimiter token to avoid collisions with the content.
  • Validate that piped command output is single-line before name=value.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →