advanced15 min read· Module 8, Lesson 6
⚙️Project: CLI Automation Tool
Build scripts that use Claude Code to automate daily dev tasks
Project: CLI Automation Tool
In this project, you'll build scripts that use the Claude API to automate daily dev tasks: morning PR reviews, dependency audits, and changelog generation.
1. Morning PR Review
import Anthropic from "@anthropic-ai/sdk";
import { execFileSync } from "child_process";
const client = new Anthropic();
async function morningPRReview() {
const prsJson = execFileSync(
"gh", ["pr", "list", "--json", "number,title,author,additions,deletions", "--limit", "10"],
{ encoding: "utf-8" }
);
const prs = JSON.parse(prsJson);
if (prs.length === 0) { console.log("No open PRs!"); return; }
for (const pr of prs) {
console.log(`\nPR #${pr.number}: ${pr.title}`);
const diff = execFileSync("gh", ["pr", "diff", String(pr.number)],
{ encoding: "utf-8", maxBuffer: 1024 * 1024 });
const response = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 500,
messages: [{
role: "user",
content: `Quick review this PR (3-point summary):\nTitle: ${pr.title}\n\n${diff.substring(0, 10000)}\n\nReply: summary, risks, rating (ready/needs-review/has-issues)`
}],
});
console.log(response.content[0].text);
console.log("---");
}
}2. Dependency Audit
async function dependencyAudit() {
let outdated = "";
try {
outdated = execFileSync("npm", ["outdated", "--json"], { encoding: "utf-8" });
} catch (e) { outdated = e.stdout; }
let audit = "";
try {
audit = execFileSync("npm", ["audit", "--json"], { encoding: "utf-8" });
} catch (e) { audit = e.stdout; }
const response = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{
role: "user",
content: `Analyze dependency health:\n\nOutdated:\n${outdated}\n\nAudit:\n${audit.substring(0, 5000)}\n\nGive: summary, urgent updates, recommended, can-wait, npm commands`
}],
});
console.log("Dependency Report\n" + response.content[0].text);
}3. Changelog Generator
async function generateChangelog(since = "1 week ago") {
const commits = execFileSync(
"git", ["log", `--since=${since}`, "--pretty=format:%h|%s|%an|%ad", "--date=short"],
{ encoding: "utf-8" }
);
if (!commits.trim()) { console.log("No new commits"); return; }
const response = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{
role: "user",
content: `Convert these commits into an organized changelog (features, fixes, improvements):\n\n${commits}`
}],
});
console.log(response.content[0].text);
}4. Putting It All Together
async function morningRoutine() {
console.log("Morning Report\n" + "=".repeat(40));
console.log("\n1. Open PR Review");
await morningPRReview();
console.log("\n2. Dependency Check");
await dependencyAudit();
console.log("\n3. Changelog");
await generateChangelog();
console.log("\nMorning report complete!");
}
morningRoutine();Using Claude Code Directly
# Morning PR review
claude "Review all open PRs and summarize each one"
# Dependency audit
claude "Check package.json for outdated or vulnerable dependencies"
# Changelog
claude "Generate a changelog from the past week's commits"
# Code quality
claude "Analyze code quality of the src/ directory"Daily Cron Job
# Add to crontab (every weekday at 8 AM)
0 8 * * 1-5 cd /path/to/project && node morning-routine.js >> morning-report.logExtensions to Try
- Slack notifications — Send reports via webhook
- Dashboard — Display reports in a web page
- Smart alerts — Only notify when there are issues
- Trend tracking — Compare reports over time
- Team metrics — Track PR review times
Next: The final lesson — What's next on your AI journey.