Git 커밋을 Claude Code의 메모리로 사용하기

발행: (2026년 4월 21일 PM 06:47 GMT+9)
5 분 소요
원문: Dev.to

Source: Dev.to

The problem

Claude Code의 컨텍스트 창은 단점이 됩니다. 세션이 오래 지속될수록 자신의 대화 기록을 다시 읽는 데 비용이 늘어나고, 모델이 이전 컨텍스트에서 벗어날 가능성이 커집니다.

  • 컨텍스트가 빠르게 누적됩니다(긴 작업일수록).
  • 초기 결정이 묻혀 버립니다.
  • 토큰 비용이 상승합니다.
  • /clear는 유용한 상태까지 모두 삭제합니다.
  • 같은 세션에서 작업을 전환하면 컨텍스트가 섞입니다.

대부분의 사람들은 세션이 커지는 것을 허용하거나 /clear를 사용해 모든 것을 잃어버립니다.

Solution: Git as a memory layer

Git 커밋 메시지를 무료이고 영구적이며 검색 가능한 컨텍스트로 활용합니다. 잘 작성된 커밋 본문은 /clear 후에도 살아남는 세션 요약이 되며, 저장 비용이 들지 않고 작업 흐름에 자연스럽게 통합됩니다.

1. One task → one worktree → one branch

git worktree add ../task-foo -b task/foo

각 작업마다 별도의 브랜치와 작업 디렉터리를 만들어 컨텍스트 섞임을 방지합니다. 해당 워크트리 안에서 Claude Code를 엽니다.

2. Commit‑body session summary

세션이 끝날 때 다음과 같은 풍부한 커밋 형식을 사용합니다:

feat: add user auth flow

what: JWT‑based auth with refresh token rotation
why: existing session cookie approach didn't work cross‑subdomain
tried: httpOnly cookie sharing — blocked by Safari ITP
next: wire up logout endpoint (separate task)

triednext 필드는 코드에 남지 않는 추론을 담습니다. 이를 직접 작성할 필요는 없습니다—Claude Code에게 commit을 요청하면 자동으로 형식에 맞게 작성해 줍니다(아래 “Commit format” 섹션 참고).

3. Session start orientation

Claude Code를 워크트리에서 열면 자동으로 다음을 실행합니다:

git log -5 --format="%s%n%b"

최근 커밋 메시지를 읽어 모델을 질문하기 전에 방향을 잡아줍니다.

Handling special cases

  • Exploratory sessions with no commitsNOTES.md 또는 SCRATCH.md 파일을 만들고, 본문이 세션 요약인 단일 커밋을 생성합니다.
  • Nuanced information – 워크트리 안에 CONTEXT.md를 두고 .gitignore에 추가해 저장소에 포함되지 않게 합니다; 로컬에만 존재하며 워크트리를 삭제하면 사라집니다.
  • Multi‑session tasks – 각 세션마다 커밋을 추가하면, 커밋 본문들의 연속이 실행 로그가 됩니다.

Commit format (must‑have)

type: short summary

what: what changed
why: motivation
tried: dead ends / rejected approaches
next: follow‑up tasks (if any)

Full workflow diagram

git worktree add ../task-name -b task/name

Open Claude Code in that worktree
  → Claude reads `git log`, orients automatically

Work on the task

Tell Claude Code: "commit"
  → Claude writes the rich commit message, you review and confirm

/clear  (or close the session)

git worktree remove ../task-name  (when merged)

Benefits

  • Token efficient – 새로운 세션이 작게 유지됩니다.
  • Durable – 컨텍스트가 /clear와 머신 재시작을 넘어 살아남습니다.
  • Searchablegit log --grep="auth" 로 과거 결정을 찾을 수 있습니다.
  • Discipline‑forcing – 커밋을 작성하면서 수행한 작업을 명확히 표현하게 됩니다.
  • Zero overhead tooling – Git만 있으면 됩니다.

Closing thought

커밋 메시지를 다음 Claude Code 세션을 위한 브리핑 문서로 생각하세요. 단순한 변경 로그가 아니라 말이죠.

Claude Code 컨텍스트 관리에 다른 접근법이 있나요? 공유해 주세요.

0 조회
Back to Blog

관련 글

더 보기 »