Skip to content

hookGit and releases

Session Git Context

A Claude Code hook that gives each new session the branch, the five latest commits and the changed files as starting context, with no prompt needed.

npx workspacetemplates add session-git-context --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file15 lines · 918 BFile
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{let j={};try{j=JSON.parse(d)}catch(e){}const cp=require('child_process');const g=a=>cp.execFileSync('git',a,{cwd:j.cwd||process.cwd(),encoding:'utf8',stdio:['ignore','pipe','ignore']}).trimEnd();try{const b=g(['branch','--show-current'])||'detached HEAD';let o='Session start. Branch: '+b+String.fromCharCode(10)+'Last commits:'+String.fromCharCode(10)+g(['log','-5','--oneline']);const c=g(['status','--short']).split(String.fromCharCode(10)).filter(Boolean);o+=String.fromCharCode(10)+(c.length?'Changed files ('+c.length+'): '+c.slice(0,15).join('; ')+(c.length>15?'; and more':''):'No changed files.');console.log(o)}catch(e){}process.exit(0)})\"",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

What it does

A fresh session knows nothing about what happened yesterday. This SessionStart hook prints a short briefing that Claude Code places in context: the branch, the five newest commit subjects and a list of files with pending changes.

With that in hand the agent can pick up where the last commit left off instead of asking you to explain. In a folder that is not a Git repository the hook stays quiet.

Example

you › Continue with the work from yesterday.

agent › The session opens with the branch name, five commit lines such as 'a1b2c3d Add retry to uploader' and the files still modified, so Claude can name the unfinished task.

Questions

Can I show more than five commits?
Yes. Change the number after the log flag inside the command, for example from 5 to 10.
Does it run when I resume or clear a session?
SessionStart fires for startup, resume and clear alike, so the briefing is refreshed each time.
  • Block Git No Verify

    HookGit and releases

    Free
  • Block Git Reset Hard

    HookGit and releases

    Free
  • Detect Merge Markers

    HookGit and releases

    Free
  • Inject Git Branch

    HookGit and releases

    Free