Skip to content
Latchkey

GitHub Actions "The expression contains invalid characters" in CI

The expression tokenizer accepts a limited character set. A smart quote pasted from a document, a non-ASCII dash, or a stray symbol inside ${{ }} is rejected as an invalid character.

What this error means

The run fails with "Invalid workflow file" and a message that the expression at the given position contains invalid characters, often after copying an expression from a chat or doc.

GitHub Actions
Invalid workflow file: .github/workflows/ci.yml
(Line: 10, Col: 13): The expression contains invalid characters

Common causes

Smart quotes pasted into the expression

Curly quotes replace the straight ' or " that the tokenizer expects inside string literals.

A non-ASCII symbol inside the braces

An en/em dash, non-breaking space, or other unicode punctuation slipped into the expression.

How to fix it

Retype the expression with plain ASCII

  1. Delete the expression and retype it by hand.
  2. Use straight quotes and a plain hyphen if needed.
  3. Re-run the workflow.
.github/workflows/ci.yml
# replace curly quotes with straight quotes
if: ${{ github.ref == 'refs/heads/main' }}

Strip non-ASCII characters from the file

Search the workflow for non-ASCII bytes and replace them.

Terminal
grep -nP '[^\x00-\x7F]' .github/workflows/ci.yml

How to prevent it

  • Disable smart-quote substitution in your editor for code.
  • Avoid pasting expressions from rich-text sources.
  • Lint for non-ASCII characters in workflow files.

Related guides

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