Skip to content

About

Zero-dependency command line interface for the Namecheap API: domains, DNS, transfers and privacy

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

ncheap-cli

CI npm License: MIT Node

A command line interface for the Namecheap API. Manage domains, DNS records, transfers and privacy from your terminal.

Zero runtime dependencies — just Node 18+. No install step, no supply chain.

namecheap domains list --expiring-in 45
namecheap dns add example.com --type A --host @ --value 203.0.113.10
namecheap domains check mybrand.com mybrand.io --available-only

Install

npm install -g ncheap-cli

The package is ncheap-cli; the command it installs is namecheap.

Or from a clone:

git clone https://github.com/adnanakil/ncheap-cli.git
cd ncheap-cli
npm link                       # puts `namecheap` on your PATH

There is nothing to build and nothing to download, so you can also just run it in place:

node bin/namecheap.js --help

Setup

Namecheap requires three things before the API will answer: API access enabled, an API key, and your public IP whitelisted. Enable access and create the key at https://ap.www.namecheap.com/settings/tools/apiaccess/.

namecheap config init     # prompts for the API user, key, and client IP
namecheap config test     # confirms the credentials actually work

config init detects your public IP for you. Whitelist that address in the same Namecheap settings page, or every call fails with error 1011150.

Credential precedence

Command-line flags beat environment variables, which beat the config file.

Setting Flag Environment variable Config key
API username --api-user NAMECHEAP_API_USER apiUser
API key --api-key NAMECHEAP_API_KEY apiKey
Account username --username NAMECHEAP_USERNAME username
Whitelisted IP --client-ip NAMECHEAP_CLIENT_IP clientIp
Sandbox mode --sandbox NAMECHEAP_SANDBOX sandbox
Profile --profile NAMECHEAP_PROFILE defaultProfile

The config file lives at ~/.config/namecheap/config.json (mode 0600); run namecheap config path to confirm. The API key is sent in a POST body, never in a URL, so it does not end up in proxy or shell logs.

Profiles and the sandbox

Sandbox and production are separate Namecheap accounts with separate keys, so keep them in separate profiles:

namecheap config init --profile sandbox   # answer "y" to the sandbox question
namecheap --profile sandbox domains list
namecheap config use sandbox              # make it the default

Usage

namecheap --help              # all commands
namecheap dns --help          # commands in one group
namecheap dns add --help      # options and examples for one command

Every command takes --json for scripting, and mutating commands take --dry-run and --yes.

Domains

namecheap domains list
namecheap domains list --expiring-in 45          # renewal triage
namecheap domains check mybrand.com mybrand.io --available-only
namecheap domains info example.com
namecheap domains renew example.com --years 2
namecheap domains lock example.com               # show the registrar lock
namecheap domains lock example.com off           # unlock, e.g. before a transfer
namecheap domains tlds --search dev

Registering a domain needs a full WHOIS contact set. Either reuse the contacts from a domain you already own, or start from the template:

namecheap domains contacts-template > contacts.json   # edit it
namecheap domains create example.com --contacts contacts.json

namecheap domains create example.com --contacts-from mysite.com --years 2

DNS

namecheap dns list example.com
namecheap dns add example.com --type A     --host @   --value 203.0.113.10
namecheap dns add example.com --type CNAME --host www --value example.com --replace
namecheap dns add example.com --type TXT   --host @   --value "v=spf1 include:_spf.google.com ~all"
namecheap dns remove example.com --host www
namecheap dns remove example.com --type TXT --value "stale-verification-token"

Namecheap's setHosts endpoint replaces the entire zone — there is no per-record API. So add and remove read the current records, apply your change, show a diff, and write the whole set back:

Updating example.com
  + api  A  203.0.113.9  (ttl 1800)
Apply these changes? [y/N]

Use --dry-run to see that diff without sending anything, and --yes to skip the prompt in scripts. The CLI refuses to proceed without confirmation in a non-interactive shell unless --yes is given.

Because the zone is replaced wholesale, the EmailType setting is carried across automatically — losing it silently breaks mail delivery. Adding an MX record promotes EmailType to MX for you; override with --email-type.

Bulk edits and backups go through JSON:

