DEV Community

Cover image for How I Built an AI Agent That Earns $150 Reviewing Pull Requests
ZG361
ZG361

Posted on

How I Built an AI Agent That Earns $150 Reviewing Pull Requests

How I Built an AI Agent That Earns $150 Reviewing Pull Requests

What if your code could write code that earns money? That's exactly what I built: a PR Review Agent that autonomously reviews GitHub pull requests and claims bounties in cryptocurrency.

In this article, I'll walk you through how I built claude-review-agent, a CLI tool that fetches GitHub PR diffs, generates structured code reviews, and earned me a $150 bounty.

The Problem

Open source maintainers are overwhelmed. PRs pile up, reviews take hours, and contributors wait days for feedback. What if an AI could handle the first-pass review?

RustChain, a DePIN blockchain project, had a bounty for exactly this:

"Build a CLI tool that reviews PRs and posts structured comments"

Reward: $150 in RTC tokens

The Solution: claude-review-agent

I built a Node.js CLI tool that:

  1. Fetches PR diffs via GitHub API
  2. Generates structured reviews using Claude AI
  3. Posts comments directly on PRs
  4. Outputs Markdown for easy reading

Architecture

┌─────────────┐     ┌──────────────┐     ┌─────────────┐
│ GitHub API  │────▶│   claude-    │────▶│   Claude    │
│  (PR diff)  │     │  review.js   │     │     AI      │
└─────────────┘     └──────────────┘     └─────────────┘
                           │
                           ▼
                    ┌──────────────┐
                    │   Markdown   │
                    │   Review     │
                    └──────────────┘
Enter fullscreen mode Exit fullscreen mode

Step 1: Parse the PR URL

First, we need to extract owner, repo, and PR number from the URL:

function parsePrUrl(url) {
  const match = url.match(/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/);
  if (!match) throw new Error('Invalid GitHub PR URL');
  return {
    owner: match[1],
    repo: match[2],
    prNumber: parseInt(match[3])
  };
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Fetch the PR Diff

Using the GitHub API with Accept: application/vnd.github.v3.diff header:

function fetchPrDiff(owner, repo, prNumber, token) {
  const diff = execSync(
    `curl -s -L -H "Authorization: Bearer ${token}" ` +
    `-H "Accept: application/vnd.github.v3.diff" ` +
    `"https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}"`,
    { encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }
  );
  return diff;
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Generate the Review

Here's where Claude AI shines. We send the diff and ask for structured analysis:

const prompt = `You are an expert code reviewer. Analyze this PR diff and provide:

## Summary
Brief overview of changes (2-3 sentences)

## Risks
List potential issues or concerns (bulleted list)

## Suggestions
Improvement recommendations (bulleted list)

## Confidence
Rate your confidence: High/Medium/Low

Diff:
${diff}`;

const response = await anthropic.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 4096,
  messages: [{ role: 'user', content: prompt }]
});
Enter fullscreen mode Exit fullscreen mode

Step 4: Output Formats

The tool supports multiple output modes:

# Print to console
claude-review --pr https://github.com/owner/repo/pull/123

# Save to file
claude-review --pr https://github.com/owner/repo/pull/123 --output review.md

# Post as PR comment
claude-review --pr https://github.com/owner/repo/pull/123 --post
Enter fullscreen mode Exit fullscreen mode

Example Output

Here's a real review from testing on awesome-depin PR #28:

## Summary
This PR adds RustChain to the DePIN infrastructure list. It's a minimal 
addition of one entry under the L1/L2 category with project description 
and links.

## Risks
- Low complexity change, minimal risk
- Link validation should be verified

## Suggestions
- Consider adding a brief note about the Proof-of-Antiquity mechanism
- The description could mention supported hardware architectures

## Confidence
Medium
Enter fullscreen mode Exit fullscreen mode

Testing on Real PRs

I tested the agent on two real pull requests:

PR Repository Result
#28 iotexproject/awesome-depin ✅ Review generated
#2372 rust-unofficial/awesome-rust ✅ Review generated

Both tests produced meaningful, actionable feedback.

The Bounty Submission

After testing, I submitted the tool to the RustChain bounty issue:

Repository: https://github.com/ZG361/claude-review-agent

Acceptance criteria met:

  • ✅ Works via CLI
  • ✅ Structured Markdown output
  • ✅ Tested on 2 real PRs
  • ✅ README with setup/usage instructions

Result: $150 bounty claimed!

Installation

Want to use it yourself?

# Clone the repo
git clone https://github.com/ZG361/claude-review-agent
cd claude-review-agent

# Install dependencies
npm install

# Set environment variables
export GH_TOKEN=your_github_token
export ANTHROPIC_API_KEY=your_anthropic_key

# Run
node bin/claude-review.js --pr https://github.com/owner/repo/pull/123
Enter fullscreen mode Exit fullscreen mode

Lessons Learned

  1. Start with the acceptance criteria - Read the bounty requirements carefully before coding
  2. Test on real data - Use actual PRs to validate your tool works
  3. Template mode is useful - When you don't have API access, generate structured templates
  4. Document everything - A good README is half the battle

What's Next?

The agent is just the beginning. Future improvements could include:

  • Multi-language support for non-English reviews
  • Custom review templates per repository
  • Integration with CI/CD for automated reviews on every PR
  • Support for other AI providers (GPT-4, Gemini, etc.)

Conclusion

Building AI agents that earn cryptocurrency isn't science fiction—it's happening right now. The claude-review-agent took about 3 hours to build and earned $150 in RTC tokens.

The future of work is AI-assisted, and platforms like RustChain are creating the infrastructure for AI agents to participate in the economy.

Your old hardware might be worth more than you think—and so is your code.


Built with ❤️ and Claude AI. Check out RustChain for more bounties.

Wallet: ZG361

Top comments (0)