claude-code - 💡(How to fix) Fix [BUG] Edit tool settings. json validator fails with "Unterminated string" when old string spans a line with backslash sequences [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56467Fetched 2026-05-06 06:27:16
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

Error Message

Invalid JSON: JSON Parse error: Unterminated string

Fix Action

Fix / Workaround

Workaround Target a line that doesn't contain backslashes in old_string:

old_string: "Bash(git *)"
new_string: "Bash(git *)",\n    "Bash(jq *)"

Code Example

Invalid JSON: JSON Parse error: Unterminated string

---

{
    "permissions": {
        "allow": [
            "Bash(grep -E '\\.md$')",
            "Bash(git *)"
        ]
    }
}

---

old_string: "Bash(grep -E '\\.md$')",\n    "Bash(git *)"
new_string: "Bash(grep -E '\\.md$')",\n    "Bash(git *)",\n    "Bash(jq *)"

---

old_string: "Bash(git *)"
new_string: "Bash(git *)",\n    "Bash(jq *)"
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When using the Edit tool to modify ~/.claude/settings.json, the post-edit validator throws Invalid JSON: JSON Parse error: Unterminated string if old_string spans a line containing a permission rule with backslash sequences. The file on disk is valid JSON - the validator accepted it when originally written. The error fires before any write occurs, so the file is never actually corrupted.

What Should Happen?

Expected behavior Edit succeeds; Bash(jq *) is added to the allow list.

Error Messages/Logs

Invalid JSON: JSON Parse error: Unterminated string

Steps to Reproduce

  1. Add "Bash(grep -E '\\.md$')" to permissions.allow in ~/claude/settings.json:
{
    "permissions": {
        "allow": [
            "Bash(grep -E '\\.md$')",
            "Bash(git *)"
        ]
    }
}
  1. Use the Edit tool with an old_string that includes that line:
old_string: "Bash(grep -E '\\.md$')",\n    "Bash(git *)"
new_string: "Bash(grep -E '\\.md$')",\n    "Bash(git *)",\n    "Bash(jq *)"
  1. Observe: Invalid JSON: JSON Parse error: Unterminated string

Workaround Target a line that doesn't contain backslashes in old_string:

old_string: "Bash(git *)"
new_string: "Bash(git *)",\n    "Bash(jq *)"

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.128

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

No response

extent analysis

TL;DR

The issue can be worked around by targeting a line in old_string that doesn't contain backslashes when using the Edit tool to modify ~/.claude/settings.json.

Guidance

  • The error Invalid JSON: JSON Parse error: Unterminated string suggests that the JSON parser is having trouble with backslash sequences in the old_string.
  • To verify the issue, try modifying the old_string to exclude lines with backslash sequences, as shown in the provided workaround.
  • When using the Edit tool, ensure that the old_string does not span a line containing a permission rule with backslash sequences to avoid the JSON parse error.
  • Consider modifying the Edit tool to properly handle backslash sequences in the old_string to prevent this issue.

Example

No code snippet is provided as the issue is more related to the usage of the Edit tool and its interaction with the JSON file.

Notes

The provided workaround suggests that targeting a line without backslashes in old_string resolves the issue, but a more permanent fix might involve modifying the Edit tool to handle backslash sequences correctly.

Recommendation

Apply workaround: Target a line that doesn't contain backslashes in old_string when using the Edit tool, as this has been shown to resolve the issue in the provided example.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Edit tool settings. json validator fails with "Unterminated string" when old string spans a line with backslash sequences [1 participants]