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

Diagnose it: toolchain, features, or a stale target dir?

Cargo failures that only appear in CI are usually a different toolchain channel, a different feature set resolved by the dependency graph, or a target directory restored from a cache built with different flags.

Terminal
rustc --version --verbose
cargo --version
cat rust-toolchain.toml 2>/dev/null

# which features actually got enabled across the graph?
cargo tree -e features | head -40

# rule out a poisoned cache before anything else
cargo clean && cargo build --locked

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 Cargo "could not find Cargo.toml" in CI?
There are 2 common causes: wrong working directory in ci and checkout layout differs from local. The crate lives in a subfolder (e.g.
How do I fix Cargo "could not find Cargo.toml" in CI?
There are 2 fixes depending on which cause you have: run cargo from the crate directory and confirm where the manifest actually is. Work through them in order, since the first is the most common.
What does Cargo "could not find Cargo.toml" in CI actually mean?
cargo fails instantly with could not find Cargo.toml in <dir> or any parent directory.
How do I stop Cargo "could not find Cargo.toml" in CI happening again?
Pin working-directory for cargo steps when the crate isn’t at the repo root. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card