|
| 1 | +Configuring Claude Code or Cursor for uv |
| 2 | +======================================== |
| 3 | + |
| 4 | +How do we configure `Claude Code <https://claude.com/product/claude-code>`_ or |
| 5 | +`Cursor <https://cursor.com>`_ to automatically use uv instead of pip for Python |
| 6 | +package management? |
| 7 | + |
| 8 | +.. tab:: Claude Code |
| 9 | + |
| 10 | + Claude Code uses :file:`CLAUDE.md` files to configure your project’s storage |
| 11 | + and context, ensuring a consistent tooling environment for your entire |
| 12 | + development workflow. |
| 13 | + |
| 14 | + Assuming Claude Code and uv are already installed on your system and you have |
| 15 | + already created a uv-based Python project, for example with :ref:`uv init |
| 16 | + <uv-package-structure>`. |
| 17 | + |
| 18 | + .. tip:: |
| 19 | + You can use the ``/init`` command in Claude Code to automatically create a |
| 20 | + :file:`CLAUDE.md` file and then add uv-specific instructions to it. |
| 21 | + |
| 22 | + .. code-block:: md |
| 23 | + :caption: CLAUDE.md |
| 24 | +
|
| 25 | + # Python environment with uv |
| 26 | + Use uv exclusively for the Python environment in this project. |
| 27 | +
|
| 28 | + ## Environment commands |
| 29 | + - Use uv to install, sync, and lock Python dependencies |
| 30 | + - Never use pip, pip-tools, poetry, or conda for dependency management |
| 31 | +
|
| 32 | + Use these commands: |
| 33 | + - Install dependencies: `uv add <package>` |
| 34 | + - Remove dependencies: `uv remove <package>` |
| 35 | + - Sync dependencies: `uv sync` |
| 36 | +
|
| 37 | + ## Running Python Code |
| 38 | + - Run a Python script with `uv run <script-name>.py` |
| 39 | + - Run Python tools like pytest with `uv run pytest` |
| 40 | +
|
| 41 | + .. tip:: |
| 42 | + Remember to manage your project-specific :file:`CLAUDE.md` file with |
| 43 | + :doc:`Git </productive/git/index>` so that everyone on the team working |
| 44 | + with Claude Code automatically receives the same configuration. |
| 45 | + |
| 46 | + .. seealso:: |
| 47 | + * `Claude Docs <https://docs.claude.com/en/home>`_ |
| 48 | + * `Manage Claude's memory |
| 49 | + <https://docs.claude.com/en/docs/claude-code/memory>`_ |
| 50 | + |
| 51 | +.. tab:: Cursor |
| 52 | + |
| 53 | + `Cursor Rules <https://cursor.com/docs/context/rules>`_ can be used to use uv |
| 54 | + instead of pip. |
| 55 | + |
| 56 | + This assumes that Cursor and uv are already installed on your system and you |
| 57 | + have already created a uv-based Python project, for example, with :ref:`uv |
| 58 | + init <uv-package-structure>`. |
| 59 | + |
| 60 | + Then you can create a *Cursor Markdown Context* file :file:`uv.mdc` in |
| 61 | + :samp:`{PROJECT}/.cursor/rules/` for your Cursor Rules in |
| 62 | + :menuselection:`View Menu --> Command Palette --> New Cursor Rule` with |
| 63 | + |
| 64 | + * Name: ``uv`` |
| 65 | + * Rule Type: *Agent Requested* |
| 66 | + * Description: *Exclusively use uv for the Python environment in this project.* |
| 67 | + |
| 68 | + Afterwards, you can add the following rules: |
| 69 | + |
| 70 | + .. code-block:: md |
| 71 | + :caption: .cursor/rules/uv.mdc |
| 72 | +
|
| 73 | + # Python environment with uv |
| 74 | + Exclusively use uv for the Python environment in this project. |
| 75 | +
|
| 76 | + ## Environment commands |
| 77 | + - Use uv to install, sync, and lock Python dependencies |
| 78 | + - Never use pip, pip-tools, poetry, or conda for dependency management |
| 79 | +
|
| 80 | + Use these commands: |
| 81 | + - Install dependencies: `uv add <package>` |
| 82 | + - Remove dependencies: `uv remove <package>` |
| 83 | + - Sync dependencies: `uv sync` |
| 84 | +
|
| 85 | + ## Running Python Code |
| 86 | + - Run a Python script with `uv run <script-name>.py` |
| 87 | + - Run Python tools like pytest with `uv run pytest` |
0 commit comments