1. It may create branches and commits
A session can run git commands for you, including creating a branch and committing, when your prompt, a project instruction file or a skill asks for it. The documentation does not describe a default of committing on its own, but it also does not promise that nothing will be committed, and the one documented automatic branch is the one created by --worktree, named worktree-<name>. Treat both as possible and check, rather than assume.
Verify
git branch --show-current # empty output means detached HEAD
git status --short # uncommitted changes
git log --oneline -5 # recent commits and their messages
git reflog -10 # every HEAD movement, including ones log does not show
git worktree list # worktrees and the branch each one is onRestrict
Deny rules in the project settings stop the tool from running specific commands. The pattern Bash(git commit *) with a space before the star matches git commit with any arguments.
{
"permissions": {
"deny": [
"Bash(git commit *)",
"Bash(git push *)"
]
}
}A guardrail, not a sandbox
Rules match command text. The documentation states that git -C . push is not matched by Bash(git push *). Keep the same restriction in the place that cannot be bypassed: branch protection and push permissions on the remote, and credentials that are absent from the environment where the tool runs.
2. It may run in another directory than the one you opened
With --worktree (or -w) the tool creates a git worktree under <repo>/.claude/worktrees/<name>/ on a new branch worktree-<name> and works there. A session can also be moved into a worktree part-way through. In both cases edits land in that directory, not in the checkout you have open in your editor, and they are not in your branch until merged.
- An unnamed session with a clean worktree is removed on exit, together with its branch. A named session asks first.
.claude/worktrees/should be ignored by git. See configuration.- Paths in the output may be relative to the worktree, so “the file at
src/a.ts” may not be yoursrc/a.ts.
Verify
pwd # directory the command runs in
git rev-parse --show-toplevel # root of the working tree you are in
git worktree list # all worktrees, with branch or "detached HEAD"
git -C <path> status --short # state of another worktree, without leaving yoursRun the first two with the ! prefix inside the session and in your own terminal. If they differ, the tool is working somewhere other than where you are looking. Official page: worktrees.
3. It may answer correctly for its context and still miss your question
The tool answers from what it has read: the files it opened, the directory and branch it is in, the instructions it loaded. If any of these differ from what you had in mind, the answer can be accurate and still be about something else. Typical causes: a different branch or worktree, a file of the same name elsewhere in the tree, an outdated document taken as current, an instruction file that overrides what you asked.
- Ask for the evidence, not the conclusion. “Which files did you read, on which branch, and what is the exact line?”
- Restate the question in one sentence and ask whether that is what was answered.
- Check the inputs. The commands below show which version of the code the answer was based on.
- Prefer checks that do not involve the tool: a test, a grep, a diff.
git rev-parse --abbrev-ref HEAD # branch name, or HEAD when detached
git rev-parse HEAD # exact commit the answer should refer to
git status --short # local edits the answer may or may not include
grep -rn "<symbol>" <dir> # does the claimed definition exist, and where/status in the session shows which setting sources were loaded, which is where unexpected instructions usually come from.
A short check to run first
- Directory.
pwdandgit rev-parse --show-toplevelmatch your editor’s folder. - Branch.
git branch --show-currentis the branch you intended; if empty, you are on a detached HEAD. - Worktrees.
git worktree listshows only the ones you expect. - History.
git log --oneline -5contains no commit you did not ask for. - Rules. Deny rules for
git commitandgit pushare in place if the task does not need them.
Unofficial notes, not affiliated with or endorsed by Anthropic. Command names, flags and behaviour change between versions; the official documentation and the tool's own help output are authoritative.