| Age | Commit message (Collapse) | Author |
|
Git before 2.38 has no safe.bareRepository. Check before the prompt and
Stop hooks run git, following the same search git uses to find a
repository, and let a work tree kept elsewhere through core.worktree
through.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
Treat a folder as a repository to run git in only when it has its own
.git entry or the caller named the repository through GIT_DIR, and set
safe.bareRepository=explicit on the hook's git commands. Linked worktrees
and ordinary checkouts work as before.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
security-guidance: push review of a merge reviews what the push added
|
|
The reviewed prefix could end on the merged-in branch, so the diff held
everything the first parent has that the branch lacks. Keep the base on
HEAD's first-parent line. A merge whose history is all reviewed is sent as
its combined diff, so only its conflict resolutions and hand edits are read.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
A commit review starts from a hook on the Bash tool, so a commit made any
other way starts none. The Stop row now carries turn_commits: how many
commits the turn made, how many have no review, and how many of those no
commit hook saw. Count only; what is reviewed does not change, and no hook
entry is added.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
security-guidance: keep a renamed file paired with its old name in the Stop review
|
|
security-guidance: take the turn baseline without git stash create
|
|
security-guidance: keep new files in the Stop review when git add -N fails
|
|
security-guidance: read git log output without signature checks
|
|
When git add -N fails on both tries or times out, wake Claude once per
set of files with their names, so the review no longer ends as "no
changes". A timed-out add now keeps the tracked files' diff, so a
timeout on every turn cannot stop their reviews. Private object
directory cleanup no longer chmods through a link.
Fixes #6996
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
Whether git starts something in a gitlink's directory is decided when git runs,
so the check for a .git there beforehand can go stale. Remove all of them from
the copy. On git older than 2.34 the baseline for a submodule that is not
checked out falls back to HEAD.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
A bare program name on Windows is looked up in the working directory before
PATH, and the hooks run in the project. Name the first git.exe on PATH, leaving
out relative entries, the working directory and folders inside the project, as
the claude lookup already avoids that search.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
With log.showSignature set, git log and git show verify every signed commit,
which adds lines to the output the hooks parse and starts gpg.program. Set it
off for the hooks' git and for the commit reviewer's environment.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
stash create checks the work tree on one thread. add -u into the throwaway
index copy, write-tree and commit-tree produce the same commit and use git's
index preload instead, which matters where each file status is slow. See #6854.
|
|
Retry the add with a private object directory for users who cannot write the object store. Drop the pathspec settings git refuses alongside literal pathspecs, which hid new files since 2.0.16. When a failure stays and nothing is reviewed, keep the files for a later turn.
|
|
# Conflicts:
# plugins/security-guidance/hooks/diffstate.py
|
|
security-guidance: count failed git add -N calls in the Stop review
|
|
A failed add leaves new files out of the diff with no sign of it. Measure only; behaviour is unchanged.
|
|
Prompts that wait a second or more in the UserPromptSubmit hook send one
metrics row: total, baseline and untracked listing time, index size, and
whether the repository is on a Windows drive under WSL. Measures only;
capture is unchanged. See #6854.
|
|
|
|
|
|
The hooks run `git stash create` (the turn baseline) and
`git add --intent-to-add` (untracked files) on a throwaway copy of the
index. A nested repository that the index records is a gitlink entry
there. `git stash create` takes no --ignore-submodules option and
`git add` reads the gitlinks its paths cover, so both started a second
git inside that directory.
Before anything runs on the copy, remove the gitlink entry of every
nested repository from the copy, never from the real index. If that
removal fails, do not use the copy at all: the baseline falls back to
HEAD and runs no stash create, and the diff reads the real index with
--ignore-submodules=all. A gitlink whose directory has no `.git` (a
submodule that is not checked out) stays; git starts nothing there.
Run the intent-to-add `git add` with literal pathspecs, in that one
call's environment only.
The index file is scanned for a gitlink's mode bytes first, so a
repository without one starts no extra git process.
|
|
review
The Stop review limits its diff to the changed paths. For a rename that git
already knows about (git mv, or a rename committed during the turn) that list
held only the new name, so the diff showed a new file and the parsers could
not apply the rule that leaves out a file renamed away from a secret-shaped
name. The old name now goes into the list beside the new one, as it already
did for a plain mv.
The file listings themselves are unchanged.
|
|
The batched path commands now read each diff through the bounded reader
that main added, so both changes apply to get_git_diff.
|
|
security-guidance: count secret-named data files in the Stop review set
|
|
security-guidance: read the Stop review's git diff without holding it whole
|
|
security-guidance: keep Claude Code's own credential files out of reviews
|
|
security-guidance: do not review against a baseline from another checkout
|
|
Conflict in get_git_diff: main added IGNORE_SUBMODULES to the diff command on the line where this branch resets its read counters. Both are kept.
|
|
A directory with its own .git inside the work tree (a submodule, a vendored
checkout, an unpacked archive) was added to the throwaway index as a submodule
entry, and git then started a second git inside it to see whether it had
changed. Nothing in such a directory is reviewed.
git status and work-tree git diff now ignore submodule entries, an untracked
nested repository is no longer listed as a changed file or added to the index
copy, and a commit that moves a submodule is always shown as its two commit ids.
|
|
A reviewable file past the per-file cap now keeps as much again of its added lines, so a rewritten large file still shows what is new, and its diff ends with a line saying it was cut. The read runs on a thread so the 30 s limit holds while a process git started keeps the pipe open; a read that breaks is an error instead of a short diff. SG_MAX_FILE_DIFF_BYTES of zero or less means the default. The parser and the reader share one test for which files are reviewed.
|
|
The turn baseline (stash SHA, HEAD, untracked snapshot) is kept per
session, and the Stop review used it in whatever checkout the turn ended
in. After the session entered another worktree, that worktree's older
commits looked like commits made this turn and its files were diffed
against the first checkout's, so code committed long before was reviewed
and reported again (anthropics/claude-code#102567).
The prompt hook now stores the repo root and the prompt time beside the
baseline. When the Stop review runs in a different checkout it leaves the
baseline out and uses what that checkout can say for itself: its own HEAD
when the turn began (from its reflog) for the commit range, HEAD for file
contents, and file times to leave out uncommitted files last written
before the turn. A baseline taken after a finding records the checkout it
was taken in.
A prompt in a folder that is not a repo no longer replaces the untracked
snapshot of the kept baseline with an empty one, which made every
untracked file in the repo look new at the next Stop.
Stop rows carry `bl_origin`: 0 same checkout, 1 another worktree, 2
another repository, 3 a folder that is gone, 4 no baseline; plus 10 or 20
when the baseline is an earlier turn's.
|
|
Data files named like secrets.yml or client_secret.json are reviewed like any other file. The Stop hook now reports how many are in its review set, as a count only (secret_named_reviewed, emitted when nonzero), so the share of reviews that include one can be read from telemetry. No change to what is reviewed.
Refs anthropics/claude-code#96276
|
|
The Stop review captured the whole diff of the turn before its per-file caps applied, so a turn that wrote large text files cost the hook several times their size in memory. The output is now read as it arrives: files the review drops keep only their header line, and one file's diff is cut at 4 MiB (SG_MAX_FILE_DIFF_BYTES). The git command is unchanged.
Adds count-only metrics, nonzero only: diff_mb, diff_cut_files, diff_timeout.
|
|
paths do not fit one command
When the changed paths are too long for one git command:
- secret-shaped paths gone from the work tree go into every batch, so a
rename away from such a name is still paired and its content stays out
of the review
- the batch size follows the system's own argument limit when it is lower
- giving up is reported as skip 8 and a set with no source files as skip 7,
instead of 6 (no changes)
MAX_REVIEW_SET_PATHS counts only reviewable paths, read from the repo root,
so an unignored dependency directory does not hide an edited source file.
|
|
|
|
When the Claude Code config directory is a git repo, .credentials.json and .claude.json show up as changed files each time Claude Code rewrites them, and their contents (sign-in tokens, a saved API key, MCP server secrets) were sent to the Stop review. Treat both names as secret-shaped, like .netrc and .npmrc.
Refs anthropics/claude-code#90010
|
|
|
|
* security-guidance: keep secret-shaped files out of reviews
The Stop review covers every dirty file in the work tree, including ones the user changed and Claude never opened. Key files, credential files and encrypted dotfile sources were sent along with the code.
Skip files that are secret stores by naming convention: .env variants, SSH private keys, common credential files, and chezmoi private/encrypted sources.
* security-guidance: report how many secret-shaped files were skipped
The Stop hook now reports secret_shaped_skipped (a count, never names, only when nonzero) so the skip can be confirmed after release and watched for over-matching.
|
|
not fit one command
The Stop review passed every changed path to `git diff` as arguments. With enough of them (an unignored cache, a repo at $HOME) the OS refused to start git, the diff failed twice, and the turn's real edits were never reviewed.
When the OS refuses the argument list, keep only the paths the review can use (reviewable source files) and send them in a few commands under the same time limit. A path list that fits one command is handled exactly as before. Skip review sets of more than 100,000 paths before any diff.
Fixes #4824
|
|
With diff.mnemonicPrefix or diff.noprefix set in the user's git config, diff headers no longer read `a/<path> b/<path>`, the parser matched no file, and the review was skipped with nothing shown. mnemonicPrefix switched off the Stop review; noprefix switched off the commit and push reviews as well.
Pass the default prefix settings on every git call the hook makes.
Fixes #4569
|
|
A file whose header cannot be parsed is left out of the review without a trace. The Stop hook now reports diff_hdr_unparsed (a count, only when nonzero) so a header shape the parser misses shows up in metrics.
|
|
The diff parser split on the text 'diff --git ' anywhere, so a file whose own content contains it was cut short, and the rest of that file was never reviewed. It also dropped files whose names git quotes (a double quote, backslash or control character in the name).
Split only where a line starts with the header, and decode quoted names.
|
|
Releases before 2.0.10 ran `git stash create` on the real index. When that
git was killed, it left an `index.stash.<pid>` file the size of the index
in the git directory, and nothing removes those: a clone can hold hundreds.
Before it copies the index, the hook now deletes such files once they are
older than 30 minutes. It only touches regular files of the current user
whose name is exactly `index.stash.<digits>`, and never `index.lock`.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QR7edfw5HHkxJvJVgZiWpM
|
|
(2.0.10 → 2.0.11)
In a clone with a very large git index, 2.0.10 could still fill the disk.
It copies the index for each git call that might write it, and a hook that
Claude Code cancels (SIGTERM, then SIGKILL) never reached its cleanup, so
every cancelled hook left index-sized files in the temp directory for up
to 30 minutes. With several agents in one clone the live copies alone
could take many GB.
- A hook told to terminate removes its copies before it exits.
- A copy's name records the hook's pid; the next run deletes copies whose
hook is gone instead of waiting for the age limit.
- Diffs no longer need a copy: diff.autoRefreshIndex is off, so they only
read the index. Only `git stash create` and `git add -N` get one.
- The copy is a hard link where the filesystem allows it.
- Only so many hooks hold a copy at once, fewer as the disk fills. A hook
that gets no slot within 5 s goes without: the baseline falls back to
HEAD, or new untracked files are left out of that review.
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
With a very large git index the hook's git calls hit their time limits and
are killed, so git cannot clean up. Each kill could leave an index-sized
file in the temp directory, index.stash.<pid> files in .git, and a dead
.git/index.lock that fails the user's next git add or commit.
- `git stash create` and the work-tree diff run on a throwaway index copy.
- Every git the hook spawns gets GIT_OPTIONAL_LOCKS=0.
- Copies live in a private per-user folder and are removed together with
the files git writes next to them.
- Leftovers older than 30 minutes are swept, including existing ones.
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
:house: Remote-Dev: homespace
|
|
- SubagentStop reviews without consuming or advancing the session's
Stop state; an identical diff is not reviewed twice.
- SubagentStop from a different working tree than the project is skipped.
- An explicit `git -C <dir>` / `cd <dir>` naming another repository takes
precedence over the hook cwd.
- Narrows the `git -C … commit` matcher; keeps Windows path separators
when tokenizing; adds `--no-textconv` to diff/show invocations.
- Adds tests.
:house: Remote-Dev: homespace
|
|
followup)
Followup to PR #2086 (which added the flag to 4 specific git call
sites) and PR #2100 (text=True purge for #2099).
The Windows reporter for #2099 noticed more git invocations still
lacked the flag — rev-parse path queries (--show-toplevel, --git-dir,
--git-common-dir), reflog %gs subjects, and `git show <sha>:<path>`
all output paths but the per-site PR #2086 approach missed them. The
result: an Arabic-named directory shows up via _git_diff_range but
rev-parse-emitted paths get C-quoted, breaking downstream
os.path.isabs() checks.
Fix: add `-c core.quotePath=false` to GIT_CMD itself as the 4th
config-set. Every subprocess.run using the *GIT_CMD splat picks it
up automatically — diff feeders, rev-parse path queries, reflog log,
ls-files, status, git show. No more per-site flag duplication.
This commit:
1. gitutil.py: add -c core.quotePath=false to GIT_CMD.
2. Remove the now-redundant per-site flags at the 7 call sites that
previously had inline -c core.quotePath=false (cleanup, since the
global setting subsumes them):
gitutil.py: _git_diff_range, _git_name_only, _git_status_porcelain,
get_git_diff (4 sites)
diffstate.py: _list_untracked git ls-files (1 site)
security_reminder_hook.py: commit-review git diff + git show (2 sites)
Verified locally on latest main (post PR #2100 merge) with macOS
Python 3.13:
- py_compile clean on all 3 modified files.
- Bare main BEFORE my fix: 400/401 pass — 1 failure proves the gap
(test_git_cmd_contains_quotepath_false catches the missing flag).
- Main + my fix: 401/401 pass.
- 23 new tests in test_quotepath_global.py (added to internal test
suite at sg-staging/tests/, not in this PR):
* 1 GIT_CMD-level: GIT_CMD list contains core.quotePath=false as
a (-c, value) pair. Single source of truth — single place a
future PR will be caught if the flag gets dropped.
* 10 static-shape (one per hooks/*.py): every subprocess.run
uses the *GIT_CMD splat (no bare git invocation that would
bypass the global flag).
* 12 end-to-end (parametrized over Arabic, Hebrew, CJK directory
names): real git repo, _git_diff_range emits unquoted diff,
extract_file_paths_from_diff and parse_diff_into_files keep
the non-ASCII path in their output, _git_toplevel returns the
non-ASCII path intact.
- 1 staleness fix in test_diff_parser_non_ascii.py
(test_no_bare_git_diff_or_show_without_flag): updated to accept
EITHER inline core.quotePath=false OR *GIT_CMD splat (which
globally provides it).
NOT verified end-to-end on Windows with a non-ASCII repo root path.
The new global-flag test pins the contract permanently, and the
parametrized macOS tests confirm parser behavior on ASCII-control
paths in non-ASCII directories. The Windows-specific rev-parse
quoting behavior follows from the same git contract our macOS test
environment exercises (POSIX git always emits raw UTF-8 regardless
of quotePath; on Windows the flag is what makes output raw).
Closes the #2099 followup specifically about _git_diff_range /
rev-parse --show-toplevel / git log %gs paths slipping past.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|