Skip to content

Commit 40382c7

Browse files
konardclaude
andcommitted
fix(hooks): auto-stage .gemini, .claude, .codex directories on commit
- Remove .claude from .gitignore so it can be tracked alongside .gemini and .codex - Add auto-staging logic to pre-commit hook for AI agent config directories - Update setup-pre-commit-hook.js to include AI dir staging in generated hook - Auto-configure core.hooksPath in setup script instead of requiring manual step Previously the pre-commit hook only staged .knowledge directories. The .claude directory was also listed in .gitignore, making it impossible to track. The setup script required a manual `git config core.hooksPath .githooks` step that was easy to forget, causing all hooks (including pre-push session backup) to never activate. Fixes #170 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ef9b5b4 commit 40382c7

4 files changed

Lines changed: 86 additions & 7 deletions

File tree

.githooks/pre-commit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ done < <(
1515
-print0
1616
)
1717

18+
# CHANGE: auto-stage AI agent config directories (.gemini, .claude, .codex)
19+
# WHY: ensures AI session context is always included in commits without manual git add
20+
# REF: issue-170
21+
for ai_dir in .gemini .claude .codex; do
22+
if [ -d "$ai_dir" ]; then
23+
git add -A -- "$ai_dir"
24+
fi
25+
done
26+
1827
MAX_BYTES=$((99 * 1000 * 1000))
1928
too_large=()
2029

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ yarn-error.log*
2323
pnpm-debug.log*
2424
reports/
2525
.idea
26-
.claude
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Test that the pre-commit hook logic correctly stages AI config directories
5+
echo "=== Testing AI directory auto-staging logic ==="
6+
7+
REPO_ROOT="$(git rev-parse --show-toplevel)"
8+
cd "$REPO_ROOT"
9+
10+
# Create test AI directories with test files
11+
for ai_dir in .gemini .claude .codex; do
12+
mkdir -p "$ai_dir"
13+
echo "test-content-$(date +%s)" > "$ai_dir/test-file.txt"
14+
done
15+
16+
echo "Created test files:"
17+
ls -la .gemini/test-file.txt .claude/test-file.txt .codex/test-file.txt
18+
19+
# Check gitignore status
20+
echo ""
21+
echo "=== Checking gitignore status ==="
22+
for ai_dir in .gemini .claude .codex; do
23+
if git check-ignore -q "$ai_dir/test-file.txt" 2>/dev/null; then
24+
echo "IGNORED: $ai_dir (this is a problem!)"
25+
else
26+
echo "NOT IGNORED: $ai_dir (good - can be tracked)"
27+
fi
28+
done
29+
30+
# Simulate the auto-staging logic from the pre-commit hook
31+
echo ""
32+
echo "=== Simulating auto-staging ==="
33+
for ai_dir in .gemini .claude .codex; do
34+
if [ -d "$ai_dir" ]; then
35+
git add -A -- "$ai_dir"
36+
echo "Staged: $ai_dir"
37+
fi
38+
done
39+
40+
echo ""
41+
echo "=== Staged files ==="
42+
git diff --cached --name-only | grep -E "^\.(gemini|claude|codex)/" || echo "(none found)"
43+
44+
# Clean up - unstage the test files
45+
git reset HEAD -- .gemini .claude .codex 2>/dev/null || true
46+
rm -rf .gemini/test-file.txt .claude/test-file.txt .codex/test-file.txt
47+
48+
echo ""
49+
echo "=== Test complete ==="

scripts/setup-pre-commit-hook.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env node
22

3-
// CHANGE: Add repeatable pre-commit hook setup for secret auto-redaction
4-
// WHY: Keep secret scanning on every commit without one-time manual hook wiring.
3+
// CHANGE: Add repeatable pre-commit hook setup for secret auto-redaction and AI session directory staging
4+
// WHY: Keep secret scanning on every commit without one-time manual hook wiring,
5+
// and automatically include .gemini, .claude, .codex directories in commits.
6+
// REF: issue-170
57
// SOURCE: n/a
68
// PURITY: SHELL (git config + filesystem)
79

@@ -33,6 +35,15 @@ done < <(
3335
-print0
3436
)
3537
38+
# CHANGE: auto-stage AI agent config directories (.gemini, .claude, .codex)
39+
# WHY: ensures AI session context is always included in commits without manual git add
40+
# REF: issue-170
41+
for ai_dir in .gemini .claude .codex; do
42+
if [ -d "$ai_dir" ]; then
43+
git add -A -- "$ai_dir"
44+
fi
45+
done
46+
3647
MAX_BYTES=$((99 * 1000 * 1000))
3748
too_large=()
3849
@@ -59,7 +70,18 @@ bash "$REPO_ROOT/scripts/pre-commit-secret-guard.sh"
5970

6071
fs.chmodSync(hookPath, 0o755);
6172

62-
console.log(
63-
"Installed .githooks/pre-commit."
64-
);
65-
console.log("Enable it for this repository with: git config core.hooksPath .githooks");
73+
// CHANGE: automatically configure core.hooksPath so hooks are active immediately
74+
// WHY: previously required a manual step that was easy to forget, causing hooks to never run
75+
// REF: issue-170
76+
const { execFileSync } = require("node:child_process");
77+
try {
78+
execFileSync("git", ["config", "core.hooksPath", ".githooks"], {
79+
cwd: repoRoot,
80+
encoding: "utf8",
81+
stdio: ["pipe", "pipe", "pipe"],
82+
});
83+
console.log("Installed .githooks/pre-commit and configured core.hooksPath = .githooks");
84+
} catch (error) {
85+
console.log("Installed .githooks/pre-commit.");
86+
console.log("Enable it for this repository with: git config core.hooksPath .githooks");
87+
}

0 commit comments

Comments
 (0)