Module 02 / Lesson 03
Run Safe Git Worktree Experiments and Find Symbols with Serena
Treat your AI coding agent like an engineer who needs a clear handbook, an organized desk, and a safe sandbox.
You wouldn’t dump a 500-page operational manual into every short conversation with a teammate, nor would you let an intern run experimental tests directly on your production branch. When you connect too many tools or paste huge documents into an AI session, its memory context fills up, causing it to ignore earlier rules and make random mistakes.
Read the narration transcript
Keep the review branch clean
The publish change is already under review. I want to try a shorter timeline layout without mixing its edits into that review.
I create a linked worktree from the agreed starting commit. The experiment gets its own branch and working directory. The original checkout stays on the review branch.
Run the timeline experiment in another checkout
The main checkout already has a publish change in review. I create a second Git worktree for the timeline experiment. Think of it as a separate folder checked out on another branch.
The list shows the two paths and branches. I start the experimental session in the new folder, then check the path before it touches a file. Both checkouts can still point at the same database, so I use seeded local data.
Use symbol lookup when the target is unclear
A normal search may already find the one incident timeline component. In that case, open it and read its caller.
If there are several similarly named helpers, Serena or your IDE’s symbol navigation can identify a declaration and its references. Verify that the language server resolved the one the page actually uses.
Review the experiment on its own
Read the diff from the experiment directory. The timeline layout should change. The publish action and public data query should stay as they were.
Then open the preview using a long incident update. Are the timestamp and reading order still easy to follow? That's the evidence for keeping the experiment.
The everyday problem
A teammate is reviewing the publish fix. You want to test a shorter incident timeline without mixing the new layout into their review. You also have IncidentTimeline, TimelineForIncident, and tests with similar names. Searching by text finds all of them, but it doesn’t immediately tell you which one the public page renders.
Use Git to separate the experiment from the review, then decide whether language-aware navigation makes it easier to find the correct symbol.
Why the agent got it wrong
An agent edits files in its current checkout. Two sessions started in the same folder can both touch the same code, even when you intended different tasks. A Git worktree gives a branch another working directory and index. The two checkouts still share the repository’s history and objects.
A symbol is a named part of code, such as a function or component. Text search finds matching characters. Language-aware lookup can connect a declaration to references based on how the project imports it. The distinction matters when names repeat.
The tool and technique
Before adding a worktree, read git status and decide which committed revision the experiment should start from. Create a new branch and a sibling directory, then use git worktree list to check the mapping. Tell the agent to work only in the experiment folder and to leave publish logic alone.
Use plain search for IncidentTimeline first. If it points to several candidates and references are unclear, try Serena’s find_symbol and reference navigation with the project’s language server. Recover from a poor lookup by checking server indexing and reading the actual import and caller.
Separate the experiment and jump to the right symbol
Create another checkout for the timeline experiment. Superpowers includes a worktree procedure if you want the agent to follow a written checklist. In a larger TypeScript project, Serena uses language-aware navigation to locate declarations and references, so the agent can follow the component to its caller without reading whole directories.
git worktree add -b experiment/incident-timeline ../status-timeline HEAD git worktree list Use Serena’s find_symbol to locate IncidentTimeline. Then find the references to it in the incident detail screen. List the callers before changing the component.
Confirm the folder and branch before editing. A worktree shares Git repository state, and loaded environment credentials can still point at shared services. When plain search already finds the component and its caller, keep the simpler setup.
On screen in the status app
The before example creates edits in the checkout under review. The after example creates experiment/timeline-layout from HEAD and moves the session to that folder. The related publish diff stays in its own branch. Start the dev preview with the fixture settings for the experiment checkout.
Ask for the declaration used by the incident detail route and the caller that imports it. Change just that component’s date-and-status layout. Review the resulting diff. It should contain the timeline changes, and include no changes to the server action or public query.
Terminal · from the status app checkout
Before
Ask a second agent to refactor the timeline from the same working directory as the reviewed publish patch.
After
git status --short --branch git worktree add -b experiment/timeline-layout ../status-timeline HEAD git worktree list cd ../status-timeline git status --short --branch # Open the incident route’s actual timeline component and limit edits to layout.
What to watch for
A worktree separates checked-out files. It shares repository state and it can read the same external services and credentials if both sessions use the same environment. Give the experiment a disposable dataset and check the actual project URL before running anything that writes data.
Semantic indexing has setup and language support costs. Try Serena when basic search repeatedly leaves you reading the wrong files. For a small project with one obvious caller, ordinary search is easier to verify. Review any automated symbol edit in the diff before it becomes part of the experiment.
How you know it worked
From each folder, run git status --short --branch. Compare their active branches and verify the review branch’s files are unchanged by the layout experiment. From the experiment, review its diff and open the same incident at phone and desktop widths.
Keep the experiment if it improves how quickly people notice the timeline’s latest update. If a refactor touches the publish boundary or introduces another fetch, inspect why before bringing it into the main review. You now have an isolated place for the interface changes in Module 3.