preloader
post-thumb

Last Update: October 4, 2025


BYauthor-thumberic


Keywords

Introduction

In today's fast-paced development world, managing DNS records manually through web interfaces is time-consuming and error-prone. As someone who frequently needs to update DNS configurations across multiple domains, I wanted a better solution—a command-line tool that AI could use to automatically construct and execute commands based on the information I provide.

When I tried to set up domain for my a Google Cloud project, the below are the DNS records I needed to add:

Type
Data
Alias
A
216.239.32.21
A
216.239.34.21
A
216.239.36.21
A
216.239.38.21
AAAA
2001:4860:4802:32::15
AAAA
2001:4860:4802:34::15
AAAA
2001:4860:4802:36::15
AAAA
2001:4860:4802:38::15
CNAME
ghs.googlehosted.com
www

And I am too lazy to click through the Cloudflare web dashboard to add them one by one. That's when I discovered cloudflare-cli (cfcli), a promising Node.js tool for managing Cloudflare DNS records from the terminal. The vision was simple: I could tell an AI assistant "update these DNS records for my domain," and it would construct the proper cfcli commands and execute them automatically.

But there was a problem — cfcli was broken.

The Problem: A Broken Tool

The Configuration File

Cfcli requires a configuration file (~/.cfcli.yaml) containing your Cloudflare API credentials. I created mine with the following content:

yaml
defaults:
   account: work
accounts:
   work:
      token: "p9XvQ2s7LwT8zR4bJ6yNf0c3KjHqWmVtSdFgLbXy"
       email: "[email protected]"
       domain: example.com

When I first tried to use cfcli, I immediately ran into two critical bugs:

Bug #1: Missing help.txt File

bash
$ cd /tmp
$ cfcli help
Error: ENOENT: no such file or directory, open '/tmp/doc/help.txt'

Running cfcli from any directory outside its installation folder caused it to crash when trying to display help documentation.

Bug #2: Invalid Request Headers

bash
$ node ./bin/cfcli zones
Error response received: Invalid request headers

Every API request to Cloudflare was failing with cryptic "Invalid request headers" errors. The tool was completely unusable.

Initially, I used Google Gemini to run cfcli commands and update DNS records for me, but it kept failing due to these bugs. And Gemini simply gave up and asked me to update those records manually.

Why This Mattered

These bugs weren't just inconvenient—they completely blocked my automation workflow. I needed cfcli to work reliably so that AI tools like Google Gemini, Claude Code, OpenAI Codex or others could:

  1. Automatically construct commands based on natural language requests
  2. Execute DNS updates without manual intervention
  3. Work from any directory in my system
  4. Handle bulk operations like updating multiple A, AAAA, and CNAME records at once

Without a working CLI tool, my entire automation strategy fell apart. I could continue using the Cloudflare web dashboard, but that defeated the purpose of having AI assistance.

Enter Claude Code: From Broken to Fixed in Minutes

This is where things got interesting. Instead of spending hours debugging Node.js code, diving into axios documentation, and testing different configurations, I simply asked Claude Code to help me fix the bugs.

First, I forked the project to my own GitHub account: e-tang/cloudflare-cli.

Then, I started a new conversation with Claude Code, providing the context about the two bugs I encountered.

Here's what happened:

Step 1: Reproducing the Bug

Claude Code immediately understood the context and ran the local cfcli to confirm the error:

bash
$ node ./bin/cfcli zones
Error response received: Invalid request headers

Step 2: Intelligent Debugging

Rather than randomly trying fixes, Claude Code:

  1. Analyzed the codebase to understand how authentication headers were being set
  2. Checked the axios version (1.12.0) to identify compatibility issues
  3. Created test scripts to isolate the problem
  4. Tested different authentication methods (Bearer token vs. API Key)

Through systematic testing, Claude Code discovered that:

  • The newer axios version (1.12.0) sets Content-Type: undefined by default
  • This undefined header causes Cloudflare's API to reject requests
  • The deprecated API Key authentication (X-Auth-Email + X-Auth-Key) doesn't work properly with newer axios versions
  • Bearer token authentication works perfectly

Step 3: The Fix

Claude Code implemented two elegant fixes:

Fix #1: Remove the undefined Content-Type header

javascript
// lib/apiClient.js
const client = axios.create({
  baseURL: 'https://api.cloudflare.com/client/v4',
  timeout: 20000
});

// Remove the Content-Type header set to undefined by axios
// which causes issues with Cloudflare API in newer axios versions
delete client.defaults.headers.common['Content-Type'];

Fix #2: Force Bearer token authentication

javascript
// bin/cfcli
let params = { ...config, ...argv };
// Remove email from params to force Bearer token authentication
// The old API Key authentication (email + key) is deprecated and causes issues with newer axios
if (params.token && params.email) {
  delete params.email;
}

Step 4: Fixing the Path Resolution Bug

For the second bug, Claude Code identified that path.resolve() returns the current working directory, not the module's directory. The fix was straightforward:

javascript
// index.js
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

showHelp() {
  return Promise.resolve(new Result([
    fs.readFileSync(path.join(__dirname, 'doc', 'help.txt'), 'utf8')
  ]));
}

Step 5: Testing and Validation

Claude Code didn't just fix the bugs—it verified them:

bash
# Test from the project directory
$ node ./bin/cfcli zones
✓ Success! Listed 4 zones

# Test from a different directory
$ cd /tmp && node /data/tyolab/node/cloudflare-cli/bin/cfcli help
✓ Success! Help text displayed correctly

# Test actual DNS operations
$ node ./bin/cfcli add --domain example.com --type A @ 216.239.32.21
✓ Added A record example.com -> 216.239.32.21

