Comment by dwb

2 days ago

Yes, it’s fantastic. I have a post-tool-use hook for Claude Code to snapshot the repository for every edit. It’s like the built in file history feature but native in my VCS and works for my edits too. Don’t want to froth too much but JJ is my favourite piece of software in a while, and the fact that it’s not VC-funded is a major plus point.

Its VC funded https://www.sec.gov/Archives/edgar/data/2076429/000207642925...

  • Jujutsu is not "VC funded". But some of the developers, including me, work at East River Source Control (I worked on Jujutsu before that, too). The majority of the code in the project doesn't come from us -- or Google, for that matter. We don't allow people to approve patches when the author is from the same company, anyway.

    • (also at ERSC here, hi Austin!) Heck, I have not had enough bandwidth to do as much upstream work as I initially thought I would when I started there!

  • that's a company built on top of Jujutsu, not jj itself

    • If I remember correctly, jj is one guy who works at Google. Which presents a separate worry, which is that one day, when jj gets popular enough, Google will consume it, make it shit, change the name of it every six months and then shut it down.

      4 replies →

Can you expand on this? How do you achieve it? Just a WIP JJ commit after every change or something more clever?

  •   "hooks": {
        "PreToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [
              {
                "type": "command",
                "command": "if command -v jj >/dev/null && jj root >/dev/null 2>&1; then if ! jj status >/dev/null 2>&1; then echo 'WARNING: failed to snapshot jj repository, tell user to fix'; fi; fi"
              }
            ]
          }
        ],
        "PostToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [
              {
                "type": "command",
                "command": "if command -v jj >/dev/null && jj root >/dev/null 2>&1; then if ! jj status >/dev/null 2>&1; then echo 'WARNING: failed to snapshot jj repository, tell user to fix'; fi; fi"
              }
            ]
          },
    

    In newer jj there’s a dedicated snapshot command but I’ve not updated yet. Pop this in your Claude Code settings.json. It will snapshot the repository, thus recording any changes. Explore with jj evolog.

  • In .claude/settings.json you can trigger shell commands on events like SessionStart, Stop, PreCompact, and PostToolUse [1].

    I have all of them run `jj status`, because jj snapshots the working copy every time it's invoked.

    You can have Claude write the hooks, but mine is:

    `[[ -d .jj ]] && jj status >/dev/null 2>&1; exit 0`

    [1] https://code.claude.com/docs/en/agent-sdk/hooks

  • The others use `jj status`, but if I were to do this, I'd use `jj log -n0`, which has no output. All you really need is any read-only jj command.

    You could also turn on watchman and have this property on every save of a file and not even need to worry about hooks.