Updated Hooks for auto sync
This commit is contained in:
@@ -32,18 +32,31 @@ AI/
|
|||||||
|
|
||||||
### Claude Code (Automatic)
|
### Claude Code (Automatic)
|
||||||
|
|
||||||
Claude Code automatically reads `CLAUDE.md` from the root of any project it's working in.
|
Claude Code automatically reads `~/.claude/CLAUDE.md` globally, and any `CLAUDE.md` in a project root. Global preferences apply everywhere; project-level adds on top.
|
||||||
|
|
||||||
**Option A — Per project:** Copy `CLAUDE.md` into the root of any project repo. Claude Code will pick it up automatically every session.
|
**Recommended setup (symlinks + auto-pull across machines):**
|
||||||
|
|
||||||
**Option B — Global (recommended):** Place `CLAUDE.md` in your Claude global config folder so it applies to *every* project without copying:
|
Clone this repo locally and symlink `CLAUDE.md` and `preferences/` into `~/.claude/`. From that point on, `git pull` is the only sync step — and the auto-pull hook in `preferences/hooks-setup.md` handles that automatically on every session.
|
||||||
|
|
||||||
```
|
**Linux (one-time setup per machine):**
|
||||||
# Windows
|
|
||||||
Copy-Item "CLAUDE.md" "$env:USERPROFILE\.claude\CLAUDE.md"
|
```bash
|
||||||
|
git clone https://git.chns.tech/CHNS/AI ~/repos/AI
|
||||||
|
ln -sf ~/repos/AI/CLAUDE.md ~/.claude/CLAUDE.md
|
||||||
|
ln -sf ~/repos/AI/preferences ~/.claude/preferences
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: If a project also has its own `CLAUDE.md`, Claude Code merges both — global preferences apply everywhere, project-specific ones add on top.
|
**Windows (one-time setup — requires Developer Mode or run PowerShell as Administrator):**
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
git clone https://git.chns.tech/CHNS/AI C:\repos\AI
|
||||||
|
Remove-Item "$env:USERPROFILE\.claude\CLAUDE.md" -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Item "$env:USERPROFILE\.claude\preferences" -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
New-Item -ItemType SymbolicLink -Path "$env:USERPROFILE\.claude\CLAUDE.md" -Target "C:\repos\AI\CLAUDE.md"
|
||||||
|
New-Item -ItemType SymbolicLink -Path "$env:USERPROFILE\.claude\preferences" -Target "C:\repos\AI\preferences"
|
||||||
|
```
|
||||||
|
|
||||||
|
After symlinking, configure hooks from `preferences/hooks-setup.md` — the auto-pull hook will keep preferences current automatically.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -115,16 +128,10 @@ Preferences should evolve as your stack and habits change. Treat this repo like
|
|||||||
|
|
||||||
### After Updating
|
### After Updating
|
||||||
|
|
||||||
**If you're using the global Claude Code setup**, sync your changes by running these two commands from the repo root:
|
**If you're using the symlink setup**, no manual copy step is needed. Edit the repo files directly — the symlinks mean `~/.claude/` always reflects the latest committed content. The auto-pull hook fetches remote changes automatically at the start of each session.
|
||||||
|
|
||||||
```powershell
|
> **Hooks are not synced automatically.** `~/.claude/settings.json` is machine-local and not part of this repo. After cloning and symlinking on a new machine, set up hooks by telling Claude Code: *"Read preferences/hooks-setup.md and configure my ~/.claude/settings.json with the required hooks."*
|
||||||
Copy-Item "CLAUDE.md" "$env:USERPROFILE\.claude\CLAUDE.md" -Force
|
|
||||||
Copy-Item -Path "preferences" -Destination "$env:USERPROFILE\.claude\preferences" -Recurse -Force
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Hooks are not synced automatically.** `~/.claude/settings.json` is machine-local and not part of this repo. After syncing preferences on a new machine, set up hooks by telling Claude Code: *"Read preferences/hooks-setup.md and configure my ~/.claude/settings.json with the required hooks."*
|
|
||||||
|
|
||||||
- If you've **copied** `CLAUDE.md` into other project repos, re-copy the updated version to those projects
|
|
||||||
- If you're using **ChatGPT/Claude.ai** manually, you'll be pasting the updated file next time
|
- If you're using **ChatGPT/Claude.ai** manually, you'll be pasting the updated file next time
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -19,9 +19,20 @@ They cannot be committed to a repo (global user settings only).
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 3. Auto-Sync Preferences (UserPromptSubmit)
|
||||||
|
|
||||||
|
**Trigger:** Before each user message
|
||||||
|
**Behavior:** Runs `git pull` in the local clone of this preferences repo. Because `CLAUDE.md` and `preferences/` are symlinked into `~/.claude/`, the pull immediately updates what Claude sees without any manual steps. Silently skips if already up to date or unreachable.
|
||||||
|
|
||||||
|
Requires the one-time symlink + clone setup described in this repo's `README.md`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Settings JSON
|
## Settings JSON
|
||||||
|
|
||||||
Add this to `~/.claude/settings.json` (merge with any existing content):
|
Add this to `~/.claude/settings.json` (merge with any existing content). Commands differ by platform — use the block that matches your machine.
|
||||||
|
|
||||||
|
#### Linux
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -50,6 +61,51 @@ Add this to `~/.claude/settings.json` (merge with any existing content):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"UserPromptSubmit": [
|
||||||
|
{
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "git -C \"$HOME/repos/AI\" pull --quiet --ff-only 2>/dev/null; true",
|
||||||
|
"async": true,
|
||||||
|
"statusMessage": "Syncing preferences..."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Windows
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"hooks": {
|
||||||
|
"Stop": [
|
||||||
|
{
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "agent",
|
||||||
|
"prompt": "Check if a README.md file exists in the current project directory. If it does, review what changes were made during this session and update README.md to reflect any new or changed functionality, configuration, API endpoints, environment variables, or setup steps. Only make updates if there is genuinely new or changed information that belongs in a README. Preserve the existing format and style. If nothing meaningful changed, leave the README as-is.",
|
||||||
|
"statusMessage": "Checking README for updates...",
|
||||||
|
"timeout": 120
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"UserPromptSubmit": [
|
||||||
|
{
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "powershell -NonInteractive -Command \"git -C C:\\repos\\AI pull --quiet --ff-only 2>$null\"",
|
||||||
|
"async": true,
|
||||||
|
"statusMessage": "Syncing preferences..."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user