Skip to content

FunnelEnvy/ahrefs-cli

Repository files navigation

ahrefs-cli

npm version CI License: MIT

Command-line interface for the Ahrefs SEO API — query backlinks, organic keywords, referring domains, domain ratings, and site metrics from your terminal.

Install

npm install -g @funnelenvy/ahrefs-cli

Quick Start

# Save your API key
ahrefs auth login

# Get domain rating for a site
ahrefs domain-rating get --target example.com -o table

# List backlinks
ahrefs backlinks list --target example.com --limit 20 -o table

# Find organic keywords
ahrefs keywords organic --target example.com --country us -o csv

# Get referring domains
ahrefs domains referring --target example.com --limit 10

# Full site overview
ahrefs site-explorer overview --target example.com -o table

Authentication

Ahrefs CLI supports three authentication methods (in priority order):

1. Command-line flag

ahrefs domain-rating get --target example.com --api-key YOUR_KEY

2. Environment variable

export AHREFS_API_KEY=your_api_key_here
ahrefs domain-rating get --target example.com

3. Config file (recommended)

ahrefs auth login
# Enter your API key when prompted, saved to ~/.config/ahrefs-cli/config.json

Check auth status:

ahrefs auth status

Command Reference

auth — Manage authentication

ahrefs auth login [api-key]     # Save API key (interactive or inline)
ahrefs auth status              # Show current auth status
ahrefs auth logout              # Remove saved API key

backlinks — Analyze backlinks

ahrefs backlinks list --target <domain> [options]

Options:
  --target <target>       Target domain or URL (required)
  --limit <n>             Number of results (default: 50)
  --offset <n>            Pagination offset (default: 0)
  --mode <mode>           exact, domain, subdomains, prefix (default: subdomains)
  --protocol <protocol>   http, https, both (default: both)
  --date <date>           Historical date (YYYY-MM-DD)
  -o, --output <format>   json, table, csv (default: json)
  -q, --quiet             Suppress status messages
  -v, --verbose           Debug logging

keywords — Organic keyword analysis

ahrefs keywords organic --target <domain> [options]

Options:
  --target <target>       Target domain or URL (required)
  --country <code>        Country code (default: us)
  --limit <n>             Number of results (default: 50)
  --offset <n>            Pagination offset (default: 0)
  --mode <mode>           exact, domain, subdomains, prefix (default: subdomains)
  -o, --output <format>   json, table, csv (default: json)

domains — Referring domain analysis

ahrefs domains referring --target <domain> [options]

Options:
  --target <target>       Target domain or URL (required)
  --limit <n>             Number of results (default: 50)
  --offset <n>            Pagination offset (default: 0)
  --mode <mode>           exact, domain, subdomains, prefix (default: subdomains)
  -o, --output <format>   json, table, csv (default: json)

domain-rating — Domain rating metrics

ahrefs domain-rating get --target <domain> [options]

Options:
  --target <target>       Target domain (required)
  --mode <mode>           exact, domain, subdomains, prefix (default: subdomains)
  --date <date>           Historical date (YYYY-MM-DD)
  -o, --output <format>   json, table, csv (default: json)

site-explorer — Site overview

ahrefs site-explorer overview --target <domain> [options]

Options:
  --target <target>       Target domain or URL (required)
  --country <code>        Country code (default: us)
  --mode <mode>           exact, domain, subdomains, prefix (default: subdomains)
  --date <date>           Historical date (YYYY-MM-DD)
  -o, --output <format>   json, table, csv (default: json)

Output Formats

All data commands support --output json|table|csv:

  • json (default) — machine-readable, pipe-friendly
  • table — human-readable aligned columns
  • csv — for spreadsheets and data pipelines

Configuration

Config file location: ~/.config/ahrefs-cli/config.json

{
  "auth": {
    "api_key": "your_api_key_here"
  },
  "defaults": {
    "output": "table"
  }
}

Development

git clone https://github.com/FunnelEnvy/ahrefs-cli.git
cd ahrefs-cli
pnpm install
pnpm run build
pnpm run test
pnpm run typecheck

Part of Marketing CLIs

This tool is part of Marketing CLIs — open source CLIs for marketing tools that have APIs but lack command-line interfaces.

License

MIT

About

CLI for Ahrefs SEO — backlinks, keywords, domain rating, site explorer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors