Claude Code, 자동 코드 백업 설정을 모든 프로젝트에 적용하기 (macOS에서)
macOS에서 ~/
는 사용자의 Home 경로를 의미합니다.
Finder 앱에서 Cmd+Shift+h
단축키를 누르면 이동하는 그 경로가 Home 경로이며 ~/
로 표시됩니다.
각 위치에 다음과 같이 파일을 준비하시면 claude code 전체 프로젝트에 대해서 적용하실 수 있습니다.
~/.claude/settings.json
{
"permissions": {
"allow": [
"Edit(.commit_message.txt)"
],
"deny": [
]
},
"hooks": {
"Stop": [
{
"matcher": "Edit|MultiEdit|Write",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/auto-commit.sh \"$CLAUDE_PROJECT_DIR\""
}
]
}
]
}
}
~/.claude/CLAUDE.md
# Claude Code Project Setup
## Version Control
* Whenever code changes are made, you must record a one-line description with emoji in korean of the change in `.commit_message.txt` with Edit Tool.
- Read `.commit_message.txt` first, and then Edit.
- Overwrite regardless of existing content.
- If it was a git revert related operation, make the .commit_message.txt file empty.
~/.claude/hooks/auto-commit.sh
#!/usr/bin/env bash
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
[ -z "$(git status --porcelain)" ] && exit 0
MSG_FILE="${1}/.commit_message.txt"
[ -s "$MSG_FILE" ] || exit 0
[ -z "$(cat "$MSG_FILE")" ] && exit 0
git add -A
git commit -F "$MSG_FILE" -q
~/.claude/commands/git-log.md
git log --oneline --date=format:'%Y-%m-%d %H:%M' --format="%h %ad %s"
~/.claude/commands/git-revert.md
git revert --no-edit --no-commit #$ARGUMENTS..HEAD && git commit -C "#$ARGUMENTS"
그리고 프로젝트 폴더 안에는 .gitignore
파일을 준비해서 .commit_message.txt
를 담아두어주세요.