Do you have an autonomous AI agent that modifies its own files? If you're using OpenClaw (or its fork Clawdbot) as a personal assistant, you know these agents learn, adapt, and modify their own configuration over time. The problem: what happens when something goes wrong? How do you recover previous versions? How do you keep everything optimized without manual intervention?
In this tutorial I'll show you exactly how I automated the automatic backup, versioning, and daily optimization of Nyx — my personal AI agent based on OpenClaw. Battle-tested, running 24/7 for months.
The Problem: Autonomous Agents That Modify Themselves
OpenClaw is different from ChatGPT or Claude. It's not a chatbot that simply answers questions. It's an autonomous agent that:
- Modifies its own configuration files (
AGENTS.md,SOUL.md,USER.md) - Creates and updates documentation (
TOOLS.md,MEMORY.md) - Generates new scripts and skills
- Learns from mistakes and updates its own instructions
- Executes tasks without constant supervision
The risk: A bad update, a misunderstood instruction, or a failed experiment can leave your agent in an inconsistent state. And since it works autonomously, you might not notice for days.
The solution: An automated system for backup, versioning, and continuous optimization.
System Architecture
My agent Nyx has three critical components that need backing up:
1. Core Files (Identity & Configuration)
These files define who the agent is:
-
AGENTS.md— Operational instructions, rules, workflows -
SOUL.md— Personality, tone, communication style -
USER.md— Information about me (the human) -
IDENTITY.md— Name, role, purpose -
TOOLS.md— Local notes on tools and configurations -
HEARTBEAT.md— Checklist for periodic reviews -
MEMORY.md— Long-term memory (critical context) -
BRAND.md— Style and branding guidelines
2. Custom Skills
skills/ directory with custom integrations:
-
coolify-api/— Self-hosted service management -
late-api/— Social media publishing -
listmonk-api/— Newsletter automation -
replicate-api/— Image generation -
wordpress-api/— Blog management - And more...
3. Automation Scripts
scripts/ directory with utilities:
-
auto-archive.sh— Automatic archiving of temp files -
sync-core-nyx.sh— The star script (explained in detail below) -
test-apis.sh— API credential verification
Why GitHub as Backup?
I considered several options:
❌ Dropbox/Google Drive:
- Don't automatically version every change
- Hard to see what changed between versions
- No granular rollback
❌ Manual tar backup:
- Requires human intervention
- Doesn't scale
- Easy to forget
✅ GitHub (private):
- Automatic versioning of every change
- Visual diffs to see exactly what changed
- Easy rollback to any commit
- Free for private repos
- Accessible from anywhere
- CI/CD ready if I want to add tests later
Quick Start: Let the Agent Do It (5 Minutes)
The agent can set up everything automatically. All you need:
-
Create a GitHub Token with permissions:
- GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Generate new token
- Scopes:
repo(all) +admin:repo_hook - Copy the token (save it — you won't see it again)
Talk to your agent naturally:
No need for a giant technical prompt. Just tell it what you need like you'd tell a colleague:
Message 1 (Initial setup):
"Hey, I need you to automatically back up your core files to GitHub. My token is ghp_XXXXX and my username is my-github-username. Create a private repo named something based on your name, sync all your configuration files (.md, skills, scripts), and set everything up to work automatically."
Message 2 (Versioning):
"I want you to manage versions like professional projects. Use semantic versioning (v0.1.0, v0.1.1, etc.), keep a CHANGELOG.md updated with the changes you make, and create git tags for each version."
Message 3 (Auto-optimization):
"Every morning at 3 AM, I want you to self-optimize: review your core files, remove redundancies, improve anything confusing, learn from mistakes, and document everything in the CHANGELOG. Then automatically sync to GitHub with a new version."
That's it. The agent understands, does the entire technical setup, and confirms when it's done.
Manual Setup (If You Want to Understand What's Happening)
Step 1: Create Private Repository
# Option A: Via GitHub.com manually
# New Repository → "core-nyx" → Private → Create
# Option B: With the API (what the agent does)
curl -H "Authorization: token ghp_YOUR_TOKEN" \
-d '{"name":"core-nyx","private":true}' \
https://api.github.com/user/repos
Step 2: Configure GitHub Token
# Configure git to use token
cd ~/clawd/repos
git clone https://github.com/your-username/core-nyx.git
cd core-nyx
# Configure credentials (once)
git config credential.helper store
git config user.name "Your Name"
git config user.email "your-email@example.com"
Step 3: Strategic .gitignore
Critical: Do NOT back up secrets or temp files.
cat > .gitignore << 'EOF'
# Secrets
**/.config/credentials.json
**/.env
**/api_key
secrets/
# Temporary
*.log
*.tmp
temp-*
**/node_modules/
**/__pycache__/
# Data
data/*.db
data/*.json
*.sqlite
# OS
.DS_Store
Thumbs.db
EOF
The Sync Script
Here's the heart of the system — sync-core-nyx.sh:
#!/bin/bash
set -euo pipefail
REPO_DIR="$HOME/clawd/repos/core-nyx"
SOURCE_DIR="$HOME/clawd"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
echo "🔄 Starting Nyx core sync - $TIMESTAMP"
# 1. Sync core files
rsync -av --delete \
--include='*.md' \
--exclude='memory/20*.md' \
--exclude='node_modules/' \
--exclude='.git/' \
"$SOURCE_DIR/" "$REPO_DIR/"
# 2. Sync skills (without credentials)
rsync -av \
--exclude='**/.config/' \
--exclude='**/.env' \
"$SOURCE_DIR/skills/" "$REPO_DIR/skills/"
# 3. Sync scripts
rsync -av "$SOURCE_DIR/scripts/" "$REPO_DIR/scripts/"
# 4. Git commit
cd "$REPO_DIR"
git add -A
if git diff --staged --quiet; then
echo "✅ No changes to commit"
exit 0
fi
git commit -m "auto: sync core files - $TIMESTAMP"
git push origin main
echo "✅ Sync complete"
Daily Cron: Auto-Optimization at 3 AM
# crontab -e
0 3 * * * /home/moltbot/clawd/scripts/sync-core-nyx.sh >> /home/moltbot/clawd/logs/sync.log 2>&1
The agent runs at 3 AM, reviews its own files, eliminates redundancies, and syncs to GitHub. Every morning when you wake up, you have a fresh versioned backup.
Results After Months of Use
- Commits: 200+ automatic commits
- Rollbacks used: 3 times (saved me 2-3 hours each time)
- Manual interventions needed: 0
- Sleep lost due to "what happened to my agent": 0
The system just works. The agent keeps itself versioned and I have full visibility into every change it makes to itself.
Key Takeaways
- Autonomous agents need version control — just like production code
- GitHub is the right tool for file versioning (you already know it)
- The agent can set itself up — you don't need to be technical
- Strategic .gitignore is critical — never back up secrets
- 3 AM optimization — let the agent improve itself while you sleep
If you're running any AI agent that modifies files autonomously, implement this. The 2 hours of setup will save you from hours of debugging and recovery later.
📝 Originally published in Spanish at cristiantala.com
Top comments (0)