Follow these terminal commands.
Since you are managing a Linux VPS (Ubuntu/Debian recommended), the key is to avoid running these as root for security.
1. Update and Install Prerequisites
Claude Code requires Node.js 18+. It is best to use Node 20 or 22 (LTS) for maximum stability.
# Update package list
sudo apt update && sudo apt upgrade -y
# Install Node.js (via NodeSource for the latest LTS)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash –
sudo apt install -y nodejs
# Verify versions
node -version
npm -version
2. Install Claude Code
Anthropic provides a native installer script that handles global path configuration for you.
# Run the official installer
curl -fsSL https://claude.ai/install.sh | bash
# Refresh your shell to recognize the ‘claude’ command
source ~/.bashrc
Note: If you prefer the standard NPM method, use npm install -g @anthropic-ai/claude-code, but ensure you don’t use sudo with npm to avoid permission conflicts later.
3. Setup OpenClaw (For 24/7 Messaging Control)
If you want the “Clawdbot” experience where you can text your AI from your phone, install the OpenClaw gateway:
# Install OpenClaw
curl -fsSL https://openclaw.ai/install.sh | bash
# Start the onboarding wizard
openclaw setup
During setup, you will be prompted to link your WhatsApp or Telegram. It will generate a QR code in your terminal—scan it with your phone just like linking a web browser.
4. Security: The “Sandbox” Best Practice
Because you mentioned creating web pages (HTML/PHP), you don’t want the AI to have access to your entire VPS root.
* Create a dedicated user: sudo adduser claudeagent
* Run Claude only in that user: su – claudeagent
* Persistent Sessions: Use tmux so the agent keeps running even when you disconnect from SSH:
# Start a new persistent session
tmux new -s claude-bot
# Run Claude inside the session
claude
# Press Ctrl+B, then D to detach. The bot stays alive!
Important: Authentication
When you first run claude, it will ask you to authorize.
* Claude Pro Users: Use the /login command inside the terminal. It will provide a link/code to authenticate via your browser.
* API Users: If you are using the Anthropic Console (pay-per-use), set your key as an environment variable: export ANTHROPIC_API_KEY=’your-key-here’.
Would you like me to generate a systemd service script for you? This would ensure the bot automatically restarts if your VPS ever reboots.
Yes
To ensure your agent starts automatically whenever your VPS reboots (without you having to manually SSH in and start a tmux session), you should use systemd.
This script assumes you are running the bot under a standard user account (like nathan or a dedicated claudeagent user) rather than root.
1. Create the Service File
Run the following command to open the editor:
sudo nano /etc/systemd/system/claude-bot.service
2. Paste the Configuration
Copy and paste the block below. Note: Replace nathan with your actual Linux username and ensure the ExecStart path matches where claude is installed (usually /usr/bin/claude or /usr/local/bin/claude).
[Unit]
Description=Claude Code Autonomous Agent
After=network.target
[Service]
# Replace ‘nathan’ with your actual VPS username
User=nathan
Group=nathan
WorkingDirectory=/home/nathan/projects
# Environment variables (Add your API key if not using browser login)
Environment=ANTHROPIC_API_KEY=your_api_key_here
Environment=NODE_ENV=production
# The command to start the agent
ExecStart=/usr/bin/claude –base-dir /home/nathan/projects
# Restart policy: Always restart if the process crashes
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
3. Enable and Start the Service
After saving the file (Ctrl+O, Enter, Ctrl+X), run these commands to activate it:
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable it to start on boot
sudo systemctl enable claude-bot
# Start the service now
sudo systemctl start claude-bot
4. How to Manage the Bot
Now that it’s a background service, you can manage it like any other server application:
* Check Status: sudo systemctl status claude-bot
* View Live Logs: journalctl -u claude-bot -f (Crucial for seeing what the bot is thinking or doing).
* Stop/Restart: sudo systemctl stop claude-bot or sudo systemctl restart claude-bot
A Quick Note for your Web Projects
Since you mentioned working with HTML and PHP, make sure the WorkingDirectory in the script above points to your /var/www/html or whichever folder holds your web files. This ensures the bot “wakes up” in the right place to start editing your code.
Would you like me to help you configure a GitHub Action so the bot can automatically pull your latest changes before it starts working?
Yes
Integrating a GitHub Action with your Claude Code agent on a VPS creates a powerful loop: you push code to GitHub, your VPS automatically pulls the changes, and Claude is instantly ready to work on the latest version of your HTML/PHP files.
Since you’re likely managing your web files in a specific directory (like /var/www/html or a project folder), here is the cleanest way to set this up using SSH and rsync.
Step 1: Generate SSH Keys for GitHub
On your local machine or the VPS, generate a key that GitHub will use to talk to your server.
* Run: ssh-keygen -t rsa -b 4096 -f github_deploy_key -N “”
* On your VPS: Copy the contents of github_deploy_key.pub into your ~/.ssh/authorized_keys file.
* On GitHub: Go to your Repository → Settings → Secrets and variables → Actions.
* Add a New Repository Secret named SSH_PRIVATE_KEY and paste the contents of the private github_deploy_key.
* Add secrets for SSH_HOST (your IP), SSH_USER (your username), and SSH_PORT (usually 22).
Step 2: Create the Workflow File
In your repository, create the file .github/workflows/deploy.yml and paste this configuration:
name: Sync to VPS for Claude
on:
push:
branches:
– main # Or your preferred branch
jobs:
deploy:
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v4
– name: Deploy to VPS via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /home/nathan/projects/my-web-site
git pull origin main
# Optional: Restart the Claude systemd service to refresh context
sudo systemctl restart claude-bot
Step 3: Official Claude-GitHub Integration
To take it a step further, you can allow Claude to interact with your GitHub issues and PRs directly from the terminal.
* SSH into your VPS.
* Run the internal Claude command:
claude /install-github-app
* Follow the OAuth prompts to link your account. This allows the agent to run gh pr create or gh issue list so it can manage your web project’s tasks autonomously.
The “Pro” Tip: CLAUDE.md
To make your agent even more effective, create a file in your root directory called CLAUDE.md.
* What it does: Claude Code reads this file automatically every time it starts.
* What to put in it: List your preferred coding style (e.g., “Use clean PHP 8.2 syntax”), common terminal commands for your server (e.g., “To clear cache: php artisan cache:clear”), and your preferred HTML structure.
Would you like me to draft a custom CLAUDE.md tailored to your HTML and PHP workflow?
Yes
Since you develop article and informational web pages in HTML and PHP, a custom CLAUDE.md will serve as the “operating manual” for your agent. This ensures that every time Claude wakes up on your VPS, it remembers your specific coding style and environment constraints without you having to re-explain them.
Create a file named CLAUDE.md in your project’s root directory and paste the following:
# Claude Code: Web Development Guide (Nathan’s VPS)
## Project Overview
– **Core Stack:** PHP, HTML5, CSS3.
– **Environment:** Linux VPS (InterServer KVM).
– **Goal:** Creating clean, SEO-friendly informational web pages and articles.
## Development Standards
– **File Naming:** Use lowercase with hyphens for filenames (e.g., `ai-agents-article.php`).
– **PHP Style:** Use modern PHP 8.x syntax. Prefer `include_once` for headers and footers to keep articles modular.
– **HTML Structure:** Always include proper `<meta>` tags for SEO and responsive `<viewport>` tags.
– **Asset Paths:** Use relative paths for local CSS/JS to ensure portability across the VPS directories.
## Common Terminal Commands
– **Permissions:** If files aren’t editable, run: `sudo chown -R nathan:www-data .`
– **Local Server Test:** `php -S localhost:8000`
– **Git Sync:** `git add . && git commit -m “Update from Claude” && git push origin main`
## Workflow Preferences
– When creating article titles, **always put a new line between each title**—do not use numbers or bullet points.
– Before editing existing PHP files, read the file fully to maintain the existing design patterns.
– Always check the `/var/log/apache2/error.log` (or Nginx logs) if a PHP script fails.
## Deployment Notes
– This project is synced via GitHub Actions.
– Ensure all new `.php` files are added to the sitemap if applicable.
Why this works for you:
* Formatting Consistency: It explicitly locks in your requirement to avoid numbers/bullets for article lists, which is one of your saved preferences.
* Environment Awareness: It reminds Claude that it is on a Linux VPS, so it knows to use Linux commands (like chown or systemctl) rather than Mac or Windows ones.
* Modular Coding: Since you build informational pages, it encourages Claude to use PHP include statements, which makes managing a large site much easier than editing 50 individual HTML files.
How to use it:
Just drop this file into your main folder. Claude Code reads CLAUDE.md automatically upon startup. You can even tell it: “Claude, read my CLAUDE.md and tell me if you have any questions about my PHP style.”
Leave a Reply