diff --git a/NEWS.rst b/NEWS.rst
index 220b9f76..8c97e0f1 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -19,6 +19,7 @@ Bug Fixes
 * Quoted f-strings are no longer evaluated prematurely.
 * Fixed a regression in the production of error messages for empty
   expressions.
+* Fixed a scoping bug for code executed with `hy -c`.
 
 0.18.0
 ==============================
diff --git a/hy/cmdline.py b/hy/cmdline.py
index b9ffcdb5..6277d3d7 100644
--- a/hy/cmdline.py
+++ b/hy/cmdline.py
@@ -429,7 +429,7 @@ def run_command(source, filename=None):
         return 1
 
     with filtered_hy_exceptions():
-        hy_eval(tree, None, __main__, filename=filename, source=source)
+        hy_eval(tree, __main__.__dict__, __main__, filename=filename, source=source)
     return 0
 
 

`lfor` can't see an imported name in `hy -c`
This one is deeply bizarre.

```
$ CODE='(import math) (print (lfor j [1] (math.sqrt 5)))' 
$ hy -c "$CODE"
Traceback (most recent call last):
  File "/usr/local/bin/hy", line 8, in <module>
    sys.exit(hy_main())
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <listcomp>
NameError: name 'math' is not defined
$ echo "$CODE" | hy           
hy 0.18.0 using CPython(default) 3.7.5 on Linux
=> [2.23606797749979]
=> 
now exiting HyREPL...
$ echo "$CODE" > /tmp/foo.hy && hy /tmp/foo.hy 
[2.23606797749979]
```
diff --git a/tests/test_bin.py b/tests/test_bin.py
index 6c8e51c7..9bb63c8f 100644
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -266,6 +266,10 @@ def test_bin_hy_cmd():
     _, err = run_cmd("hy -c \"(koan\"", expect=1)
     assert "Premature end of input" in err
 
+    # https://github.com/hylang/hy/issues/1879
+    output, _ = run_cmd(
+        """hy -c '(setv x "bing") (defn f [] (+ "fiz" x)) (print (f))'""")
+    assert 'fizbing' in output
 
 def test_bin_hy_icmd():
     output, _ = run_cmd("hy -i \"(koan)\"", "(ideas)")

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.7
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
appdirs==1.4.4
astor==0.8.1
Babel==2.14.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
colorama==0.4.6
coverage==7.2.7
distlib==0.3.9
docutils==0.17.1
exceptiongroup==1.2.2
filelock==3.12.2
flake8==5.0.4
funcparserlib==1.0.1
-e git+https://github.com/hylang/hy.git@6fb668e886da53269ef9b9f6b1665563902e75ed#egg=hy
idna==3.10
imagesize==1.4.1
importlib-metadata==4.2.0
iniconfig==2.0.0
Jinja2==3.1.6
MarkupSafe==2.1.5
mccabe==0.7.0
packaging==24.0
platformdirs==2.6.2
pluggy==1.2.0
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
Pygments==2.17.2
pytest==7.4.4
pytz==2025.2
requests==2.31.0
rply==0.7.8
six==1.17.0
snowballstemmer==2.2.0
Sphinx==4.3.2
sphinx-rtd-theme==1.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==2.0.1
tox==3.28.0
typing_extensions==4.7.1
urllib3==2.0.7
virtualenv==20.16.2
zipp==3.15.0

name: hy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - appdirs==1.4.4
      - astor==0.8.1
      - babel==2.14.0
      - charset-normalizer==3.4.1
      - colorama==0.4.6
      - coverage==7.2.7
      - distlib==0.3.9
      - docutils==0.17.1
      - exceptiongroup==1.2.2
      - filelock==3.12.2
      - flake8==5.0.4
      - funcparserlib==1.0.1
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.2.0
      - iniconfig==2.0.0
      - jinja2==3.1.6
      - markupsafe==2.1.5
      - mccabe==0.7.0
      - packaging==24.0
      - platformdirs==2.6.2
      - pluggy==1.2.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pygments==2.17.2
      - pytest==7.4.4
      - pytz==2025.2
      - requests==2.31.0
      - rply==0.7.8
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==4.3.2
      - sphinx-rtd-theme==1.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==2.0.1
      - tox==3.28.0
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - virtualenv==20.16.2
      - zipp==3.15.0
prefix: /opt/conda/envs/hy

tests/test_bin.py::test_bin_hy_cmd
tests/test_bin.py::test_bin_hy tests/test_bin.py::test_bin_hy_stdin tests/test_bin.py::test_bin_hy_stdin_multiline tests/test_bin.py::test_bin_hy_history tests/test_bin.py::test_bin_hy_stdin_comments tests/test_bin.py::test_bin_hy_stdin_assignment tests/test_bin.py::test_bin_hy_stdin_as_arrow tests/test_bin.py::test_bin_hy_stdin_error_underline_alignment tests/test_bin.py::test_bin_hy_stdin_except_do tests/test_bin.py::test_bin_hy_stdin_unlocatable_hytypeerror tests/test_bin.py::test_bin_hy_error_parts_length tests/test_bin.py::test_bin_hy_stdin_bad_repr tests/test_bin.py::test_bin_hy_stdin_hy_repr tests/test_bin.py::test_bin_hy_ignore_python_env tests/test_bin.py::test_bin_hy_icmd tests/test_bin.py::test_bin_hy_icmd_file tests/test_bin.py::test_bin_hy_icmd_and_spy tests/test_bin.py::test_bin_hy_missing_file tests/test_bin.py::test_bin_hy_file_with_args tests/test_bin.py::test_bin_hyc tests/test_bin.py::test_bin_hyc_missing_file tests/test_bin.py::test_bin_hy_builtins tests/test_bin.py::test_bin_hy_main tests/test_bin.py::test_bin_hy_main_args tests/test_bin.py::test_bin_hy_main_exitvalue tests/test_bin.py::test_bin_hy_no_main tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt0-normal] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt0-prevent_by_force] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt0-prevent_by_env] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt0-prevent_by_option] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt1-normal] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt1-prevent_by_force] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt1-prevent_by_env] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt1-prevent_by_option] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt2-normal] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt2-prevent_by_force] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt2-prevent_by_env] tests/test_bin.py::test_bin_hy_byte_compile[cmd_fmt2-prevent_by_option] tests/test_bin.py::test_bin_hy_module_main tests/test_bin.py::test_bin_hy_module_main_file tests/test_bin.py::test_bin_hy_file_main_file tests/test_bin.py::test_bin_hy_file_sys_path tests/test_bin.py::test_bin_hy_module_main_args tests/test_bin.py::test_bin_hy_module_main_exitvalue tests/test_bin.py::test_bin_hy_module_no_main tests/test_bin.py::test_bin_hy_sys_executable tests/test_bin.py::test_bin_hy_file_no_extension tests/test_bin.py::test_bin_hy_circular_macro_require tests/test_bin.py::test_bin_hy_macro_require tests/test_bin.py::test_bin_hy_tracebacks
hy/cmdline.py NEWS.rst
hy/cmdline.py NEWS.rst