Step 6: Proper Git Commits

Claude Code even created well-documented git commits following best practices:

commit e9ff7a6
Fix "Invalid request headers" error with axios 1.12.0

This fixes compatibility issues with the newer axios version (1.12.0)...

commit feef4f7
Fix help command path resolution when run from different directory

Changed from using path.resolve() (which returns current working
directory) to using import.meta.url with __dirname...

The Real Magic: AI-Powered Automation in Action

With cfcli fixed, I could finally achieve my original goal. Here's what happened next:

Me: "For my domain example.com, please update them with: A 216.239.32.21, A 216.239.34.21, A 216.239.36.21, A 216.239.38.21, AAAA 2001:4860:4802:32::15, AAAA 2001:4860:4802:34::15, AAAA 2001:4860:4802:36::15, AAAA 2001:4860:4802:38::15, CNAME ghs.googlehosted.com www"

Claude Code immediately:

  1. Parsed my natural language request
  2. Constructed the proper cfcli commands
  3. Executed them in sequence
  4. Verified the results
bash
# Added 4 A records
Added A record example.com -> 216.239.32.21
Added A record example.com -> 216.239.34.21
Added A record example.com -> 216.239.36.21
Added A record example.com -> 216.239.38.21

# Added 4 AAAA records
Added AAAA record example.com -> 2001:4860:4802:32::15
Added AAAA record example.com -> 2001:4860:4802:34::15
Added AAAA record example.com -> 2001:4860:4802:36::15
Added AAAA record example.com -> 2001:4860:4802:38::15

# Updated CNAME record
Added CNAME record www.example.com -> ghs.googlehosted.com

What would have taken me 15-20 minutes of clicking through the Cloudflare dashboard took less than 10 seconds with AI assistance.

Lessons Learned

This experience taught me several valuable lessons about AI-assisted development:

1. AI Excels at Systematic Debugging

Rather than guessing, Claude Code used a methodical approach:

  • Reproduce the error
  • Analyze the codebase
  • Identify the root cause
  • Test potential solutions
  • Implement the fix
  • Verify it works

2. AI Understands Context

Claude Code didn't just fix the immediate bug. It understood:

  • The purpose of the tool
  • The compatibility issues with newer dependencies
  • Best practices for path resolution in ES modules
  • Proper git commit message formatting

3. AI Accelerates Learning

Throughout the debugging process, I learned about:

  • How axios handles headers in different versions
  • The difference between API Keys and API Tokens in Cloudflare
  • ES module path resolution with import.meta.url
  • Better patterns for CLI tool development

4. The Compound Effect of Automation

By fixing cfcli, I unlocked a new level of productivity:

  • Before: Manual DNS updates through web UI (15+ minutes per domain)
  • After: Natural language commands to AI → Automatic execution (seconds)

The Bigger Picture: AI as a Development Multiplier

This story isn't just about fixing two bugs in a CLI tool. It's about how AI tools like Claude Code are fundamentally changing software development:

From Bug Fixing to Feature Building

Instead of spending hours debugging, I spent minutes. That freed me to:

  • Update DNS records for all my domains
  • Write this blog post
  • Think about other automation opportunities

From Manual Work to Intelligent Automation

The combination of AI and CLI tools creates powerful workflows:

  1. I describe what I want in natural language
  2. AI translates it into technical commands
  3. AI executes and verifies the results
  4. I review and confirm

From Isolated Tools to Connected Systems

By fixing cfcli, I created a reliable bridge between:

  • Natural language (what I want)
  • Technical commands (how to do it)
  • Cloud APIs (where it happens)

Conclusion: Life Becomes Easier with AI

The title says it all—life really does become much easier with AI assistance. But not in the way you might expect.

AI didn't replace my understanding or judgment. Instead, it:

  • Amplified my productivity by handling repetitive debugging tasks
  • Accelerated my learning by showing me best practices
  • Enabled new workflows that weren't practical before

The open source community benefits too. Those two bug fixes are now committed to my local fork, ready to be shared back with the project maintainers. You can find the pull request here: Fix axios compatibility and path resolution bugs in cfcli

This is the promise of AI-assisted development: not replacing developers, but empowering them to focus on what matters—solving real problems and building valuable tools—while AI handles the tedious details.

What's Next?

With cfcli working perfectly, I'm exploring more automation opportunities:

  • Automated DNS configuration for new projects
  • Bulk DNS record management across multiple domains
  • Integration with infrastructure-as-code tools
  • Automated SSL certificate management

The possibilities are endless when you combine AI intelligence with reliable CLI tools.


Have you used AI to debug open source software? I'd love to hear your stories. Share them in the comments or reach out on Twitter @_e_tang.

Want to try Claude Code? Visit claude.com/claude-code to get started with AI-assisted development.


This post was written with assistance from Claude Code—the same AI that helped fix the bugs described in this story. Meta, right?

Previous Article
post-thumb

Oct 05, 2025

From Broken Fractions to Beautiful Formulas: Claude Code Trumpeted the Game!

A real-world comparison of Google Gemini, OpenAI Codex, and Claude Code in debugging a MathJax rendering issue. Spoiler: only one AI actually fixed it.

Next Article
post-thumb

Sep 26, 2025

Migrating a Website from MODX to Next.js with the Help of AI Tools

Case study of migrating a MODX site to Next.js with AI copilots guiding Bootstrap upgrades, content recovery, and automation.

agico

We transform visions into reality. We specializes in crafting digital experiences that captivate, engage, and innovate. With a fusion of creativity and expertise, we bring your ideas to life, one pixel at a time. Let's build the future together.

Copyright ©  2025  TYO Lab