<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henry Wang</title>
    <description>The latest articles on DEV Community by Henry Wang (@henrywangxf).</description>
    <link>https://dev.to/henrywangxf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3890523%2F34ea1bee-a876-46bb-8f12-dee20e078875.png</url>
      <title>DEV Community: Henry Wang</title>
      <link>https://dev.to/henrywangxf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/henrywangxf"/>
    <language>en</language>
    <item>
      <title>Using Git Commits as Claude Code's Memory</title>
      <dc:creator>Henry Wang</dc:creator>
      <pubDate>Tue, 21 Apr 2026 09:47:05 +0000</pubDate>
      <link>https://dev.to/henrywangxf/using-git-commits-as-claude-codes-memory-48e3</link>
      <guid>https://dev.to/henrywangxf/using-git-commits-as-claude-codes-memory-48e3</guid>
      <description>&lt;p&gt;Claude Code's context window is a liability. The longer a session runs, the more you're paying to re-read your own conversation history — and the more likely the model drifts on earlier context. Here's the workflow I landed on to fix it: &lt;strong&gt;one task, one worktree, one session, one commit&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;When you use Claude Code on a long task, context accumulates fast:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Earlier decisions get buried&lt;/li&gt;
&lt;li&gt;Token costs climb&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/clear&lt;/code&gt; wipes everything, including useful state&lt;/li&gt;
&lt;li&gt;Switching between tasks in the same session bleeds context&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most people either let sessions balloon or &lt;code&gt;/clear&lt;/code&gt; and lose everything. There's a better path.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Insight
&lt;/h2&gt;

&lt;p&gt;Git commit messages are &lt;strong&gt;free, durable, searchable context&lt;/strong&gt;. A well-written commit body is a session summary that survives &lt;code&gt;/clear&lt;/code&gt;, costs nothing to store, and is already part of your workflow. The trick is treating them as first-class context artifacts, not afterthoughts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Workflow
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. One Worktree Per Task
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git worktree add ../task-foo &lt;span class="nt"&gt;-b&lt;/span&gt; task/foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each task gets its own branch and working directory. No context bleeding between tasks. When you open Claude Code, you open it in that worktree.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Work in a Focused Session
&lt;/h3&gt;

&lt;p&gt;Keep the session scoped to the task. Don't mix concerns.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Write a Rich Commit Message
&lt;/h3&gt;

&lt;p&gt;This is the key step. Use the commit body as your session summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;tried&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt; fields are the most valuable — they capture reasoning that doesn't live in the code. You don't write this manually — at the end of a session, just tell Claude Code to commit, and it follows the format automatically (see CLAUDE.md below).&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Clear and Close
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;/clear
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or just close the session. The context is committed.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Resume Any Time
&lt;/h3&gt;

&lt;p&gt;Just open Claude Code in the worktree. Because of the &lt;code&gt;Session Start&lt;/code&gt; rule in &lt;code&gt;CLAUDE.md&lt;/code&gt;, it automatically reads &lt;code&gt;git log&lt;/code&gt; and orients itself before asking any questions. No manual context passing needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing the Gaps
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What about exploration sessions that produce no commits?&lt;/strong&gt;&lt;br&gt;
Commit a &lt;code&gt;NOTES.md&lt;/code&gt; or &lt;code&gt;SCRATCH.md&lt;/code&gt; anyway. One file, one commit, body = session summary. The commit is the log entry, not just the code change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about nuance that's hard to fit in a commit?&lt;/strong&gt;&lt;br&gt;
Write more. Commit bodies have no length limit. A 20-line body that captures a tricky decision is worth more than 5 lines of clean code with no context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about multi-session tasks?&lt;/strong&gt;&lt;br&gt;
Each worktree is on its own branch, so there's no conflict between tasks. For context across sessions on the same task, just use &lt;code&gt;git log&lt;/code&gt; — each session's commit body &lt;em&gt;is&lt;/em&gt; the running log. If you want a freeform scratchpad, keep a &lt;code&gt;CONTEXT.md&lt;/code&gt; in the worktree but add it to &lt;code&gt;.gitignore&lt;/code&gt; so it never enters git. It lives in the directory, stays out of the PR, and disappears when you remove the worktree.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Goes in CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;The commit messages handle &lt;strong&gt;task-level context&lt;/strong&gt;. Your &lt;code&gt;CLAUDE.md&lt;/code&gt; handles &lt;strong&gt;project-level context&lt;/strong&gt; — conventions, architecture decisions, things every session needs to know. That file is loaded automatically and costs nothing per session. Keep it sharp.&lt;/p&gt;

&lt;p&gt;Critically, put the commit format here so Claude Code writes it correctly every time without being told:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Session Start&lt;/span&gt;
At the start of each session, run &lt;span class="sb"&gt;`git log -5 --format="%s%n%b"`&lt;/span&gt; to orient yourself on recent work before asking any questions.

&lt;span class="gu"&gt;## Commit Format&lt;/span&gt;
Always write commit messages in this format:

type: short summary

what: what changed
why: motivation
tried: dead ends / rejected approaches
next: follow-up tasks (if any)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these two rules, Claude Code self-orients at the start and self-documents at the end — no manual context passing required.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Full Loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git worktree add ../task-name -b task/name
↓
Open Claude Code in that worktree
  → Claude reads git log, orients itself 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)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why This Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token efficient&lt;/strong&gt; — fresh sessions stay small&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Durable&lt;/strong&gt; — context survives &lt;code&gt;/clear&lt;/code&gt; and machine restarts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Searchable&lt;/strong&gt; — &lt;code&gt;git log --grep="auth"&lt;/code&gt; finds past decisions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discipline forcing&lt;/strong&gt; — writing the commit makes you articulate what you actually did&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero overhead tooling&lt;/strong&gt; — it's just git&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The mental shift is treating the commit message as a briefing document, not a changelog entry. You're writing for your next session's Claude Code, not for &lt;code&gt;git blame&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have a different approach to managing Claude Code context? I'd love to hear it.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>git</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
