     |> List.delete(to_string(Mix.Project.config[:app]))
   end
 
-  defp filter_loaded(apps, opts) do
-    load_opts = if only = opts[:only], do: [env: :"#{only}"], else: []
-    load_deps = Mix.Dep.loaded(load_opts) |> Enum.map(&Atom.to_string(&1.app))
-    Enum.reject(apps, &(&1 in load_deps))
+  defp filter_loaded(apps, deps) do
+    apps -- Enum.map(deps, &Atom.to_string(&1.app))
   end
 
-  defp do_clean(apps, build, deps, build_only?) do
+  defp do_clean(apps, deps, build_path, deps_path, build_only?) do
     shell = Mix.shell
-    loaded_deps = Mix.Dep.loaded([])
 
-    Enum.each apps, fn(app) ->
+    local =
+      for %{scm: scm, app: app} <- deps,
+          not scm.fetchable?,
+          do: Atom.to_string(app)
+
+    Enum.each apps, fn app ->
       shell.info "* Cleaning #{app}"
 
       # Remove everything from the build directory of dependencies
-      build
+      build_path
       |> Path.join(to_string(app))
       |> Path.wildcard
       |> Enum.each(&File.rm_rf!/1)

    Mix.Project.get!
    {opts, apps, _} = OptionParser.parse(args, switches: @switches)

    build = Mix.Project.build_path
            |> Path.dirname
            |> Path.join("#{opts[:only] || :*}/lib")
    deps = Mix.Project.deps_path

    apps_to_clean = cond do
      opts[:all] -> checked_deps(build, deps)
      opts[:unused] -> checked_deps(build, deps) |> filter_loaded(opts)
      apps != [] -> apps
      true ->
        Mix.raise "\"mix deps.clean\" expects dependencies as arguments or " <>

                  "the --unused option cleans unused dependencies"
    end

    do_clean(apps_to_clean, loaded_deps, build_path, deps_path, opts[:build])

    if opts[:unlock] do
      Mix.Task.run "deps.unlock", args
