Claude Code, 자동 코드 백업 설정을 모든 프로젝트에 적용하기 (Windows에서)

photo.jpg

Windows에서 파워쉘 터미널을 열고 그림에서와 같이 ii ~/.claude라고 입력하면 Claude Code의 설정을 담을 수 있는 폴더가 열립니다.

각 위치에 다음과 같이 파일을 준비하시면 Claude Code 전체 프로젝트에 대해서 적용하실 수 있습니다.

~/.claude/settings.json

{
  "permissions": {
    "allow": [
      "Edit(.commit_message.txt)"
    ],
    "deny": [
    ]
  },

  "hooks": {
    "Stop": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"$p = Join-Path $HOME '.claude/hooks/auto-commit.ps1'; & $p -- $env: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.ps1

# Auto-commit with .commit_message.txt (PowerShell)

if ($args.Count -lt 1 -or [string]::IsNullOrWhiteSpace($args[0])) { exit 0 }

$null = & git rev-parse --is-inside-work-tree 2>$null
if ($LASTEXITCODE -ne 0) { exit 0 }

$changes = & git status --porcelain
if ([string]::IsNullOrWhiteSpace($changes)) { exit 0 }

$top = $args[0].Trim()
$msgFile = Join-Path $top '.commit_message.txt'
if (!(Test-Path -LiteralPath $msgFile) -or (Get-Item -LiteralPath $msgFile).Length -eq 0) { exit 0 }
if ([string]::IsNullOrEmpty((Get-Content -LiteralPath $msgFile -Raw))) { exit 0 }

& git add -A
& git commit -F $msgFile --quiet

~/.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 를 담아두어주세요.