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