magecli

magecli by Atlantic BT

A Magento 2 CLI for developers and AI agents. Query products, inventory, promotions, configuration, and content via the REST API. Ships with prebuilt AI skills for Claude Code and Codex.

$ go install github.com/atlanticbt/magecli/cmd/magecli@latest

Why magecli?

Give your AI agent direct access to Magento

AI coding agents like Claude Code and Codex CLI are transforming how developers work with complex systems. But they can only use what they can reach. Without magecli, asking an agent to "check if SKU X is in stock" or "find all products under $50" means the agent has no way to answer — it can't call the Magento REST API on its own.

magecli bridges that gap. It ships with prebuilt skill definitions that plug directly into Claude Code and Codex. Once installed, your agent automatically discovers magecli and can query products, browse categories, check inventory, inspect CMS content, and explore store configuration — all through simple CLI commands it already knows how to run.

Example: Ask Claude Code "What configurable products do we have priced over $200?" and it runs:
magecli product list --filter "price gt 200" --filter "type_id eq configurable" --json --jq '.items[] | {sku, name, price}'

The skill files teach the agent the full command syntax, filter operators, output modes, and context management — so it writes correct commands on the first try without you having to explain the Magento API.

Just as useful without an agent

Magento 2's REST API is powerful but verbose. A simple product lookup requires constructing complex searchCriteria query parameters, managing authentication headers, and parsing nested JSON. magecli wraps all of that in a clean, composable CLI that feels like gh or aws-cli.

Built for AI Agents

Ships with skill definitions for Claude Code and Codex CLI. Install once, and your agent can query any connected Magento store autonomously.

Structured Output

--json, --yaml, --jq, and --template on every command. Agents parse JSON; humans read tables. Both work out of the box.

Human-Friendly Filters

Write --filter "price gt 50" instead of encoding searchCriteria[filter_groups][0]... by hand.

Read-Only by Default

Contexts block write operations unless explicitly enabled with --allow-writes. Safe to hand to an AI agent pointed at production.

Multi-Store Contexts

Switch between production, staging, and dev in one flag. Tokens stored in your OS keyring, never in config files.

Single Binary

No runtime deps. Cross-compiled for Linux, macOS, and Windows — amd64 and arm64. Install in seconds.

Why a CLI instead of MCP?

An MCP server is another way to connect an AI agent to Magento, but it comes with overhead: a Node or Python runtime, a long-lived server process, JSON-RPC transport configuration, and custom code to maintain. Every tool call also burns tokens on the MCP protocol framing before you even get to the Magento data.

magecli is a static binary. There's no runtime, no server, no process to keep alive. It works in CI, Docker, SSH sessions, and local dev — anywhere you can run a command. The agent calls it like any other CLI tool, gets compact JSON back, and moves on. Less infrastructure, fewer tokens per interaction, and nothing to babysit.

Installation

Quick Install Recommended

The install scripts auto-detect your OS and architecture, download the latest release, verify the checksum, and place the binary in your PATH.

Linux / macOS

curl -fsSL https://raw.githubusercontent.com/atlanticbt/magecli/main/install.sh | sh

Windows (PowerShell)

irm https://raw.githubusercontent.com/atlanticbt/magecli/main/install.ps1 | iex

Options: Use --dir to change the install location or --version to pin a specific release:

# Custom install directory and version
curl -fsSL https://raw.githubusercontent.com/atlanticbt/magecli/main/install.sh | sh -s -- --dir ~/.local/bin --version v1.0.0

From Go

go install github.com/atlanticbt/magecli/cmd/magecli@latest

From Source

git clone https://github.com/atlanticbt/magecli.git
cd magecli
make build
# Binary at bin/magecli

From GitHub Releases (manual)

Download the archive for your platform from GitHub Releases and extract the binary to a directory in your PATH.

Verify the installation:

magecli --version

Updating

