Skip to content
Latchkey

Cargo "could not find `Cargo.toml`" in CI

Cargo walks up from the current directory looking for a Cargo.toml and found none. The job is running somewhere other than your crate root - usually a wrong working directory or an unexpected checkout layout.

What this error means

cargo fails instantly with could not find Cargo.toml in <dir> or any parent directory. The build never starts because Cargo has no manifest to work from. Common when the crate lives in a subdirectory of the repo.

cargo output
error: could not find `Cargo.toml` in `/home/runner/work/app/app` or any parent directory

Common causes

Wrong working directory in CI

The crate lives in a subfolder (e.g. backend/ or crates/api/), but the cargo step runs from the repo root where there is no Cargo.toml.

Checkout layout differs from local

A monorepo or a path the action checked out nests the crate differently than your machine, so the cwd Cargo inherits has no manifest above it.

How to fix it

Run cargo from the crate directory

Set the working directory or pass --manifest-path so Cargo points at the right Cargo.toml.

.github/workflows/ci.yml
- run: cargo build --locked
  working-directory: backend
# or, without changing cwd:
- run: cargo build --manifest-path backend/Cargo.toml --locked

Confirm where the manifest actually is

  1. Add a debug step: ls -la and find . -name Cargo.toml -maxdepth 3.
  2. Set working-directory (or --manifest-path) to that location.
  3. For workspaces, run from the workspace root that holds the virtual manifest.

How to prevent it

  • Pin working-directory for cargo steps when the crate isn’t at the repo root.
  • Use --manifest-path in shared scripts so they work regardless of cwd.
  • Keep the CI checkout layout consistent with the local repo structure.

Frequently asked questions

What causes ""could not find Cargo.toml""?
The crate lives in a subfolder (e.g. backend/ or crates/api/), but the cargo step runs from the repo root where there is no Cargo.toml.
How do I fix "could not find Cargo.toml"?
Set the working directory or pass --manifest-path so Cargo points at the right Cargo.toml.

Related guides

References

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