I spent a session configuring Claude Code so that every interaction — across every repo, every environment — starts with the same global rules and automatically documents itself as a WordPress post. Here’s what I built and why.
The Problem
I have 28+ GitHub repos and use Claude Code from multiple environments: the terminal on my server, VS Code, and claude.ai/code (the browser-based sandbox). I wanted two things:
- Consistent agent behavior — the same rules and conventions applied everywhere, managed from a single source of truth.
- Automatic documentation — every Claude Code interaction logged as a private WordPress draft on my site, ready to review and publish.
Part 1: Global Rules via a Single Source of Truth
I maintain a file called agent.md in my agentGuidance repo. It defines my preferred stack, conventions, and workflow rules. The goal: every Claude Code session fetches the latest version of this file at startup, no matter which repo I’m working in.
The CLAUDE.md Layer
Every repo already had (or now has) a CLAUDE.md file in its root with a simple instruction to fetch the global rules:
curl -s https://raw.githubusercontent.com/npezarro/agentGuidance/main/agent.md
Claude Code automatically loads CLAUDE.md into context at session start. This works everywhere — terminal, IDE, and claude.ai/code. I pushed this file to all 28 repos in one batch.
The SessionStart Hook Layer
CLAUDE.md relies on the AI choosing to run the curl command. To make it truly automatic, I added a SessionStart hook — a shell command that Claude Code executes natively when a session begins, injecting the output directly into context.
In ~/.claude/settings.json (user-level, applies to all projects on this server):
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "bash ~/.claude/hooks/fetch-rules.sh",
"timeout": 15000
}
]
}
]
}
}
The script fetches the rules with a 10-second timeout and fails gracefully if the network is down.
Covering claude.ai/code
The user-level ~/.claude/settings.json only exists on my server. The browser-based claude.ai/code environment runs in a separate cloud sandbox. To cover that, I committed a project-level .claude/settings.json with the same SessionStart hook to all 28 repos. When any repo is cloned in that sandbox, the hook is right there.
| Environment | Hook fires? | CLAUDE.md loaded? |
|---|---|---|
| Terminal / IDE on my server | Yes (user-level) | Yes |
| claude.ai/code (cloud sandbox) | Yes (project-level) | Yes |
Part 2: Auto-Posting Interactions to WordPress
With the rules layer sorted, I wanted every Claude Code turn to automatically create a private WordPress post on this site — a living log of my AI-assisted development work.
How It Works
Claude Code supports a Stop hook that fires every time the assistant finishes responding. I wrote a bash script that:
- Reads the hook input (JSON on stdin with
session_id,transcript_path, andlast_assistant_message) - Parses the transcript JSONL to find the user’s last prompt
- Builds a title from the first ~60 characters of the prompt
- POSTs a private WordPress post via the REST API with the prompt and response formatted in HTML
Authentication uses a WordPress Application Password with Basic Auth. The script has a 15-second timeout and fails silently — it never blocks the session.
The Post Format
Each auto-generated post contains:
- The user prompt in a blockquote
- Claude’s full response
- Session ID and working directory as metadata
Posts are created as private by default, so I can review and edit before publishing.
The Result
With two hooks and a CLAUDE.md in every repo, I now have:
- One file to edit (
agentGuidance/agent.md) to update rules across all 28 repos and all environments - Automatic documentation of every Claude Code interaction as a private WordPress draft
- Zero manual steps — everything fires on session start and session stop
To update my global AI rules, I edit one file. Every future session — on any repo, in any environment — picks it up automatically. And every interaction gets logged here as a post I can curate and share.