magecli can update itself to the latest release directly from GitHub. The update command downloads the correct binary for your platform, verifies the SHA-256 checksum, and replaces the current binary in place.

# Update to the latest release
magecli update

# Reinstall even if already on the latest version
magecli update --force

Setup Tutorial

Four steps to your first query.

1

Create an Integration Token in Magento

magecli authenticates with Integration Access Tokens — permanent bearer tokens created in the Magento Admin.

  1. Log in to the Magento Admin Panel
  2. Navigate to System > Extensions > Integrations
  3. Click Add New Integration
  4. On the Integration Info tab, enter a name (e.g., magecli). Leave callback and identity link URLs blank.
  5. On the API tab, select the resources the integration needs. Use All for full read access, or scope to specific resources (Catalog, CMS, Sales, etc.).
  6. Click Save, then Activate
  7. Confirm the permissions popup. Magento displays four tokens:
TokenUsed by magecli?
Consumer KeyNo
Consumer SecretNo
Access TokenYes — copy this one
Access Token SecretNo

Tip: Integration tokens don't expire. For production, scope the integration to the minimum resources needed. You can revoke the token at any time from the Integrations page.

2

Authenticate

Store the Access Token in your OS keyring:

magecli auth login https://store.example.com --token <access-token>

On headless servers without a keyring backend:

magecli auth login https://store.example.com --token <access-token> --allow-insecure-store

Or use an environment variable instead:

export MAGECLI_TOKEN=<access-token>
3

Create a Context

A context links a name to a host and store code:

magecli context create production --host store.example.com --store-code default --set-active

Contexts are read-only by default. To allow write operations via the api command:

magecli context create dev --host dev.example.com --allow-writes --set-active
4

Start Querying

# List products
magecli product list --limit 10

# Search by name
magecli product search "blue shirt"

# View product details as JSON
magecli product view SKU123 --json

# Browse the category tree
magecli category tree

# Check inventory
magecli inventory status SKU123

Command Reference

CommandDescription
auth login <host> --token <t>Store a bearer token for a host
auth statusShow auth status for all hosts
auth logout <host>Remove credentials for a host
context create <name>Create a named context
context listList contexts (* = active)
context use <name>Switch active context
context delete <name>Delete a context
product listList/search products with filters
product search <term>Quick name search
product view <sku>View product details by SKU
product media <sku>List images and videos
product children <sku>List configurable variants
product options <sku>List configurable options
product url <url-key>Find product by URL key
category treeFull category hierarchy
category view <id>View category by ID
category products <id>Products in a category
attribute view <code>View attribute definition
attribute options <code>List attribute option values
attribute setsList attribute sets
inventory status <sku>Check stock status
store viewsList store views
store config [code]Show store configuration
store groupsList store groups
store websitesList websites
config listList config as path=value pairs
config get <path>Get a specific config value
config dumpDump all config for env diffing
promo catalog-rule listList catalog price rules
promo catalog-rule view <id>View catalog price rule details
promo cart-rule listList cart price rules
promo cart-rule view <id>View cart price rule details
promo coupon listList coupon codes
promo coupon view <id>View coupon details
cms page listList CMS pages
cms page view <id>View a CMS page
cms block listList CMS blocks
cms block view <id>View a CMS block
api <path>Raw REST API requests

Global Flags

FlagDescription
-c, --context <name>Use a specific context
--store-code <code>Override store code
--jsonJSON output
--yamlYAML output
--jq <expr>Filter JSON with jq
--template <tmpl>Go template output

Products

Listing & Searching

# List all products (default limit: 50)
magecli product list

# Quick name search
magecli product search "outdoor shirt"

# Filter with operators
magecli product list --filter "price gt 100" --filter "status eq 1"

# Sort and paginate
magecli product list --sort "price:ASC" --limit 20 --page 2

# Find by URL key
magecli product url blue-outdoor-jacket

Viewing Details

# Full product details
magecli product view SKU123

