uv for AI agents
uv for coding agents: sync Python environments from the lockfile, run tests, add packages, and run tools with uvx, plus rules for lockfiles and pins.
What uv does for an agent
uv is a fast Python package and project manager from Astral, written in Rust. It creates virtual environments, resolves and locks dependencies in uv.lock, installs Python versions, and runs tools with uvx.
uv run executes a command inside the project's environment and syncs it first, so an agent does not have to activate a virtual environment between shell calls.
Official site: astral.sh/uv
Install uv
The install commands from the official docs. Check it worked with uv --version.
curl -LsSf https://astral.sh/uv/install.sh | sh
brew install uv
Signing in uv for an agent
No account is needed. Private package indexes are configured in pyproject.toml or uv.toml, with credentials from environment variables or a keyring.
What agents use uv for
Example commands with placeholder names. Swap in your own project, app, or file names.
Install exactly what the lockfile says
uv sync --locked
Run tests in the project environment
uv run pytest
Run a tool without installing it
uvx ruff check .
Show the dependency tree
uv tree
Add a dependency
uv add httpx
Changes pyproject.toml and uv.lock. Mention it in the summary.
Safety rules for agents
Safe to run without asking
uv --versionuv treeuv sync --lockeduv run <test, lint, or type-check command>
Ask a human first
uv add / removeuv lock --upgradeuv publishuv python install (changes the machine)
- Use uv run instead of calling python or pip directly, so commands use the project's environment.
- Use --locked in CI-like checks so uv fails instead of silently rewriting uv.lock.
- Pin versions when running tools with uvx in scripts, for example uvx ruff@0.8.0, so runs are repeatable.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## uv Use `uv` for managing Python environments, dependencies, and tools. - Check it is installed with `uv --version`. If it is missing, ask before installing it. - Auth: none needed. - Run without asking (read-only): `uv --version`, `uv tree`, `uv sync --locked`, `uv run <test, lint, or type-check command>`. - Ask a human first (changes or deletes things): `uv add / remove`, `uv lock --upgrade`, `uv publish`, `uv python install (changes the machine)`. - Use uv run instead of calling python or pip directly, so commands use the project's environment. - Use --locked in CI-like checks so uv fails instead of silently rewriting uv.lock. - Pin versions when running tools with uvx in scripts, for example uvx ruff@0.8.0, so runs are repeatable. - Prefer JSON output where the command supports it, and keep output short.
uv or an MCP server?
No official MCP server. uv is a local tool, so agents run it directly. It shows up in the MCP world anyway: many Python MCP servers are launched with uvx in client configs.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Dev & Git tools
uv questions
How do I install uv?
Install script (macOS, Linux): curl -LsSf https://astral.sh/uv/install.sh | sh. Other official options: Homebrew. Check the install with uv --version, and see the Astral docs for other platforms.
How does an AI agent authenticate uv?
No account is needed. Private package indexes are configured in pyproject.toml or uv.toml, with credentials from environment variables or a keyring. There is nothing to set up: an agent can use it as soon as uv --version succeeds.
Which uv commands are safe for an agent to run?
Commands that only read state are safe to run without asking: uv --version; uv tree; uv sync --locked; uv run <test, lint, or type-check command>. Ask a human before anything that changes or deletes something: uv add / remove; uv lock --upgrade; uv publish; uv python install (changes the machine).
Is there an MCP server for uv?
uv is a local tool, so agents run it directly. It shows up in the MCP world anyway: many Python MCP servers are launched with uvx in client configs.