Skip to content
Latchkey

Turborepo "--filter" Syntax Errors - Fix Selection in CI

Turborepo’s --filter selects packages by name, path, scope, or git range. A malformed pattern, an unfetched [ref] base, or shell quoting that eats the .../^ operators makes turbo select nothing or error.

What this error means

turbo run ... --filter=... errors on an invalid filter, or runs zero packages because a [origin/main] since-ref is not in the shallow CI clone. Deterministic for the pattern and checkout.

turbo output
  × invalid filter "...[origin/main]"
  ╰─▶ could not find git ref "origin/main" - is the history fetched?

# or: 0 packages selected

Common causes

Since-ref not present in a shallow clone

A filter like ...[origin/main] diffs against a git ref. With CI’s default depth-1 checkout the base ref is absent, so the filter resolves to nothing or errors.

Malformed filter pattern

Misusing the operators - ^ (dependents), ... (dependencies/changed), {path} globs, @scope/* - yields an invalid filter turbo rejects.

Shell quoting strips operators

Unquoted ... or {} can be altered by the shell, so turbo receives a different string than intended.

How to fix it

Fetch history for since-ref filters

Provide full history so [ref] resolves, and quote the filter so the shell leaves it intact.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with: { fetch-depth: 0 }
- run: turbo run build --filter="...[origin/main]"

Use correct filter operators

Combine name/scope, path, dependency, and changed selectors deliberately.

Terminal
turbo run test --filter=@acme/web            # one package
turbo run build --filter=@acme/web...        # package + its dependencies
turbo run lint --filter=...@acme/ui          # ui + everything depending on it
turbo run build --filter="{./apps/*}[HEAD^1]" # changed packages under apps/

How to prevent it

  • Use fetch-depth: 0 whenever a filter uses a [git-ref] base.
  • Quote --filter values so the shell does not alter operators.
  • Validate a filter with turbo run <task> --filter=... --dry first.

Frequently asked questions

What causes ""invalid --filter""?
A filter like ...[origin/main] diffs against a git ref. With CI’s default depth-1 checkout the base ref is absent, so the filter resolves to nothing or errors.
How do I fix "invalid --filter"?
Provide full history so [ref] resolves, and quote the filter so the shell leaves it intact.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card