Skip to main content

Coinbase CLI

Headless access to Coinbase Advanced Trade. Install once, authenticate with a CDP API key, trade crypto with JSON output.

Installation

Linux only — install keyring support to avoid plaintext secrets:
nvm/fnm users: Upgrading Node versions requires reinstalling global packages. After upgrading, open a new terminal and run npm i -g @coinbase/coinbase-cli again.

Authentication

Create a CDP API key and configure the CLI:
  1. Sign in to https://portal.cdp.coinbase.com/api-keys/secret (a project is auto-created on first sign-in)
  2. Click Create API Key
  3. Give it a name (e.g., my-trading-agent)
  4. Under Advanced Settings > Coinbase App & Advanced Trade:
    • Under Accounts, select the portfolio for the agent to trade from
    • Enable Trade and Transfer (View is enabled by default)
    • Check Opt out of IP allowlisting if you haven’t configured specific IP addresses, or set your IP range to allowlist them
  5. Click Create & Download — save the JSON key file

Core Commands

Market Data

Orders

Portfolios & Balances

Conversions

Info & Session

Agent-Critical Flags

Use these flags on any command. They are the most important features for safe, efficient agent operation.

Field syntax

Workflows

1. Check price and preview a trade

2. Sell an asset

3. Transfer funds between portfolios

4. Convert USDC to USD (or vice versa)

5. Discover field names for any command

6. Filter large result sets

MCP Server Setup

The CLI includes an MCP server that exposes every command as a typed tool. If using MCP, the tool schemas are your primary reference — they include full field descriptions and enums. Claude Code:
Other agents — add to your MCP config:
Codex users: Default sandbox can’t access OS keychain. Either prompt Codex for “elevated access” or use the MCP server instead of direct CLI commands.

Install agent skills

Install skills so the agent has step-by-step guidance for common Coinbase workflows (trading, market data, watch, convert, portfolios):
If non-interactive, pass the skills directory explicitly:
Skills auto-update on future npm install -g @coinbase/coinbase-cli upgrades.

Permissions

By default agents prompt before each coinbase command. To reduce or remove those prompts, allow-list commands in your agent’s permission settings. Offer the user two tiers:
  • Read-only — never prompted for safe reads (prices, balances, history); still prompted before any order or transfer. Good default.
  • Everything — never prompted at all, including orders and transfers. Confirm explicitly before enabling.
Allow-list rules for each tier: How to apply depends on the agent. For Claude Code, add the rules to permissions.allow in settings.json (e.g. Bash(coinbase products *)) — ~/.claude/settings.json for all projects or .claude/settings.json to share with a team. Other agents have their own allow-list mechanism.

Gotchas

  • Products list returns 900+ items. Use symbol==USD to filter by currency, or --jq for custom filters.
  • client_order_id prevents duplicate orders. If your connection drops mid-request, retrying with the same client_order_id returns the existing order instead of creating a new one. Always generate one per order attempt.
  • nvm/fnm users: Upgrading Node versions requires reinstalling global packages. After upgrading, open a new terminal and run npm i -g @coinbase/coinbase-cli again.

Troubleshooting