Source Code
agent-client-tutorial/03-git-operationsWhat You’ll Build
An agent that inspects git history, finds commits on a detached HEAD, and merges them into the main branch. This demonstrates agents working with version control — a common real-world task.Step 1: Set Up the Repository
Clone the tutorial and run the setup script that creates a git repo with “lost” changes:workspace/ with a commit on a detached HEAD — simulating changes that were accidentally “lost” when switching back to master.
Step 2: Understand the Goal
The prompt describes the problem in natural language, as a developer would:- Inspect the git reflog to find the detached commit
- Identify the lost changes
- Merge or cherry-pick them into master
Step 3: Run It
Bash to run git reflog, git log, git merge, etc.
Step 4: Verify
What’s Different from Previous Lessons
- Stateful environment — the agent works in an existing git repository, not a clean directory
- Multi-step reasoning — finding lost commits requires inspecting reflog, understanding branch state, and choosing a merge strategy
- Tool-heavy task — the agent runs multiple shell commands, reads their output, and decides next steps
- STRICT mode applicable — this task genuinely requires a git repository, making it a natural fit for
AgentClientMode.STRICT
The LOOSE/STRICT Connection
Lessons 1-3 work in any directory — they don’t need git. That’s why LOOSE mode (the default) is appropriate. This lesson requires a git repository. If you were building a system that only runs git-aware tasks, STRICT mode would prevent accidental execution outside a git repo. See Defaults Philosophy for more on when to use each mode.Next Steps
- Getting Started — Recap the quick start for all three providers
- Switching Providers — Run any tutorial lesson with a different provider
- Claude Reference — Full configuration options including trace files