Overview
The --fix flag enables auto-fix mode, where Warden applies suggested fixes from findings automatically.
warden --fix [targets...] [options]
How It Works
Run analysis
Warden analyzes your code and identifies issues with suggested fixes.
Review fixes
In interactive mode (default), you review each fix: π§ Apply fix for src/api/users.ts:45?
Missing error handling in async function
- const user = await db.users.findOne({ id });
+ const user = await db.users.findOne({ id }).catch(err => {
+ console.error('Failed to fetch user:', err);
+ throw err;
+ });
Apply this fix? (y/n/q)
Apply patches
Warden applies unified diff patches to your files.
Verify changes
Review applied changes with git diff.
Options
βyes, -y
Auto-apply all fixes without confirmation:
This applies all fixes automatically. Review changes afterward with git diff.
βno, -n
Dry run - show what would be fixed without applying:
βmax-findings
Limit number of fixes to apply:
warden --fix --max-findings 5
Interactive Mode
By default, --fix runs interactively:
Prompts
For each fixable finding:
π§ Apply fix for src/api/users.ts:45?
Missing error handling in async function
--- src/api/users.ts
+++ src/api/users.ts
@@ -42,7 +42,10 @@
async function getUser(id: string) {
- const user = await db.users.findOne({ id });
+ const user = await db.users.findOne({ id }).catch(err => {
+ console.error('Failed to fetch user:', err);
+ throw err;
+ });
return user;
}
Apply this fix? (y/n/q)
Responses
y (yes): Apply this fix
n (no): Skip this fix
q (quit): Exit without applying more fixes
Examples
Interactive fix mode
$ npx warden --fix
β‘ Warden v0.18.0
π Running 2 skills on 5 files...
β code-quality: 3 findings (2 fixable )
π§ Found 2 fixable findings
π§ Apply fix for src/api/users.ts:45?
Missing error handling
--- src/api/users.ts
+++ src/api/users.ts
@@ -42,3 +42,5 @@
- const user = await db.users.findOne ({ id });
+ const user = await db.users.findOne ({ id }).catch(err => {
+ throw new Error ( ` User not found: ${ err . message }` );
+ } );
Apply this fix? (y/n/q) y
β Applied fix to src/api/users.ts
π§ Apply fix for src/utils/jwt.ts:89?
Weak signature algorithm
--- src/utils/jwt.ts
+++ src/utils/jwt.ts
@@ -86,2 +86,2 @@
- algorithm: 'HS256',
+ algorithm: 'RS256',
Apply this fix? (y/n/q) y
β Applied fix to src/utils/jwt.ts
β Applied 2 fixes
Auto-apply all fixes
$ npx warden --fix --yes
β‘ Warden v0.18.0
π Running 2 skills on 5 files...
β code-quality: 3 findings (2 fixable )
π§ Applying 2 fixes...
β Applied fix to src/api/users.ts
β Applied fix to src/utils/jwt.ts
β Applied 2 fixes
Review changes with:
git diff
Fix specific files
npx warden --fix src/api/
Dry run
$ npx warden --fix --no
π§ Found 2 fixable findings (dry run )
src/api/users.ts:45 - Missing error handling [medium]
src/utils/jwt.ts:89 - Weak signature algorithm [high]
Run 'warden --fix' to apply these fixes
Fixes use unified diff format:
--- src/api/users.ts
+++ src/api/users.ts
@@ -42,3 +42,5 @@
async function getUser(id: string) {
- const user = await db.users.findOne({ id });
+ const user = await db.users.findOne({ id }).catch(err => {
+ throw new Error(`User not found: ${err.message}`);
+ });
return user;
}
Lines starting with - are removed
Lines starting with + are added
Context lines show surrounding code
Verification
After applying fixes:
Review changes
Test your code
Commit changes
git add -A
git commit -m "fix: apply Warden suggestions"
Error Handling
Patch application failures
If a patch fails to apply:
β Failed to apply fix to src/api/users.ts:
Patch does not match current file contents
Causes:
File was modified since analysis
Conflicting changes in the same area
File encoding issues
Solution:
Run analysis again: npx warden --fix
Manually apply the fix
Skip the fix and continue
No fixable findings
Not all findings have suggested fixes. Skills must explicitly provide fix diffs.
Review fixes before committing
Always review with git diff before committing: npx warden --fix
git diff
npm test
git commit -am "fix: apply Warden suggestions"
Apply fixes incrementally
Fix high-severity issues first: # Fix high severity only
npx warden --fix --fail-on high
# Then fix medium
npx warden --fix --fail-on medium
Fix specific areas: # Fix only API files
npx warden --fix src/api/
# Fix specific file
npx warden --fix src/api/users.ts
Auto-fixing in CI requires careful consideration: # Create fix PR automatically
- name : Apply fixes
run : npx warden --fix --yes
if : github.event_name == 'schedule'
- name : Create PR
run : |
git checkout -b warden-fixes-$(date +%s)
git commit -am "fix: apply Warden suggestions"
gh pr create --title "Warden fixes" --body "Auto-generated fixes"
Limitations
Not all findings are fixable
Skills must explicitly provide fix diffs. Some issues require human judgment:
Architectural changes
Logic errors
Complex refactorings
Fixes may conflict
Multiple fixes to the same area may conflict. Review carefully.
Test after fixing
Auto-fixes donβt guarantee correctness. Always test:
npx warden --fix --yes
npm test
Main command Analyze without fixing
Findings Understanding finding structure
Creating skills Add suggested fixes to your skills
Output formats JSONL format includes fix diffs