# Just the name
magecli product view SKU123 --json --jq '.name'

# Product images
magecli product media SKU123

Configurable Products

# List simple variants of a configurable
magecli product children PARENT-SKU

# List configurable options (color, size, etc.)
magecli product options PARENT-SKU

Categories

# Full category tree
magecli category tree

# From a specific root, limited depth
magecli category tree --root 37 --depth 2

# View a single category
magecli category view 42

# Products in a category
magecli category products 42 --limit 20

Attributes

# View an attribute definition
magecli attribute view color

# List option values for a select/dropdown attribute
magecli attribute options color

# List all attribute sets
magecli attribute sets

Inventory

# Check stock status
magecli inventory status SKU123

# JSON for scripting
magecli inventory status SKU123 --json

Returns quantity, in-stock status, min/max sale quantities, and other stock configuration.

Store Configuration

# List all store views
magecli store views

# Show config for all stores
magecli store config

# Filter to a specific store code
magecli store config default

# List store groups and websites
magecli store groups
magecli store websites

Config includes locale, currency, timezone, weight unit, and all base URLs (standard, secure, media, static).

System Configuration

Query Magento system configuration values for auditing and environment comparison.

# List all config values as path=value
magecli config list

# Filter to a specific section
magecli config list --filter web/secure
magecli config list --filter currency

# Get a specific config path
magecli config get general/locale/code
magecli config get web/secure/base_url

# Compare environments
diff <(magecli -c staging config list) <(magecli -c prod config list)
diff <(magecli -c staging config dump --json) <(magecli -c prod config dump --json)

Config paths follow the Magento convention (e.g., general/locale/code, web/unsecure/base_url, currency/options/base). Output is grouped by store scope.

Promotions

View catalog price rules, cart price rules, and coupon codes. All list commands support --filter, --sort, --limit, and --page.

Catalog Price Rules

Applied to products before they are added to the cart.

# List all catalog rules
magecli promo catalog-rule list

# Only active rules
magecli promo catalog-rule list --filter "is_active eq 1"

# View rule details
magecli promo catalog-rule view 42 --json

Cart Price Rules

Applied at checkout. May include coupon codes, free shipping, or buy-X-get-Y offers.

# List all cart rules
magecli promo cart-rule list

# Active rules with coupon codes
magecli promo cart-rule list --filter "is_active eq 1" --json

# View full details
magecli promo cart-rule view 5

Coupons

View coupon codes, usage stats, and expiration dates.

# List all coupons
magecli promo coupon list

# Search by code
magecli promo coupon list --filter "code like %SUMMER%"

# Coupons for a specific rule
magecli promo coupon list --filter "rule_id eq 5"

# View coupon details
magecli promo coupon view 1

Tip: Short aliases are available — promo cr list for catalog rules and promo sr list for cart (sales) rules.

CMS Pages & Blocks

# List CMS pages
magecli cms page list
magecli cms page list --filter "identifier like %home%"

# View a page (metadata only)
magecli cms page view 11

# Include HTML content
magecli cms page view 11 --content

# Blocks work the same way
magecli cms block list
magecli cms block view 31 --content

Raw API Access

For endpoints without a first-class command, use the api escape hatch. Paths are relative to /rest/{store_code}/.

# GET requests work on any context
magecli api /V1/store/storeViews --json
magecli api /V1/products -P "searchCriteria[pageSize]=5" --json

# Custom headers
magecli api /V1/products -H "X-Custom: value"

Write protection: POST, PUT, DELETE, and PATCH are blocked unless the active context was created with --allow-writes. This prevents accidental modifications to production stores.

# Create a write-enabled context
magecli context create dev --host dev.example.com --allow-writes --set-active

# Now POST/PUT/DELETE are allowed
magecli api /V1/products -X POST -d '{"product": {"sku": "new", "name": "New"}}'
magecli api /V1/products/SKU123 -X DELETE

Output Formats

