If you’re using Claude Code for iOS development, you’ve probably noticed an annoying habit: it consistently adds trailing whitespace to your code. Those pesky spaces at the end of lines trigger SwiftLint warnings and clutter your git diffs.
The Problem Won’t Be Fixed
Unfortunately, this is a known issue that Anthropic won’t fix. The trailing whitespace problem has been reported multiple times, but it seems to be a fundamental behavior of how Claude generates code. Rather than waiting for an official fix, we need to work around it.
The Solution: Claude Hooks
Thankfully, there’s an elegant solution using Claude Code’s hooks feature. This excellent post introduced me to using PostToolUse hooks to automatically clean up after Claude.
Here’s my essential setup for Swift projects.
Add this to your .claude/settings.json
:
{
"hooks": {
"PostToolUse": [
{
"matcher": "^(Edit|MultiEdit|Write)$",
"hooks": [
{
"type": "command",
"command": "swiftlint --config .swiftlint.yml --fix"
}
]
}
]
}
}
Now, every time Claude edits a Swift file, SwiftLint automatically runs and fixes EVERY RULE.
This simple hook has saved me countless minutes of cleanup work, or thousand of tokens as Claude wasted time and tokens fixing code styling.
This deserves to be the 11th tip.