Vamos a generate a first agent with Claude Code and it will run automatically every hour with a cron and upload the generated content to GitHub.
Crea the folder of your agent:
mkdir -p ~/motivational-agent/md mkdir -p ~/motivational-agent/data cd ~/motivational-agent
The final structure will be:
motivational-agent/ │ ├─ md/ │ └─ claude.md # context and style of phrases ├─ data/ │ └─ frases.json # history of phrases ├─ claude-config.json # configuration of Claude └─ run-agent.js # script that generates phrases + commits
2️ Create claude.md (context)
This file gives Claude personality and style of the phrases.
Create the file:
nano ~/motivational-agent/md/claude.md
Paste this content:
# Context for generating motivational phrases 1. Generate positive, brief and motivational phrases. 2. Inspire yourself from philosophy, self-help books and famous quotes. 3. Never repeat phrases that are already in the existing phrase file. 4. The final format must be JSON: { "phrase": "Here is the motivational phrase", "author": "Optional" }
Saves and closes.
Configure your model, paths and commit author:
nano ~/motivational-agent/claude-config.json
Paste this:
{ "model": "claude-instant-1", "temperature": 0.7, "max_tokens": 200, "md_path": "/motivational-agent/md", "data_path": "/motivational-agent/data/frases.json", "repo_path": "/motivational-agent", "commit_author": "Isma", "commit_email": "[email protected]" }
4️ Create the script run-agent.js
This script:
nano ~/motivational-agent/run-agent.js
Paste this code:
const fs = require('fs'); const { execSync } = require('child_process'); const config = JSON.parse(fs.readFileSync('claude-config.json')); const prompt = fs.readFileSync(`${config.md_path}/claude.md`, 'utf8'); try { // Execute Claude Code const output = execSync(`claude "${prompt}" --model ${config.model}`); const phrase = output.toString().trim(); // Read existing phrases let phrases = []; if (fs.existsSync(config.data_path)) { phrases = JSON.parse(fs.readFileSync(config.data_path, 'utf8')); } // Add new phrase phrases.push({ phrase, date: new Date().toISOString() }); // Save file fs.writeFileSync(config.data_path, JSON.stringify(phrases, null, 2)); console.log("Generated phrase:", phrase); // Commit and push execSync(`cd ${config.repo_path} && git add data/frases.json`); execSync(`cd ${config.repo_path} && git commit -m "Added new motivational phrase" --author="${config.commit_author} <${config.commit_email}>"`); execSync(`cd ${config.repo_path} && git push`); console.log("Commit and push done"); } catch (err) { console.error(err.toString()); }
5️ Initialize Git
If you haven’t done it yet:
Remember to replace TuUsuario with your GitHub username and ensure SSH is configured.
cd ~/motivational-agent node run-agent.js
crontab -e
0 * * * * /usr/bin/node /home/raspi4/motivational-agent/run-agent.js >> /home/raspi4/motivational-agent/cron.log 2>&1
grep CRON /var/log/syslog