Every command supports multiple output modes.

JSON

magecli product list --json

YAML

magecli product view SKU123 --yaml

jq Filtering

# Extract SKUs
magecli product list --json --jq '.items[].sku'

# Build custom objects
magecli product list --json --jq '.items[] | {sku, name, price}'

Go Templates

magecli product list --json --template '{{range .items}}{{.sku}} - {{.name}} (${{.price}})
{{end}}'

Filtering & Sorting

The --filter flag uses a simple "field operator value" syntax. Multiple filters are ANDed together.

# Single filter
magecli product list --filter "name like %shirt%"

# Multiple filters (AND)
magecli product list --filter "price gt 50" --filter "status eq 1"

# Sorting (field:direction)
magecli product list --sort "price:ASC" --sort "name:DESC"

# Pagination
magecli product list --limit 20 --page 3

Available Operators

OperatorDescriptionExample
eqEqual"status eq 1"
neqNot equal"type_id neq simple"
gt / gteqGreater than / or equal"price gt 100"
lt / lteqLess than / or equal"price lt 50"
like / nlikeSQL LIKE / NOT LIKE"name like %shirt%"
in / ninIn set / not in set"type_id in simple,configurable"
null / notnullIs null / not null"special_price null"
from / toRange bounds"created_at from 2024-01-01"
finsetFind in set"category_ids finset 42"

Context Management

Contexts let you manage multiple Magento stores and switch between them instantly.

# Create contexts for different environments
magecli context create production --host store.example.com --store-code default --set-active
magecli context create staging --host staging.example.com --store-code default
magecli context create dev --host dev.example.com --allow-writes

# Switch contexts
magecli context use staging

# List all (* = active)
magecli context list

# Override per-command
magecli product list --context production

# Delete
magecli context delete dev

Config File

Stored at ~/.config/magecli/config.yml. Tokens are never written here — they live in the OS keyring.

version: 1
active_context: production
contexts:
  production:
    host: store.example.com
    store_code: default
  staging:
    host: staging.example.com
    store_code: default
  dev:
    host: dev.example.com
    store_code: default
    allow_writes: true
hosts:
  store.example.com:
    base_url: https://store.example.com
  staging.example.com:
    base_url: https://staging.example.com
  dev.example.com:
    base_url: https://dev.example.com

Environment Variables

VariableDescription
MAGECLI_TOKENBearer token (bypasses keyring)
MAGECLI_CONFIG_DIROverride config directory
MAGECLI_HTTP_DEBUGEnable HTTP request/response logging
MAGECLI_PAGERPager command override (e.g., less)
MAGECLI_ALLOW_INSECURE_STOREAllow encrypted file-based keyring fallback

AI Agent Integration

magecli ships with skill definitions that let AI coding agents (Claude Code, Codex CLI) discover and use it automatically.

Installing the Skill

# Install globally for Claude Code
npx skills add atlanticbt/magecli

Once installed, your AI agent can run commands like:

# Agent prompt: "What products cost over $100?"
# Agent runs:
magecli product list --filter "price gt 100" --json --jq '.items[] | {sku, name, price}'

Skill Files

PathPurpose
skills/magecli/SKILL.mdSkill definition with triggers and usage
skills/magecli/references/commands.mdFull command reference
.claude/skills/magecli/Auto-synced copy for Claude Code
.codex/skills/magecli/Auto-synced copy for Codex CLI

Use Cases

magecli shines when paired with AI coding agents. Here are common prompts you can give Claude Code (or any agent with the magecli skill installed) and what happens behind the scenes.

Catalog Exploration

Prompt: "Show me all configurable products that are out of stock"

The agent cross-references product list with inventory status to find configurable products where stock quantity is zero.

Prompt: "List all products in the 'Sale' category with their prices and SKUs"

The agent uses category tree to find the Sale category ID, then category products to get the product list with pricing details.

Prompt: "Which products are missing images?"

