Google measured its coding agents reading stale TODO comments. In 6% of encounters the agent acted on the comment, 83% of those times without being asked, and those sessions used 70% more steps and 77% more tokens. The same thing happens in an iOS repo. Find TODOs that point at closed GitHub issues, find workarounds for iOS versions below your deployment target, sort the rest by age with git blame, delete or rewrite them in their own pull request, and add a few lines to CLAUDE.md or AGENTS.md that tell the agent TODOs are background, not tasks.
On November 6, two Google engineers, Sam Saccone and Madhuri Garikapati, published a post on the Google Developers Blog about something they call agent distraction. Coding agents read old comments in the code, treat them as instructions, and wander off to work on things nobody asked for. InfoQ picked it up on November 10, and it went around developer feeds this week because almost every team has a few hundred stale TODOs that suddenly cost money.
The post is about Google's own monorepo, but the mechanism has nothing to do with Google's scale. If you build an iOS app with Claude Code, Cursor, Codex or any other agent, the agent reads your Swift files the same way. Every // TODO: remove once we drop iOS 15 and every // FIXME: see #212 is text the agent has to decide about. This article covers what Google measured, why iOS repos are especially full of this kind of debris, and a set of scripts and rules you can apply this afternoon to clean it up and keep it from coming back.
What Google measured
Google needed a signal it could count, so it picked inline bug references: comments of the form TODO(bug/...) and FIXME(bug/...). These are useful to study because the linked bug ticket records whether the work is done. The comment stays in the code; the ticket gets closed. Comparing the two shows how often an agent reads an instruction that is already obsolete.
The data came from distributed traces of thousands of engineers, covering hundreds of millions of agent steps. To separate the effect of the comments from everything else, the authors used a multi-way fixed-effects regression with developer-clustered standard errors, controlling for the developer, codebase complexity, task type, model tier, number of files read, initial prompt length and the step at which the bug reference appeared. The post does not say which models were involved.
The findings, as reported in Google's post:
- 13% of file-reading sessions exposed the agent to at least one
TODO(bug/...)orFIXME(bug/...)reference. - In 94% of those encounters the agent ignored the comment. In 6% it took some action aimed at that bug.
- 83% of the sessions where the agent acted on the bug were unprompted. The developer had not asked about it.
- Of the unprompted detours, 41% went after bugs that were already closed: 32% were fixed or verified, 9% were obsolete or won't-fix, and 2% were duplicate or restricted tickets.
- Over half of the unprompted detours targeted bugs that were still open. In those cases the agent widened its own scope: 61% only looked the bug up, and 39% edited code.
- Sessions with unprompted bug detours used 70% more steps, 77% more tokens and 105% more wait time than comparable sessions. All three results were reported at p<0.0001.
Two case studies make it concrete. In one, an agent doing an unrelated investigation found a TODO in SurfaceControlTest.java pointing at a bug fixed in 2023, and spent several steps investigating it anyway. In the other, an agent found a TODO while working on a different bug and changed ModelDownloaderV1 code without being asked. The developer pushed back, and the agent agreed the change was out of scope.
Read the 6% figure carefully. Most of the time agents do ignore stale comments. The cost comes from the minority of sessions where they don't, because those sessions get much longer and much more expensive, and sometimes they ship an edit you didn't want inside a pull request about something else.
What Google did about it
Google built agents that scan the codebase for bug references whose tickets are marked fixed or obsolete. A status check alone was not enough to delete a comment, so the cleaners also read the bug history, the file history and related code changes, sometimes going back years, and only proposed removal when the TODO's intent was clearly obsolete. Over six months this "todo cleaner" removed thousands of obsolete references, and human reviewers accepted more than 95% of its proposals.
The recommendations at the end of the post are short: use presubmit analyzers, whole-codebase scanners and coding agents to find and fix dead TODOs; take another look at cleanup projects that were shelved as low value; and stop thinking of an "agent-friendly codebase" as one where only the hot path is healthy, because neglected corners of the repo now cost agents real time and tokens.
Why iOS repos collect this kind of debris
An iOS codebase ages in a specific way. Apple ships a new OS every September, and most teams raise their deployment target a year or two later. In between, the code fills up with workarounds: availability checks for APIs that weren't there yet, notes saying "remove when we drop iOS 15", FIXMEs about a UIKit bug that Apple fixed two releases ago. When the deployment target finally moves, nobody goes back for the comments.
A few other sources are common in app repos:
- TODOs that reference GitHub issues (
#212), Jira keys or Linear IDs, where the issue was closed in a different pull request. - Notes left by a previous coding agent session. AI tools write TODOs freely when they stub out a function, and those stubs often get filled in later without the comment being removed.
- Commented-out blocks of an old implementation "in case we need it", which an agent can mistake for the intended design.
#warningdirectives and// MARK: - Deprecatedsections that no longer match the code under them.- Third-party code copied into the repo with its own TODOs, which your agent may try to "finish".
For an app built mostly with AI tools, the problem compounds. The code was written fast, the TODO density is often high, and the person maintaining it may not know which notes still matter. Every new agent session then reads the same stale notes again. AI Coding Costs: Why Your Agent Bill Is Mostly Re-Reading explains where those repeated reads show up on the bill.
Step 1: Count what you have
Start with a plain inventory. From the root of your repo, this counts TODO and FIXME comments in your own source, skipping dependencies and build output:
grep -rnE --include='*.swift' --include='*.m' --include='*.h' \
'\b(TODO|FIXME)\b' . \
--exclude-dir=Pods --exclude-dir=.build --exclude-dir=DerivedData \
--exclude-dir=Carthage | wc -l
Drop the | wc -l to see the lines themselves. If the number is in the hundreds, don't try to clean everything by hand. The next two scripts split the list into groups you can act on quickly: comments tied to tickets, and comments tied to old iOS versions.
Step 2: Find TODOs that point at closed GitHub issues
This is the closest match to what Google measured. The script below finds TODO and FIXME comments that mention a GitHub issue number, asks the GitHub CLI for each issue's state, and prints the results sorted so closed issues group together. It uses gh issue view with the state, stateReason and closedAt JSON fields, which are part of the documented field list.
#!/usr/bin/env bash
# stale-todos.sh: list TODO/FIXME comments that point at GitHub issues,
# and print each issue's state so you can spot the ones already closed.
# Usage: ./stale-todos.sh [path] (run inside a clone with gh signed in)
set -euo pipefail
ROOT="${1:-.}"
grep -rnE --include='*.swift' --include='*.m' --include='*.h' \
--include='*.mm' --include='*.kt' --include='*.ts' --include='*.tsx' \
'(TODO|FIXME)[^#]*#[0-9]+' "$ROOT" \
--exclude-dir=Pods --exclude-dir=.build --exclude-dir=DerivedData \
--exclude-dir=node_modules --exclude-dir=Carthage |
while IFS= read -r hit; do
num=$(printf '%s' "$hit" | grep -oE '#[0-9]+' | head -1 | tr -d '#')
info=$(gh issue view "$num" --json state,stateReason,closedAt \
--jq '[.state, (.stateReason // "-"), (.closedAt // "-")] | join(" ")' \
2>/dev/null || echo "UNKNOWN - -")
printf '%s\t#%s\t%s\n' "$info" "$num" "$hit"
done | sort
Output looks like this:
CLOSED COMPLETED 2025-03-02T10:00:00Z #12 Sources/Feed.swift:1:// TODO(#12): retry when the token refresh race is fixed
OPEN - - #40 Sources/Feed.swift:2:// FIXME: crash on empty feed, see #40
I tested the script on Linux against a small fake repo with a stubbed gh, so try it on a branch first and expect to adjust the patterns. It only looks at the first issue number on each line, it assumes the number refers to the current repository, and it will mark pull request numbers as UNKNOWN. If your team uses Jira or Linear keys instead, swap the regex for your key format (for example [A-Z]+-[0-9]+) and replace the gh call with your tracker's CLI or API.
Pay attention to stateReason. A COMPLETED issue usually means the work landed and the comment can go. NOT_PLANNED means someone decided not to do it, so the comment is misleading in a different way: it tells the agent there is still work to do when the team already decided there isn't. Both are the kind of closed ticket that made up 41% of Google's unprompted detours.
Step 3: Find workarounds for iOS versions you no longer support
The second group is tied to OS versions. This script reads the lowest IPHONEOS_DEPLOYMENT_TARGET from your project file, then lists availability checks and TODO or FIXME comments that mention an iOS version at or below it:
#!/usr/bin/env bash
# old-os-todos.sh: find availability checks and TODOs for iOS versions
# below your deployment target. Usage: ./old-os-todos.sh path/to/App.xcodeproj
set -euo pipefail
PROJ="$1"
TARGET=$(grep -oE 'IPHONEOS_DEPLOYMENT_TARGET = [0-9]+' "$PROJ/project.pbxproj" \
| grep -oE '[0-9]+$' | sort -n | head -1)
echo "Lowest deployment target in project: iOS $TARGET"
ROOT=$(dirname "$PROJ")
grep -rnE --include='*.swift' \
'#available\(iOS [0-9]+|TODO.*iOS ?[0-9]+|FIXME.*iOS ?[0-9]+' "$ROOT" \
--exclude-dir=Pods --exclude-dir=.build |
while IFS= read -r hit; do
v=$(printf '%s' "$hit" | grep -oE 'iOS ?[0-9]+' | head -1 | grep -oE '[0-9]+')
if [ "$v" -le "$TARGET" ]; then printf 'iOS %s <= %s\t%s\n' "$v" "$TARGET" "$hit"; fi
done
On the test project, with a target of iOS 16, it flagged a "remove this workaround once we drop iOS 15" comment and an if #available(iOS 16, *) check that is now always true. It ignored a check for iOS 18, which still matters.
The script uses the lowest target in the project file on purpose. If you have an app extension or a widget with an older target than the main app, a check that looks dead in the app may still be needed there. It also only compares the major version number, so a check for iOS 16.4 on a 16.0 target will show up as a false positive. Treat the output as a list to review, and let the compiler confirm: once a branch is dead, removing the #available check and its fallback code should build cleanly for every target.
Sort the rest by age
Steps 2 and 3 catch comments that carry a ticket number or an iOS version. Most TODOs carry neither. For those, the best cheap signal is age: a note that nobody has touched in two years is done, abandoned or forgotten, and all three are worth a look. This script prints every TODO and FIXME with the date its line was last changed, oldest first.
#!/usr/bin/env bash
# todo-age.sh: list TODO/FIXME comments with the date each line was last
# changed, oldest first. Usage: ./todo-age.sh [path] (run inside a Git repo)
set -euo pipefail
ROOT="${1:-.}"
grep -rnE --include='*.swift' --include='*.m' --include='*.h' --include='*.mm' \
'\b(TODO|FIXME)\b' "$ROOT" \
--exclude-dir=Pods --exclude-dir=.build --exclude-dir=DerivedData \
--exclude-dir=Carthage |
while IFS=: read -r file line text; do
sha=$(git blame -w -L "$line,$line" --porcelain -- "$file" 2>/dev/null \
| head -1 | cut -d' ' -f1 || true)
case "$sha" in
''|0000000*) when="uncommitted" ;;
*) when=$(git log -1 --format=%as "$sha") ;;
esac
text=$(printf '%s' "$text" | sed 's/^[[:space:]]*//')
printf '%s\t%s:%s\t%s\n' "$when" "$file" "$line" "$text"
done | sort
It was run on a Mac against a sample repo with three backdated commits and one unsaved edit, and printed:
2024-03-10 Sources/Feed.swift:1 // TODO(#12): retry when the token refresh race is fixed
2024-03-10 Sources/Feed.swift:4 // TODO: remove this workaround once we drop iOS 15
2025-09-22 Sources/Feed.swift:2 // FIXME: crash on empty feed, see #40
2026-11-01 Sources/Feed.swift:5 // TODO: tidy up naming
uncommitted Sources/Feed.swift:7 // FIXME: not committed yet
The -w flag on git blame matters more than it looks. In the sample, the third commit only re-indented the iOS 15 comment. Without -w the script dated that line 2026-11-01, which would have hidden a comment from March 2024 among the new ones. With it, the line keeps its real date. A formatter that rewraps lines, or an edit to the comment's wording, still resets the date, so if every TODO in a file shows the same recent day, look at that commit before you trust it.
Work down from the top and stop when the dates reach the last few months. Recent TODOs usually belong to work in progress, and their authors still remember what they meant.
Find the debris that has no marker at all
Two items from the list of sources above never contain the word TODO: commented-out code, and #warning or deprecated MARK lines. This pattern finds comment lines that start with a Swift keyword and look like a statement:
grep -rnE --include='*.swift' \
'^[[:space:]]*//[[:space:]]*(let|var|func|if|guard|for|while|switch|return|import|class|struct|enum)[[:space:]]+[A-Za-z_.(]+.*[={(]' . \
--exclude-dir=Pods --exclude-dir=.build --exclude-dir=DerivedData
On a sample file it listed four commented-out lines, a let, an if, a guard and a func. It left alone a doc comment, a prose comment that began with the word "return", and the live code. It is a rough filter. It misses commented-out lines that start with a call, such as // cache.clear(), and it can flag a sentence that begins with "if" and contains a bracket. For the directives, a plain search is enough, and it found both in the same sample:
grep -rnE --include='*.swift' '#warning|MARK:.*Deprecated' . --exclude-dir=Pods
That gives one check for each kind of stale text this article has named. None of them is complete, so the last column matters as much as the middle one.
| Kind of stale text | What finds it | What it misses |
|---|---|---|
| TODO or FIXME with a GitHub issue number | stale-todos.sh, Step 2 | Jira or Linear keys until you change the pattern. Pull request numbers show as UNKNOWN. |
| Workaround for an old iOS version | old-os-todos.sh, Step 3 | Minor versions, and checks for macOS or watchOS. |
| TODO with no ticket and no version | todo-age.sh | Old notes whose wording was edited recently. |
| Commented-out code | The keyword pattern above | Lines that start with a call. |
#warning and deprecated MARK sections | The plain search above | Whether the code under the mark is really dead. |
| Notes left by an earlier agent session | todo-age.sh, near the bottom of the list | Who wrote them. They look like any other recent TODO. |
| TODOs inside vendored code | Nothing, on purpose. Every script skips Pods, Carthage and build folders. | Third-party code copied into your own source folders. |
Running the scripts on a stock Mac
Step 2 notes that its script was tested on Linux, and macOS ships different tools: BSD grep in place of GNU grep, and bash 3.2. So the command from Step 1, the scripts from Steps 2 and 3 and the age script above were also run on macOS 26.0.1 with only what the system provides, BSD grep 2.6.0 and bash 3.2.57, against a small sample repo and a stubbed gh. All of them ran without changes and gave the results the steps describe. You do not need Homebrew versions of grep or bash to use them. The age script calls git log --format=%as, which needs Git 2.21 or newer. Apple's Git on the test Mac was 2.50.1.
Step 4: Decide what each comment should become
Google's cleaners did not delete a TODO just because its ticket was closed. They checked the history first. You can do the same in a minute per comment with two Git commands:
# When was this line written, and in which commit?
git blame -L 1,1 Sources/Feed.swift
# Which commits added or removed this exact text anywhere in the repo?
git log -S 'TODO(#12)' --oneline
Then put each comment into one of three buckets:
- Delete: The ticket is closed as completed, the code around the comment already does what the TODO asked, or the iOS version it mentions is below every target. Remove the comment and any dead fallback code in the same commit.
- Rewrite: The note still matters, but it doesn't say enough. "TODO: fix this" tells an agent nothing about whether it should act. Something like
// Known limitation: pagination resets on rotation. Tracked in #88, not in scope for feature work.gives the agent and the next human a reason to leave it alone. - Move to the tracker: If the TODO describes real work that nobody has written up, open an issue and replace the comment with a one-line reference, or delete the comment and keep the issue. A ticket can be prioritized; a comment just sits in the code waiting to be read.
Commented-out code goes in the first bucket almost every time. Git already keeps the old implementation, and git log -S finds it again in seconds if you ever need it.
Make the cleanup its own pull request. Mixing it into feature work makes review harder, and it repeats the exact scope creep Google described, only done by a human this time.
Step 5: Tell your agent how to treat TODOs
Cleanup reduces the number of stale notes. Instructions change how the agent reacts to the ones that remain, including the new ones that will appear next month. Claude Code loads CLAUDE.md files by walking up from the working directory, and it also picks up rules from .claude/rules/. A few lines in the project CLAUDE.md cover most of it:
## TODO and FIXME comments
- TODO, FIXME and #warning comments are background, not tasks.
- Do not act on them unless my request names that comment, file or issue.
- If one looks related to the current task, mention it in your summary
and ask before changing code for it.
- Never widen a change to fix an issue referenced in a comment.
Anthropic's memory documentation recommends keeping each CLAUDE.md under 200 lines, writing instructions specifically enough to verify, and avoiding rules that contradict each other, because Claude may pick one of two conflicting rules arbitrarily. If your file already says "fix any TODOs you see", delete that line before adding the ones above. Shrink and Fix Your Claude Code Memory in an iOS Repo walks through trimming that file.
Cursor, Codex and other agents have their own rule files (AGENTS.md is common), and the same four lines work there. None of this is a guarantee. Instructions change what the agent tends to do; they don't stop it from reading the comment. That's why the cleanup in Steps 2 to 4 comes first.
Step 6: Keep stale TODOs from coming back
If you already use SwiftLint, its todo rule is on by default. It flags TODO and FIXME markers in comments as warnings, and you can change the severity or the list of markers it checks with the severity and only options. Many teams have this rule disabled because the warnings became noise. After a cleanup, turning it back on makes sense, since the count is small enough to read again.
A stricter option is to allow TODOs only when they carry a ticket reference, so the Step 2 script can always check them. In .swiftlint.yml:
disabled_rules:
- todo
custom_rules:
todo_needs_issue:
name: "TODO needs an issue"
regex: '\b(TODO|FIXME)\b(?![^\n]*#[0-9]+)'
match_kinds:
- comment
message: "Add an issue number, for example TODO(#123), or remove the comment."
severity: warning
Run SwiftLint locally on that config before you commit it, because regex rules are easy to get slightly wrong and the exact behavior depends on your SwiftLint version. Start as a warning, then move to an error once the existing ones are fixed.
Finally, schedule the check. A weekly CI job that runs stale-todos.sh and fails, or opens an issue, when any line starts with CLOSED catches the case where someone closes a ticket in one pull request and forgets the comment in another. That is the "whole-corpus scanner" Google recommended, at the size of one app.
Let an agent do the cleanup, with guardrails
Google's own fix was an agent, and you can use yours the same way. The trick is to give it a narrow job and the evidence up front, instead of letting it discover TODOs during feature work. A prompt that works well:
Here is the output of stale-todos.sh and old-os-todos.sh (attached).
For each CLOSED issue and each iOS version at or below our target:
1. Run git blame and git log -S on the line.
2. Read the surrounding code and the issue title.
3. Propose: delete, rewrite (show the new text), or keep (say why).
Do not edit any file yet. Give me a table first.
Review the table, approve the rows you agree with, and let the agent make only those edits on a branch. Then build every target and run your tests. Google's reviewers accepted more than 95% of their cleaner's proposals, but that was a tool tuned over six months on their codebase. A first pass in your repo deserves a full read of the diff.
What the study doesn't tell you
Keep the numbers in context before you quote them to your team. The data is from Google's internal tooling, on Google's codebase, with models the post doesn't name. The 70%, 77% and 105% figures compare sessions with unprompted bug detours against similar sessions without them, after controls. They don't say that your total token bill will drop by 77% if you delete your TODOs. Only 6% of encounters led to action in the first place, so the savings depend on how often your agents hit stale comments during real work.
The study also measured one kind of distraction: bug references. Google's post and InfoQ's write-up both point out that the same problem applies to obsolete specs, outdated docs and dead code, but those were not measured. For an iOS team, the direction is clear even without exact numbers: stale text in the repo is something agents read and occasionally act on, and removing it is cheap.
Put the percentages together
Google's post reports each rate on its own. Multiplying them gives a rough idea of how often a detour happens at all. This is arithmetic on the published figures and not a number Google reported, and it mixes units a little, because the 6% is counted per encounter and the 13% per session. Read it as an order of magnitude.
# Rough share of agent sessions that take an unprompted TODO detour,
# and what that adds to total token use. Rates are from Google's post.
acted = 0.06 # encounters where the agent acted on the comment
unprompted = 0.83 # share of those the developer had not asked for
extra_tokens = 0.77 # extra tokens in a session with a detour
for exposed in (0.13, 0.40, 0.80): # sessions that read a stale reference
detour = exposed * acted * unprompted
print(f"exposed {exposed:.0%}: detour in {detour:.2%} of sessions, "
f"about 1 in {round(1 / detour)}, total tokens +{detour * extra_tokens:.2%}")
Run with Python 3.12, it prints:
exposed 13%: detour in 0.65% of sessions, about 1 in 154, total tokens +0.50%
exposed 40%: detour in 1.99% of sessions, about 1 in 50, total tokens +1.53%
exposed 80%: detour in 3.98% of sessions, about 1 in 25, total tokens +3.07%
At Google's exposure rate, an unprompted detour shows up in roughly one session in 154, and the extra tokens come to about half a percent of the total. That is why the 77% figure should not be read as a saving on your bill. The 40% and 80% rows are examples and not measurements. They show why a small app can feel this more than Google does: if your repo is dense with stale notes and nearly every session reads one, the same rates give a detour in one session out of 25. The exposure rate is the input a cleanup lowers directly, and the rules in Step 5 aim at the 6%.
Tokens are also the smaller part of the cost. In Google's data, 39% of the detours on open bugs edited code, and an unrequested edit inside a pull request costs review time whether or not anyone looks at the token count.
A quick checklist
- Count TODO and FIXME comments in your own source (Step 1).
- Run
stale-todos.shand handle every CLOSED line (Step 2). - Run
old-os-todos.shagainst your project and remove dead availability branches (Step 3). - Check history with
git blameandgit log -Sbefore deleting (Step 4). - Add the four TODO lines to
CLAUDE.mdorAGENTS.md(Step 5). - Turn SwiftLint's
todorule back on or require ticket references, and schedule a weekly scan (Step 6).
FAQ
Do coding agents really act on TODO comments?
Sometimes. In Google's traces, agents ignored TODO and FIXME bug references 94% of the time and acted on them 6% of the time, and most of those actions were not requested by the developer.
How much do stale TODOs cost?
Google found that sessions with unprompted bug detours took 70% more steps, used 77% more tokens and had 105% more wait time than comparable sessions. That is a per-session figure for affected sessions, not a saving across all work.
Should I delete every TODO in my iOS app?
No. Delete the ones whose work is done or whose iOS version you no longer support, rewrite the ones that still matter with a clear reason, and move real work into your issue tracker.
Does a CLAUDE.md rule stop Claude Code from following TODOs?
It makes it less likely, because Claude Code loads those instructions at the start of a session. It doesn't remove the comment from what the agent reads, so cleaning up the stale ones is still the main fix.
Is this only a problem for big codebases like Google's?
The scale differs, but the mechanism is the same in any repo an agent reads. Small apps built quickly with AI tools often have a high density of TODOs left from earlier sessions.
How do I find the oldest TODOs in a repo?
Run git blame -w on each TODO line and sort by the commit date. The todo-age.sh script in this article does that for Swift and Objective-C files and prints the oldest first. Start there when a comment has no ticket number or iOS version to check.
One related tool
Stale TODOs are one kind of old context. Saved handoff notes and task summaries go stale the same way when the files they describe change between sessions. If you move a task between Claude Code, Cursor and Codex, Repo Context & Handoff: Portable Coding Context with Freshness Checks is a local Node.js CLI I sell that packs the files, decisions and constraints for a task into a Markdown, JSON or HTML packet, and before you resume it checks whether those selected files have changed, been deleted or been newly selected. It doesn't scan TODO comments, and its freshness check covers file contents and recorded metadata, not whether the code is correct.
Keep reading on JR Devhub
- 7 GitHub Repos That Shrink Your AI Agent's Token Bill
- Claude Code Ships Faster When “Done” Is a File, Not a Prompt
- The Best Coding Agent Fully Finished 26% of Real Tasks. Write Your Acceptance Criteria Before You Prompt
- GitHub's Spec Kit Is Trending. How to Add It to an Existing iOS App and Keep App Review in the Spec
Sources
- Agent Distraction, Google Developers Blog, Sam Saccone and Madhuri Garikapati, November 6, 2026
- Google Finds that Technical Debt Can Derail Coding Agents Through "Agent Distraction", InfoQ, Sergio De Simone, November 10, 2026
- Dev News Digest: 11 Nov 2026, 06:00, DEV Community
- gh issue view, GitHub CLI manual
- Memory (CLAUDE.md files), Claude Code documentation
- Todo rule, SwiftLint rule directory

Comments