namecheap dns export example.com --file zone.json
# edit zone.json
namecheap dns set example.com --file zone.json

Nameservers and email forwarding:

namecheap dns nameservers example.com
namecheap dns set-nameservers example.com ns1.vercel-dns.com ns2.vercel-dns.com
namecheap dns use-namecheap example.com
namecheap dns email-forwarding example.com
namecheap dns set-email-forwarding example.com --forward hello=me@gmail.com

Account, transfers, privacy, SSL

namecheap balance
namecheap pricing com io dev
namecheap pricing com --action RENEW
namecheap transfer create example.com --epp AbC123
namecheap transfer status 1150
namecheap whoisguard list
namecheap whoisguard enable 53 --email me@example.com
namecheap ssl list
namecheap address list

Anything else

raw reaches any endpoint the CLI does not wrap, including ones added after this was written:

namecheap raw users.getPricing --param ProductType=DOMAIN
namecheap raw namecheap.domains.ns.create -p SLD=example -p TLD=com -p Nameserver=ns1.example.com -p IP=203.0.113.1
namecheap raw users.getBalances --xml

The namecheap. prefix is optional. Output is JSON by default, or the untouched XML with --xml.

Use with Claude Code

skill/SKILL.md is a Claude Code skill that teaches Claude to drive this CLI — including the safety rules around edits that cost money or change live DNS. Install it for every project:

mkdir -p ~/.claude/skills/namecheap
curl -fsSL https://raw.githubusercontent.com/adnanakil/ncheap-cli/main/skill/SKILL.md \
  -o ~/.claude/skills/namecheap/SKILL.md

Or drop it in .claude/skills/namecheap/ to scope it to one project. Start a new session to pick it up.

The skill keeps Claude read-only by default: destructive commands need a --dry-run preview and your explicit approval before it will pass --yes.

Scripting

--json prints every field the API returned, not just the columns in the table:

# domains expiring in the next 30 days, one per line
namecheap domains list --expiring-in 30 --json | jq -r '.[].Name'

# point every domain in the account at a new IP
for d in $(namecheap domains list --json | jq -r '.[] | select(.IsOurDNS=="true") | .Name'); do
  namecheap dns add "$d" --type A --host @ --value 203.0.113.50 --replace --yes
done

Exit codes:

Code Meaning
0 Success
1 Runtime error (bad input, nothing matched, network failure)
2 Usage error (unknown command or option, missing argument)
3 The Namecheap API returned an error

domains check also exits 1 when none of the queried domains are available, so if namecheap domains check x.com --available-only; then ... works.

Troubleshooting

Run any command with --verbose to see the request being made (the API key is redacted). Set NAMECHEAP_DEBUG=1 for stack traces on unexpected errors.

Error Fix
1011102 API key invalid Enable API access and re-copy the key
1011105 / 1011150 client IP namecheap config detect-ip --save, then whitelist that IP
1011101 API user invalid Sandbox and production keys differ — check --sandbox
2019166 domain not found The domain is not in this account
DNS changes do nothing The domain uses custom nameservers; namecheap dns nameservers <domain>

Namecheap enforces a whitelist of production API users; new accounts need at least 20 domains, $50 spent, or $50 in the account before access is granted. Until then, use --sandbox.

Development

npm test

Tests run the real CLI binary against an in-process fake Namecheap server (test/helpers/fake-namecheap.js), so request shape, output and exit codes are all covered without touching the network or needing credentials.

src/
  cli.js          command registry, dispatch, help
  args.js         option parsing
  config.js       credential resolution and the profile file
  client.js       HTTP transport, error mapping
  xml.js          XML reader for the API responses
  dns-records.js  record normalisation, diffing, setHosts payloads
  contacts.js     WHOIS contact handling
  commands/       one module per command group

See CONTRIBUTING.md for how to add a command.

Contributing

Issues and pull requests are welcome. The one standing rule is that the CLI keeps zero runtime dependencies — please open an issue before adding one.

License

MIT

Not affiliated with or endorsed by Namecheap, Inc.

About

Zero-dependency command line interface for the Namecheap API: domains, DNS, transfers and privacy

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages