Using Git Notes for AI Context
Git notes and trailers form a zero-infrastructure metadata layer for AI agent
context. Notes attach post-hoc metadata without changing commit SHAs. Trailers
embed structured key-value pairs inside commit messages.
Notes vs. trailers
| Scenario |
Use |
| Known at commit time, concise (<5 lines) |
Trailer |
| Known at commit time, verbose |
Note |
| Post-hoc (after commit) |
Note |
| Attribution data |
Note → ai/attribution |
| Prompts / sessions |
Note → ai/prompts |
| Constraints, rejected alternatives, directives |
Trailer (Lore protocol) |
| CI/CD output |
Note → ci/* |
| Deployment records |
Note → deployments |
Rule of thumb: If the metadata should travel with the commit and be visible
in git log, use trailers. If the metadata is post-hoc, verbose, or
machine-generated, use notes.
When authoring commits, keep subject/body format aligned with the repository's
commit convention; this skill focuses on metadata structure, storage, and
querying.
Workflows
Identify the task, then follow the matching workflow.
Annotating commits with AI context
- Decide notes vs. trailers using the table above.
- For notes — select the namespace per
references/01-core-concepts-and-namespaces.md
§Namespace Scheme:
git notes --ref=ai/attribution add -m \
'{"schema":"ai-context/1.0","agent":{"tool":"claude-code","model":"claude-opus-4-6"}}' HEAD
- For trailers — include footer lines in the commit message during
commit creation (using your team's normal commit flow), for example:
AI-Agent: claude-code/claude-opus-4-6
Constraint: Must remain backward-compatible
- Verify:
git notes --ref=ai/attribution show HEAD or
git log -1 --format='%(trailers)' HEAD.
- To automate, install hooks — see
references/03-hooks-scripts-and-automation.md.
Querying context before modifying code
- Harvest existing constraints, directives, and rejected approaches:
git log --format='%(trailers:key=Constraint,key=Directive,key=Rejected)' -- <file>
- Check AI attribution notes:
for sha in $(git log --format='%H' -- <file>); do
git notes --ref=ai/attribution show "$sha" 2>/dev/null
done
- Use this context to avoid repeating rejected approaches and honor active
constraints and directives.
Setting up git notes infrastructure
- Configure remote sync:
git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'
git config --add remote.origin.push '+refs/notes/*:refs/notes/*'
- Configure rebase survival:
git config --add notes.rewriteRef "refs/notes/ai/attribution"
git config notes.rewrite.rebase true
git config notes.rewrite.amend true
- Verify sync works:
git push origin 'refs/notes/*' --dry-run
- Install hooks for automatic annotation — see
references/03-hooks-scripts-and-automation.md.
- For teams: add onboarding script and namespace governance — see
references/04-team-enterprise-and-security.md.
Choosing tools
Default recommendations:
- Line-level AI attribution: Git AI (
git ai init) — broadest agent
support (12+), rebase survival, open standard.
- Decision context in commits: Lore protocol trailers — no tool required,
just trailer conventions.
- Both: They complement each other.
For detailed comparison, see
references/02-use-cases-and-tools.md
§Tool Comparison.
Essential commands
# Notes
git notes --ref=ai/attribution add -m 'data' HEAD # Add
git notes --ref=ai/attribution append -m 'more' HEAD # Append
git notes --ref=ai/attribution show HEAD # Read
git log --show-notes=ai/attribution # Show in log
# Trailers (read/query)
git log -1 --format='%(trailers)' HEAD # Read all
git log --format='%(trailers:key=Constraint)' -- file # Filter by key
git log -1 --format=%B HEAD | git interpret-trailers --parse # Parse raw message
# Sync
git push origin 'refs/notes/*' # Push all notes
git fetch origin 'refs/notes/*:refs/notes/*' # Fetch all notes
Edge cases
- Namespace conflict:
refs/notes/ai (bare) cannot coexist with
refs/notes/ai/prompts. Always use sub-paths like ai/attribution.
- Git AI ref conflict: Git AI occupies
refs/notes/ai (bare). If using
Git AI, use non-ai/ prefixes for custom namespaces (e.g., dev/prompts,
dev/decisions) to avoid ref conflicts.
- Rebase orphans notes: Configure
notes.rewriteRef (see "Setting up"
workflow). Git AI handles this automatically.
- Notes not synced by default: Must configure fetch/push refspecs.
- One note per namespace per object: Use
append to add to existing notes,
or use separate namespaces.
- No GitHub/GitLab UI display: Notes are CLI-only — invisible in web UIs.
- Merge conflicts under concurrency: Configure merge strategy per
namespace — see
references/04-team-enterprise-and-security.md
§Merge Strategies.
Reference material
- Core concepts and namespaces
— notes/trailers mechanics, namespace scheme, structured JSON format
- Use cases and tools — Lore protocol,
session metadata, CI/CD, tool comparison
- Hooks, scripts, and automation
— post-commit/pre-push hooks, GitHub Actions, aliases, context harvest
- Team, enterprise, and security
— remote sync, merge strategies, compliance, redaction, signing, limitations
1---2name: using-git-notes-for-ai-context3description: Reads, writes, and configures git notes and trailers for AI agent context — attribution, decision reasoning, prompts, and CI/CD metadata. Sets up namespace conventions, hook automation, team sync, and compliance. Use when storing AI attribution in git, setting up git notes for AI tracking, querying constraints or directives before modifying code, configuring notes sync for a team, choosing between git notes and trailers, or when the user mentions git notes, git trailers, AI attribution, AI provenance, Lore protocol, or decision context in commits.4---5
6# Using Git Notes for AI Context
7
8Git notes and trailers form a zero-infrastructure metadata layer for AI agent
9context. Notes attach post-hoc metadata without changing commit SHAs. Trailers
10embed structured key-value pairs inside commit messages.
11
12## Notes vs. trailers
13
14| Scenario | Use |
15|----------|-----|
16| Known at commit time, concise (<5 lines) | **Trailer** |
17| Known at commit time, verbose | **Note** |
18| Post-hoc (after commit) | **Note** |
19| Attribution data | Note → `ai/attribution` |
20| Prompts / sessions | Note → `ai/prompts` |
21| Constraints, rejected alternatives, directives | Trailer (Lore protocol) |
22| CI/CD output | Note → `ci/*` |
23| Deployment records | Note → `deployments` |
24
25**Rule of thumb:** If the metadata should travel with the commit and be visible
26in `git log`, use trailers. If the metadata is post-hoc, verbose, or
27machine-generated, use notes.
28
29When authoring commits, keep subject/body format aligned with the repository's
30commit convention; this skill focuses on metadata structure, storage, and
31querying.
32
33## Workflows
34
35Identify the task, then follow the matching workflow.
36
37### Annotating commits with AI context
38
391. Decide notes vs. trailers using the table above.
402. For **notes** — select the namespace per
41 [references/01-core-concepts-and-namespaces.md](references/01-core-concepts-and-namespaces.md)
42 §Namespace Scheme:
43 ```bash
44 git notes --ref=ai/attribution add -m \
45 '{"schema":"ai-context/1.0","agent":{"tool":"claude-code","model":"claude-opus-4-6"}}' HEAD
46 ```
473. For **trailers** — include footer lines in the commit message during
48 commit creation (using your team's normal commit flow), for example:
49 ```text
50 AI-Agent: claude-code/claude-opus-4-6
51 Constraint: Must remain backward-compatible
52 ```
534. Verify: `git notes --ref=ai/attribution show HEAD` or
54 `git log -1 --format='%(trailers)' HEAD`.
555. To automate, install hooks — see
56 [references/03-hooks-scripts-and-automation.md](references/03-hooks-scripts-and-automation.md).
57
58### Querying context before modifying code
59
601. Harvest existing constraints, directives, and rejected approaches:
61 ```bash
62 git log --format='%(trailers:key=Constraint,key=Directive,key=Rejected)' -- <file>
63 ```
642. Check AI attribution notes:
65 ```bash
66 for sha in $(git log --format='%H' -- <file>); do
67 git notes --ref=ai/attribution show "$sha" 2>/dev/null
68 done
69 ```
703. Use this context to avoid repeating rejected approaches and honor active
71 constraints and directives.
72
73### Setting up git notes infrastructure
74
751. Configure remote sync:
76 ```bash
77 git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'
78 git config --add remote.origin.push '+refs/notes/*:refs/notes/*'
79 ```
802. Configure rebase survival:
81 ```bash
82 git config --add notes.rewriteRef "refs/notes/ai/attribution"
83 git config notes.rewrite.rebase true
84 git config notes.rewrite.amend true
85 ```
863. Verify sync works:
87 ```bash
88 git push origin 'refs/notes/*' --dry-run
89 ```
904. Install hooks for automatic annotation — see
91 [references/03-hooks-scripts-and-automation.md](references/03-hooks-scripts-and-automation.md).
925. For teams: add onboarding script and namespace governance — see
93 [references/04-team-enterprise-and-security.md](references/04-team-enterprise-and-security.md).
94
95### Choosing tools
96
97Default recommendations:
98
99- **Line-level AI attribution**: Git AI (`git ai init`) — broadest agent
100 support (12+), rebase survival, open standard.
101- **Decision context in commits**: Lore protocol trailers — no tool required,
102 just trailer conventions.
103- **Both**: They complement each other.
104
105For detailed comparison, see
106[references/02-use-cases-and-tools.md](references/02-use-cases-and-tools.md)
107§Tool Comparison.
108
109## Essential commands
110
111```bash
112# Notes
113git notes --ref=ai/attribution add -m 'data' HEAD # Add
114git notes --ref=ai/attribution append -m 'more' HEAD # Append
115git notes --ref=ai/attribution show HEAD # Read
116git log --show-notes=ai/attribution # Show in log
117
118# Trailers (read/query)
119git log -1 --format='%(trailers)' HEAD # Read all
120git log --format='%(trailers:key=Constraint)' -- file # Filter by key
121git log -1 --format=%B HEAD | git interpret-trailers --parse # Parse raw message
122
123# Sync
124git push origin 'refs/notes/*' # Push all notes
125git fetch origin 'refs/notes/*:refs/notes/*' # Fetch all notes
126```
127
128## Edge cases
129
130- **Namespace conflict**: `refs/notes/ai` (bare) cannot coexist with
131 `refs/notes/ai/prompts`. Always use sub-paths like `ai/attribution`.
132- **Git AI ref conflict**: Git AI occupies `refs/notes/ai` (bare). If using
133 Git AI, use non-`ai/` prefixes for custom namespaces (e.g., `dev/prompts`,
134 `dev/decisions`) to avoid ref conflicts.
135- **Rebase orphans notes**: Configure `notes.rewriteRef` (see "Setting up"
136 workflow). Git AI handles this automatically.
137- **Notes not synced by default**: Must configure fetch/push refspecs.
138- **One note per namespace per object**: Use `append` to add to existing notes,
139 or use separate namespaces.
140- **No GitHub/GitLab UI display**: Notes are CLI-only — invisible in web UIs.
141- **Merge conflicts under concurrency**: Configure merge strategy per
142 namespace — see
143 [references/04-team-enterprise-and-security.md](references/04-team-enterprise-and-security.md)
144 §Merge Strategies.
145
146## Reference material
147
148- [Core concepts and namespaces](references/01-core-concepts-and-namespaces.md)
149 — notes/trailers mechanics, namespace scheme, structured JSON format
150- [Use cases and tools](references/02-use-cases-and-tools.md) — Lore protocol,
151 session metadata, CI/CD, tool comparison
152- [Hooks, scripts, and automation](references/03-hooks-scripts-and-automation.md)
153 — post-commit/pre-push hooks, GitHub Actions, aliases, context harvest
154- [Team, enterprise, and security](references/04-team-enterprise-and-security.md)
155 — remote sync, merge strategies, compliance, redaction, signing, limitations