Using CLI with AI agents

Let AI coding agents use DeepSource CLI to read analysis data and act on it

AI coding agents like Claude Code, Cursor, and similar tools can use DeepSource CLI to fetch code health data and act on it directly.

Setup

Install CLI

curl -fsSL https://cli.deepsource.com/install | sh

Authenticate

deepsource auth login

Once authenticated, any AI agent running in your terminal has access to the same CLI commands you do.

Workflow examples

Fetch and fix issues

Ask your agent to pull critical issues from the current branch and fix them:

deepsource issues --severity critical --output json

The agent gets back structured data with file paths, line numbers, issue descriptions, and suggested fixes. That's usually enough context to make targeted code changes.

Check metrics before and after changes

Have the agent check metrics for the current branch to understand the impact of its changes:

deepsource metrics --output json

Returns code health metrics like code coverage, documentation coverage, and overall code health scores for the current branch. Useful for comparing metrics before and after the agent makes changes to track improvement across iterations.

Review analysis runs

The agent can check the most recent analysis runs on the current branch to see whether they completed and what they found:

deepsource runs --output json

Returns the status of recent analysis runs, including any new issues introduced or resolved. This helps the agent verify that its changes haven't introduced regressions.

Check vulnerabilities

The agent can fetch dependency vulnerabilities detected on the current branch and suggest dependency upgrades:

deepsource vulnerabilities --output json

Returns a list of known vulnerabilities in your dependencies along with severity levels and affected packages. The agent can use this to prioritize and apply the necessary upgrades.

Tips

  • Always use --output json. AI agents work better with structured data than formatted tables.
  • Use --repo gh/org/repo explicitly if the agent's working directory isn't inside the repository.
  • Use --commit <sha> to get results for a specific point in time rather than the latest analysis.
  • Use flags like --severity, --analyzer, and --category to focus the agent on what matters.

On this page