The agent iterates through product list and checks product media for each, flagging any SKUs with no media gallery entries.

Troubleshooting & Debugging

Prompt: "A customer says SKU WH-1042 isn't showing on the frontend. Can you figure out why?"

The agent checks: Is the product enabled? (product view) Is it in stock? (inventory status) Is it assigned to the right categories? (category products) Is it visible in the correct store view? (store views + product scope). It then reports back with the root cause.

Prompt: "Compare product data between staging and production for SKU WH-2080"

With two contexts configured, the agent runs magecli product view WH-2080 --context staging --json and --context production --json, then diffs the output to highlight mismatches in prices, descriptions, or attribute values.

Prompt: "Check if store config for base URLs looks correct across all store views"

The agent uses store views to enumerate views and store config to pull base URL values, flagging any that look misconfigured (e.g., still pointing to a dev domain).

Configuration & Environment Management

Prompt: "Compare all config values between staging and prod and tell me what's different"

The agent runs config list against both contexts and diffs the output, highlighting mismatched locales, base URLs, currency settings, or any other config drift between environments.

Prompt: "Verify that all store views are using HTTPS base URLs"

The agent uses config get web/secure/base_url and config get web/unsecure/base_url to check each store scope for non-HTTPS URLs.

Promotions & Pricing

Prompt: "Show me all active promotions and which ones have coupon codes"

The agent queries promo catalog-rule list --filter "is_active eq 1" and promo cart-rule list --filter "is_active eq 1", then cross-references cart rules with promo coupon list to show which rules have associated coupon codes.

Prompt: "Are there any expired promotions still marked as active?"

The agent lists active catalog and cart rules and checks their to_date values against today's date, flagging any that have passed their end date but weren't deactivated.

Prompt: "Which coupon codes are close to hitting their usage limit?"

The agent pulls promo coupon list --json and compares times_used against usage_limit, highlighting coupons where usage is above 80% of the limit.

Prompt: "Give me a report of all cart rules that apply free shipping"

The agent queries promo cart-rule list --json and filters for rules where apply_to_shipping is true or the action suggests free shipping, then summarizes the conditions and customer groups.

Content Auditing

Prompt: "Find all CMS pages that haven't been updated since last year"

The agent lists CMS pages with cms page list --json and filters by update_time to surface stale content.

Prompt: "Are there any disabled CMS blocks still referenced in active pages?"

The agent cross-references cms block list (filtering disabled blocks) with cms page view content to find orphaned references.

Data Export & Reporting

Prompt: "Generate a CSV of all simple products with SKU, name, price, and stock quantity"

The agent combines product list and inventory status with --jq to shape the data, then writes it to a file.

Prompt: "Build me a summary of our category tree with product counts at each level"

The agent walks category tree recursively and calls category products for each node to build a structured report.

Combining with Other Tools

magecli becomes even more powerful when your agent has access to other CLI tools and MCP servers:

+ Browser Automation

Ask the agent to verify a product's frontend display matches its API data. It queries magecli for the source of truth, then uses browser tools to screenshot the storefront and compare.

+ Jira / Project Tracking

Ask the agent to "create a Jira ticket for every product missing a meta description". It queries magecli for the data, then uses Atlassian MCP to file the issues automatically.

+ Google Sheets

Ask the agent to "export our full price list to a Google Sheet". It pulls product data from magecli and writes it row-by-row using Google Workspace tools.

+ Slack

Ask the agent to "post a daily inventory alert to #ecommerce-ops for any SKUs that dropped below 10 units". It queries stock levels via magecli and sends formatted Slack messages.

+ Git & Code

Ask the agent to "find all hardcoded SKUs in our theme templates and verify they still exist in Magento". It greps the codebase, then validates each SKU against the live catalog.

+ Database / SSH

For deeper troubleshooting, the agent can correlate magecli API output with database queries or server logs to diagnose indexing issues, cron failures, or cache inconsistencies.