diff --git a/charmcraft/commands/store/__init__.py b/charmcraft/commands/store/__init__.py
index fb7c8e9..efd9445 100644
--- a/charmcraft/commands/store/__init__.py
+++ b/charmcraft/commands/store/__init__.py
@@ -1298,11 +1298,11 @@ class CreateLibCommand(BaseCommand):
                 "characters and underscore, starting with alpha."
             )
 
-        charm_name = get_name_from_metadata()
+        charm_name = self.config.name or get_name_from_metadata()
         if charm_name is None:
             raise CraftError(
-                "Cannot find a valid charm name in metadata.yaml. Check you are in a charm "
-                "directory with metadata.yaml."
+                "Cannot find a valid charm name in charm definition. "
+                "Check that you are using the correct project directory."
             )
 
         # '-' is valid in charm names, but not in a python import
@@ -1310,11 +1310,11 @@ class CreateLibCommand(BaseCommand):
         importable_charm_name = create_importable_name(charm_name)
 
         # all libraries born with API version 0
-        full_name = "charms.{}.v0.{}".format(importable_charm_name, lib_name)
+        full_name = f"charms.{importable_charm_name}.v0.{lib_name}"
         lib_data = get_lib_info(full_name=full_name)
         lib_path = lib_data.path
         if lib_path.exists():
-            raise CraftError("This library already exists: {!r}.".format(str(lib_path)))
+            raise CraftError(f"This library already exists: {str(lib_path)!r}.")
 
         emit.progress(f"Creating library {lib_name}.")
         store = Store(self.config.charmhub)
@@ -1323,12 +1323,12 @@ class CreateLibCommand(BaseCommand):
         # create the new library file from the template
         env = get_templates_environment("charmlibs")
         template = env.get_template("new_library.py.j2")
-        context = dict(lib_id=lib_id)
+        context = {"lib_id": lib_id}
         try:
             lib_path.parent.mkdir(parents=True, exist_ok=True)
             lib_path.write_text(template.render(context))
         except OSError as exc:
-            raise CraftError("Error writing the library in {!r}: {!r}.".format(str(lib_path), exc))
+            raise CraftError(f"Error writing the library in {str(lib_path)!r}: {exc!r}.")
 
         if parsed_args.format:
             info = {"library_id": lib_id}

diff --git a/tests/commands/test_store_commands.py b/tests/commands/test_store_commands.py
index 110d454..2715f6b 100644
--- a/tests/commands/test_store_commands.py
+++ b/tests/commands/test_store_commands.py
@@ -2757,31 +2757,36 @@ def test_status_unreleased_track(emitter, store_mock, config):
 
 @pytest.mark.skipif(sys.platform == "win32", reason="Windows not [yet] supported")
 @pytest.mark.parametrize("formatted", [None, JSON_FORMAT])
-def test_createlib_simple(emitter, store_mock, tmp_path, monkeypatch, config, formatted):
+@pytest.mark.parametrize("charmcraft_yaml_name", [None, "test-charm"])
+def test_createlib_simple(
+    emitter, store_mock, tmp_path, monkeypatch, config, formatted, charmcraft_yaml_name
+):
     """Happy path with result from the Store."""
     monkeypatch.chdir(tmp_path)
 
+    config.name = charmcraft_yaml_name
+
     lib_id = "test-example-lib-id"
     store_mock.create_library_id.return_value = lib_id
 
     args = Namespace(name="testlib", format=formatted)
     with patch("charmcraft.commands.store.get_name_from_metadata") as mock:
-        mock.return_value = "testcharm"
+        mock.return_value = "test-charm"
         CreateLibCommand(config).run(args)
 
     assert store_mock.mock_calls == [
-        call.create_library_id("testcharm", "testlib"),
+        call.create_library_id("test-charm", "testlib"),
     ]
     if formatted:
         expected = {"library_id": lib_id}
         emitter.assert_json_output(expected)
     else:
         expected = [
-            "Library charms.testcharm.v0.testlib created with id test-example-lib-id.",
-            "Consider 'git add lib/charms/testcharm/v0/testlib.py'.",
+            "Library charms.test_charm.v0.testlib created with id test-example-lib-id.",
+            "Consider 'git add lib/charms/test_charm/v0/testlib.py'.",
         ]
         emitter.assert_messages(expected)
