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