-    created_lib_file = tmp_path / "lib" / "charms" / "testcharm" / "v0" / "testlib.py"
+    created_lib_file = tmp_path / "lib" / "charms" / "test_charm" / "v0" / "testlib.py"
 
     env = get_templates_environment("charmlibs")
     expected_newlib_content = env.get_template("new_library.py.j2").render(lib_id=lib_id)
@@ -2791,13 +2796,14 @@ def test_createlib_simple(emitter, store_mock, tmp_path, monkeypatch, config, fo
 def test_createlib_name_from_metadata_problem(store_mock, config):
     """The metadata wasn't there to get the name."""
     args = Namespace(name="testlib", format=None)
+    config.name = None
     with patch("charmcraft.commands.store.get_name_from_metadata") as mock:
         mock.return_value = None
         with pytest.raises(CraftError) as cm:
             CreateLibCommand(config).run(args)
         assert str(cm.value) == (
-            "Cannot find a valid charm name in metadata.yaml. Check you are in a charm "
-            "directory with metadata.yaml."
+            "Cannot find a valid charm name in charm definition. "
+            "Check that you are using the correct project directory."
         )
 
 
@@ -2856,22 +2862,20 @@ def test_createlib_path_already_there(tmp_path, monkeypatch, config):
     """The intended-to-be-created library is already there."""
     monkeypatch.chdir(tmp_path)
 
-    factory.create_lib_filepath("test-charm-name", "testlib", api=0)
+    factory.create_lib_filepath("test-charm", "testlib", api=0)
     args = Namespace(name="testlib", format=None)
-    with patch("charmcraft.commands.store.get_name_from_metadata") as mock:
-        mock.return_value = "test-charm-name"
-        with pytest.raises(CraftError) as err:
-            CreateLibCommand(config).run(args)
+    with pytest.raises(CraftError) as err:
+        CreateLibCommand(config).run(args)
 
     assert str(err.value) == (
-        "This library already exists: 'lib/charms/test_charm_name/v0/testlib.py'."
+        "This library already exists: 'lib/charms/test_charm/v0/testlib.py'."
     )
 
 
 @pytest.mark.skipif(sys.platform == "win32", reason="Windows not [yet] supported")
 def test_createlib_path_can_not_write(tmp_path, monkeypatch, store_mock, add_cleanup, config):
     """Disk error when trying to write the new lib (bad permissions, name too long, whatever)."""
-    lib_dir = tmp_path / "lib" / "charms" / "test_charm_name" / "v0"
+    lib_dir = tmp_path / "lib" / "charms" / "test_charm" / "v0"
     lib_dir.mkdir(parents=True)
     lib_dir.chmod(0o111)
     add_cleanup(lib_dir.chmod, 0o777)
@@ -2880,10 +2884,8 @@ def test_createlib_path_can_not_write(tmp_path, monkeypatch, store_mock, add_cle
     args = Namespace(name="testlib", format=None)
     store_mock.create_library_id.return_value = "lib_id"
     expected_error = "Error writing the library in .*: PermissionError.*"
-    with patch("charmcraft.commands.store.get_name_from_metadata") as mock:
-        mock.return_value = "test-charm-name"
-        with pytest.raises(CraftError, match=expected_error):
-            CreateLibCommand(config).run(args)
+    with pytest.raises(CraftError, match=expected_error):
+        CreateLibCommand(config).run(args)
 
 
 def test_createlib_library_template_is_python(emitter, store_mock, tmp_path, monkeypatch):

`create-lib` command breaks without a metadata.yaml file
### Bug Description

Without a `metadata.yaml` file, `charmcraft create-lib` fails. However, it only needs this to get the charm name.

### To Reproduce

`charmcraft init` (or with any explicit profile)
`charmcraft create-lib mylib`

### Environment

N/A

### charmcraft.yaml

```shell
N/A
```


### Relevant log output

```shell
(charmcraft) lengau@hyperion:~/Work/Test/charms/tmp$ charmcraft init --profile=kubernetes
Charmed operator package file and directory tree initialised.                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                 
Now edit the following package files to provide fundamental charm metadata                                                                                                                                                                                                       
and other information:                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                 
charmcraft.yaml                                                                                                                                                                                                                                                                  
src/charm.py                                                                                                                                                                                                                                                                     
README.md                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                 
(charmcraft) lengau@hyperion:~/Work/Test/charms/tmp$ charmcraft create-lib mylib
Cannot find a valid charm name in metadata.yaml. Check you are in a charm directory with metadata.yaml.                                                                                                                                                                          
Full execution log: '/home/lengau/.local/state/charmcraft/log/charmcraft-20230818-165535.506311.log'
```

tests/commands/test_store_commands.py::test_createlib_name_from_metadata_problem tests/commands/test_store_commands.py::test_createlib_path_already_there
tests/commands/test_store_commands.py::test_login_simple tests/commands/test_store_commands.py::test_login_exporting tests/commands/test_store_commands.py::test_login_restrictions_without_export[charm] tests/commands/test_store_commands.py::test_login_restrictions_without_export[bundle] tests/commands/test_store_commands.py::test_login_restrictions_without_export[permission] tests/commands/test_store_commands.py::test_login_restrictions_without_export[channel] tests/commands/test_store_commands.py::test_login_restrictions_without_export[ttl] tests/commands/test_store_commands.py::test_login_restricting_ttl tests/commands/test_store_commands.py::test_login_restricting_channels tests/commands/test_store_commands.py::test_login_restricting_permissions tests/commands/test_store_commands.py::test_login_restricting_permission_invalid tests/commands/test_store_commands.py::test_login_restricting_charms tests/commands/test_store_commands.py::test_login_restricting_bundles tests/commands/test_store_commands.py::test_login_restriction_mix tests/commands/test_store_commands.py::test_logout tests/commands/test_store_commands.py::test_logout_but_not_logged_in tests/commands/test_store_commands.py::test_whoami[None] tests/commands/test_store_commands.py::test_whoami[json] tests/commands/test_store_commands.py::test_whoami_but_not_logged_in[None] tests/commands/test_store_commands.py::test_whoami_but_not_logged_in[json] tests/commands/test_store_commands.py::test_whoami_with_channels[None] tests/commands/test_store_commands.py::test_whoami_with_channels[json] tests/commands/test_store_commands.py::test_whoami_with_charms[None] tests/commands/test_store_commands.py::test_whoami_with_charms[json] tests/commands/test_store_commands.py::test_whoami_with_bundles[None] tests/commands/test_store_commands.py::test_whoami_with_bundles[json] tests/commands/test_store_commands.py::test_whoami_comprehensive tests/commands/test_store_commands.py::test_register_charm_name tests/commands/test_store_commands.py::test_register_bundle_name tests/commands/test_store_commands.py::test_unregister_name tests/commands/test_store_commands.py::test_list_registered_empty[None] tests/commands/test_store_commands.py::test_list_registered_empty[json] tests/commands/test_store_commands.py::test_list_registered_one_private[None] tests/commands/test_store_commands.py::test_list_registered_one_private[json] tests/commands/test_store_commands.py::test_list_registered_one_public[None] tests/commands/test_store_commands.py::test_list_registered_one_public[json] tests/commands/test_store_commands.py::test_list_registered_several[None] tests/commands/test_store_commands.py::test_list_registered_several[json] tests/commands/test_store_commands.py::test_list_registered_with_collaborations[None] tests/commands/test_store_commands.py::test_list_registered_with_collaborations[json] tests/commands/test_store_commands.py::test_get_name_bad_zip tests/commands/test_store_commands.py::test_get_name_charm_ok tests/commands/test_store_commands.py::test_get_name_charm_bad_metadata[=] tests/commands/test_store_commands.py::test_get_name_charm_bad_metadata[foo: tests/commands/test_store_commands.py::test_get_name_bundle_ok tests/commands/test_store_commands.py::test_get_name_bundle_bad_data[=] tests/commands/test_store_commands.py::test_get_name_bundle_bad_data[foo: tests/commands/test_store_commands.py::test_get_name_nor_charm_nor_bundle tests/commands/test_store_commands.py::test_upload_parameters_filepath_type tests/commands/test_store_commands.py::test_upload_call_ok[None] tests/commands/test_store_commands.py::test_upload_call_ok[json] tests/commands/test_store_commands.py::test_upload_call_error[None] tests/commands/test_store_commands.py::test_upload_call_error[json] tests/commands/test_store_commands.py::test_upload_call_login_expired[None] tests/commands/test_store_commands.py::test_upload_call_login_expired[json] tests/commands/test_store_commands.py::test_upload_call_ok_including_release[None] tests/commands/test_store_commands.py::test_upload_call_ok_including_release[json] tests/commands/test_store_commands.py::test_upload_call_ok_including_release_multiple tests/commands/test_store_commands.py::test_upload_including_release_with_resources[None] tests/commands/test_store_commands.py::test_upload_including_release_with_resources[json] tests/commands/test_store_commands.py::test_upload_options_resource tests/commands/test_store_commands.py::test_upload_call_error_including_release tests/commands/test_store_commands.py::test_upload_with_different_name_than_in_metadata tests/commands/test_store_commands.py::test_revisions_simple[None] tests/commands/test_store_commands.py::test_revisions_simple[json] tests/commands/test_store_commands.py::test_revisions_empty[None] tests/commands/test_store_commands.py::test_revisions_empty[json] tests/commands/test_store_commands.py::test_revisions_ordered_by_revision[None] tests/commands/test_store_commands.py::test_revisions_ordered_by_revision[json] tests/commands/test_store_commands.py::test_revisions_version_null[None] tests/commands/test_store_commands.py::test_revisions_version_null[json] tests/commands/test_store_commands.py::test_revisions_errors_simple[None] tests/commands/test_store_commands.py::test_revisions_errors_simple[json] tests/commands/test_store_commands.py::test_revisions_errors_multiple[None] tests/commands/test_store_commands.py::test_revisions_errors_multiple[json] tests/commands/test_store_commands.py::test_release_simple_ok tests/commands/test_store_commands.py::test_release_simple_multiple_channels tests/commands/test_store_commands.py::test_release_including_resources tests/commands/test_store_commands.py::test_release_options_resource tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs0-expected_parsed0] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs1-expected_parsed1] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs2-expected_parsed2] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs3-expected_parsed3] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs4-expected_parsed4] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs5-expected_parsed5] tests/commands/test_store_commands.py::test_release_parameters_ok[sysargs6-expected_parsed6] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs0] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs1] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs2] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs3] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs4] tests/commands/test_store_commands.py::test_release_parameters_bad[sysargs5] tests/commands/test_store_commands.py::test_close_simple_ok tests/commands/test_store_commands.py::test_status_simple_ok[None] tests/commands/test_store_commands.py::test_status_simple_ok[json] tests/commands/test_store_commands.py::test_status_empty[None] tests/commands/test_store_commands.py::test_status_empty[json] tests/commands/test_store_commands.py::test_status_channels_not_released_with_fallback[None] tests/commands/test_store_commands.py::test_status_channels_not_released_with_fallback[json] tests/commands/test_store_commands.py::test_status_channels_not_released_without_fallback[None] tests/commands/test_store_commands.py::test_status_channels_not_released_without_fallback[json] tests/commands/test_store_commands.py::test_status_multiple_tracks[None] tests/commands/test_store_commands.py::test_status_multiple_tracks[json] tests/commands/test_store_commands.py::test_status_tracks_order tests/commands/test_store_commands.py::test_status_with_one_branch[None] tests/commands/test_store_commands.py::test_status_with_one_branch[json] tests/commands/test_store_commands.py::test_status_with_multiple_branches tests/commands/test_store_commands.py::test_status_with_resources[None] tests/commands/test_store_commands.py::test_status_with_resources[json] tests/commands/test_store_commands.py::test_status_with_resources_missing_after_closed_channel tests/commands/test_store_commands.py::test_status_with_resources_and_branches tests/commands/test_store_commands.py::test_status_multiplebases_single_track[None] tests/commands/test_store_commands.py::test_status_multiplebases_single_track[json] tests/commands/test_store_commands.py::test_status_multiplebases_multiple_tracks tests/commands/test_store_commands.py::test_status_multiplebases_everything_combined tests/commands/test_store_commands.py::test_status_multiplebases_multiplebranches tests/commands/test_store_commands.py::test_status_with_base_in_none[None] tests/commands/test_store_commands.py::test_status_with_base_in_none[json] tests/commands/test_store_commands.py::test_status_unreleased_track tests/commands/test_store_commands.py::test_createlib_simple[None-None] tests/commands/test_store_commands.py::test_createlib_simple[None-json] tests/commands/test_store_commands.py::test_createlib_simple[test-charm-None] tests/commands/test_store_commands.py::test_createlib_simple[test-charm-json] tests/commands/test_store_commands.py::test_createlib_name_contains_dash tests/commands/test_store_commands.py::test_createlib_invalid_name[foo.bar] tests/commands/test_store_commands.py::test_createlib_invalid_name[foo/bar] tests/commands/test_store_commands.py::test_createlib_invalid_name[Foo] tests/commands/test_store_commands.py::test_createlib_invalid_name[123foo] tests/commands/test_store_commands.py::test_createlib_invalid_name[_foo] tests/commands/test_store_commands.py::test_createlib_invalid_name[] tests/commands/test_store_commands.py::test_createlib_library_template_is_python tests/commands/test_store_commands.py::test_publishlib_simple[None] tests/commands/test_store_commands.py::test_publishlib_simple[json] tests/commands/test_store_commands.py::test_publishlib_contains_dash tests/commands/test_store_commands.py::test_publishlib_all[None] tests/commands/test_store_commands.py::test_publishlib_all[json] tests/commands/test_store_commands.py::test_publishlib_not_found tests/commands/test_store_commands.py::test_publishlib_not_from_current_charm tests/commands/test_store_commands.py::test_publishlib_name_from_metadata_problem tests/commands/test_store_commands.py::test_publishlib_store_is_advanced[None] tests/commands/test_store_commands.py::test_publishlib_store_is_advanced[json] tests/commands/test_store_commands.py::test_publishlib_store_is_exactly_behind_ok tests/commands/test_store_commands.py::test_publishlib_store_is_exactly_behind_same_hash[None] tests/commands/test_store_commands.py::test_publishlib_store_is_exactly_behind_same_hash[json] tests/commands/test_store_commands.py::test_publishlib_store_is_too_behind[None] tests/commands/test_store_commands.py::test_publishlib_store_is_too_behind[json] tests/commands/test_store_commands.py::test_publishlib_store_has_same_revision_same_hash[None] tests/commands/test_store_commands.py::test_publishlib_store_has_same_revision_same_hash[json] tests/commands/test_store_commands.py::test_publishlib_store_has_same_revision_other_hash[None] tests/commands/test_store_commands.py::test_publishlib_store_has_same_revision_other_hash[json] tests/commands/test_store_commands.py::test_fetchlib_simple_downloaded[None] tests/commands/test_store_commands.py::test_fetchlib_simple_downloaded[json] tests/commands/test_store_commands.py::test_fetchlib_simple_dash_in_name tests/commands/test_store_commands.py::test_fetchlib_simple_dash_in_name_on_disk tests/commands/test_store_commands.py::test_fetchlib_simple_updated tests/commands/test_store_commands.py::test_fetchlib_all[None] tests/commands/test_store_commands.py::test_fetchlib_all[json] tests/commands/test_store_commands.py::test_fetchlib_store_not_found[None] tests/commands/test_store_commands.py::test_fetchlib_store_not_found[json] tests/commands/test_store_commands.py::test_fetchlib_store_is_old[None] tests/commands/test_store_commands.py::test_fetchlib_store_is_old[json] tests/commands/test_store_commands.py::test_fetchlib_store_same_versions_same_hash[None] tests/commands/test_store_commands.py::test_fetchlib_store_same_versions_same_hash[json] tests/commands/test_store_commands.py::test_fetchlib_store_same_versions_different_hash[None] tests/commands/test_store_commands.py::test_fetchlib_store_same_versions_different_hash[json] tests/commands/test_store_commands.py::test_listlib_simple[None] tests/commands/test_store_commands.py::test_listlib_simple[json] tests/commands/test_store_commands.py::test_listlib_charm_from_metadata tests/commands/test_store_commands.py::test_listlib_name_from_metadata_problem tests/commands/test_store_commands.py::test_listlib_empty[None] tests/commands/test_store_commands.py::test_listlib_empty[json] tests/commands/test_store_commands.py::test_listlib_properly_sorted[None] tests/commands/test_store_commands.py::test_listlib_properly_sorted[json] tests/commands/test_store_commands.py::test_resources_simple[None] tests/commands/test_store_commands.py::test_resources_simple[json] tests/commands/test_store_commands.py::test_resources_empty[None] tests/commands/test_store_commands.py::test_resources_empty[json] tests/commands/test_store_commands.py::test_resources_ordered_and_grouped[None] tests/commands/test_store_commands.py::test_resources_ordered_and_grouped[json] tests/commands/test_store_commands.py::test_uploadresource_options_filepath_type tests/commands/test_store_commands.py::test_uploadresource_options_image_type tests/commands/test_store_commands.py::test_uploadresource_options_good_combinations[sysargs0] tests/commands/test_store_commands.py::test_uploadresource_options_good_combinations[sysargs1] tests/commands/test_store_commands.py::test_uploadresource_options_bad_combinations[sysargs0] tests/commands/test_store_commands.py::test_uploadresource_options_bad_combinations[sysargs1] tests/commands/test_store_commands.py::test_uploadresource_filepath_call_ok[None] tests/commands/test_store_commands.py::test_uploadresource_filepath_call_ok[json] tests/commands/test_store_commands.py::test_uploadresource_image_digest_already_uploaded[None] tests/commands/test_store_commands.py::test_uploadresource_image_digest_already_uploaded[json] tests/commands/test_store_commands.py::test_uploadresource_image_digest_upload_from_local tests/commands/test_store_commands.py::test_uploadresource_image_id_upload_from_local tests/commands/test_store_commands.py::test_uploadresource_image_digest_missing_everywhere tests/commands/test_store_commands.py::test_uploadresource_image_id_missing tests/commands/test_store_commands.py::test_uploadresource_call_error[None] tests/commands/test_store_commands.py::test_uploadresource_call_error[json] tests/commands/test_store_commands.py::test_resourcerevisions_simple[None] tests/commands/test_store_commands.py::test_resourcerevisions_simple[json] tests/commands/test_store_commands.py::test_resourcerevisions_empty[None] tests/commands/test_store_commands.py::test_resourcerevisions_empty[json] tests/commands/test_store_commands.py::test_resourcerevisions_ordered_by_revision[None] tests/commands/test_store_commands.py::test_resourcerevisions_ordered_by_revision[json]