[BUG] byte index 135 is not a char boundary; it is inside '释' (bytes 133..136)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Writing Chinese content causes Claude code to crash.
thread '<unnamed>' (4654) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 135 is not a char boundary; it is inside '释' (bytes 133..136) of 解的概念。相反,"是建设社会主义的锐利武器"作为概念依存元素,其完整意义依赖于对"总路线"的阐释——
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
What Should Happen?
Writing Chinese content causes Claude code to crash.
Error Messages/Logs
thread '<unnamed>' (4654) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 135 is not a char boundary; it is inside '释' (bytes 133..136) of `解的概念。相反,"是建设社会主义的锐利武器"作为概念依存元素,其完整意义依赖于对"总路线"的阐释——`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
Steps to Reproduce
Claude Code Read Tool - Offset Parameter Bug Report
Test Date: 2025-12-17
Test Environment: Claude Code CLI on WSL2 (Linux 6.6.87.2)
Test File: test_unicode.txt (10 lines of Chinese content)
---
Executive Summary
The offset parameter of Claude Code's Read tool exhibits multiple bugs when processing Unicode (Chinese) text files. The issues include incorrect content retrieval, inconsistent line number formatting, and 0-indexed behavior contrary to documentation.
---
Test Configuration
Test File Structure
| Line | Content | Chars | Bytes |
|:----:|:--------|------:|------:|
| 1 | 第一行:这是中文测试内容 | 12 | 36 |
| 2 | 第二行:汉字Unicode编码测试 | 17 | 37 |
| 3 | 第三行:中英混合 English mixed 测试 | 25 | 45 |
| 4 | 第四行:特殊字符测试——破折号、引号""、符号※ | 24 | 68 |
| 5 | 第五行:多字节字符:𠀀𠀁𠀂(CJK扩展B区) | 22 | 61 |
| 6-10 | (additional Chinese text lines) | - | - |
Total: 177 characters, 448 bytes (byte/char ratio: 2.53)
---
Test Results
Test Case Matrix
| Test ID | offset | limit | Expected Line | Actual Line# | Actual Content | Prefix Format | Status |
|:-------:|:------:|:-----:|:-------------:|:------------:|:---------------|:--------------|:------:|
| T1 | 0 | 1 | Line 1 | 0 | 第一行 | 0→ | ⚠️ |
| T2 | 1 | 1 | Line 2 | 1 | 第一行 | 1→ | ❌ |
| T3 | 2 | 1 | Line 3 | 2 | 第二行 | 2→ | ⚠️ |
| T4 | 3 | 2 | Lines 4-5 | 3-4 | 第三行、第四行 | Normal | ⚠️ |
| T5 | 5 | 1 | Line 6 | 5 | 第五行 | Normal | ⚠️ |
| T6 | 10 | 1 | Line 11 | 10 | 第十行 | 10→ | ⚠️ |
---
Identified Bugs
Bug #1: Incorrect Content at offset=1 (Critical)
Description: Both offset=0 and offset=1 return the same content ("第一行"), indicating the skip logic fails at offset=1.
Expected Behavior:
offset=0→ Line 1 contentoffset=1→ Line 2 content
Actual Behavior:
offset=0→ Line 1 content ✓offset=1→ Line 1 content ✗ (should be Line 2)
Severity: Critical - breaks basic pagination functionality
---
Bug #2: Inconsistent Line Number Prefix Formatting
Description: The line number prefix format varies unexpectedly based on offset value.
Expected Format: N→ (5 spaces + line number + arrow)
Observed Anomalies:
| offset | Prefix | Issue |
|:------:|:-------|:------|
| 0 | 0→ | Normal formatting |
| 1 | 1→ | Missing leading spaces |
| 2 | 2→ | Normal formatting |
| 10 | 10→ | Missing leading spaces |
Severity: Medium - affects readability and parsing
---
Bug #3: Zero-Indexed Line Numbers
Description: Line numbers start from 0 instead of 1.
Documentation States: "Results are returned using cat -n format, with line numbers starting at 1"
Actual Behavior: offset=0 displays line number as 0, not 1
Severity: Low - inconsistent with documentation
---
Bug #4: Semantic Confusion in Offset Behavior
Description: The offset parameter behavior is inconsistent and undocumented for Unicode content.
Observations:
- offset appears to be 0-indexed
- Content mapping: offset N → Line N (not Line N+1)
- But offset=1 breaks this pattern
Potential Root Cause: The offset calculation may be mixing byte-based and line-based indexing, causing issues with multi-byte UTF-8 characters.
---
Technical Analysis
UTF-8 Encoding Impact
Chinese characters are encoded as 3 bytes in UTF-8:
| Character | Unicode | UTF-8 Bytes |
|:---------:|:-------:|:------------|
| 第 | U+7B2C | E7 AC AC |
| 一 | U+4E00 | E4 B8 80 |
| 行 | U+884C | E8 A1 8C |
If the offset parameter internally uses byte counting instead of line counting, a byte-based skip could land in the middle of a multi-byte character, causing:
- UTF-8 decoding errors
- Incorrect line boundary detection
- Content corruption
Hypothesis
The Read tool's offset implementation likely:
- Uses 0-based indexing internally
- Has an off-by-one error at offset=1
- May have byte vs. line counting confusion for CJK content
---
Reproduction Steps
# Step 1: Create test file with Chinese content
cat > test_unicode.txt << 'EOF'
第一行:这是中文测试内容
第二行:汉字Unicode编码测试
第三行:中英混合 English mixed 测试
EOF
# Step 2: Test with Claude Code Read tool
# Execute in Claude Code CLI:
Read test_unicode.txt offset=0 limit=1
Read test_unicode.txt offset=1 limit=1
Read test_unicode.txt offset=2 limit=1
# Step 3: Compare results
# offset=0 and offset=1 should return different lines
# but both return "第一行" (Bug confirmed)
---
Impact Assessment
| Use Case | Impact Level | Description |
|:---------|:------------:|:------------|
| Large file pagination | High | Cannot reliably skip to specific lines |
| Incremental file reading | High | Content may be duplicated or skipped |
| Academic document editing | Medium | Affects thesis/paper editing workflows |
| Log file analysis | Medium | Line-based navigation unreliable |
---
Recommendations
For Users (Workaround)
- Avoid using
offset=1; useoffset=0oroffset=2+ - Read entire file when possible, then process locally
- Use
Bashtool withsedorawkfor reliable line extraction
For Developers (Fix Suggestions)
- Audit offset calculation logic for Unicode handling
- Ensure line-based (not byte-based) indexing
- Fix off-by-one error at offset=1
- Standardize line number display format
- Update documentation to clarify 0-indexed vs 1-indexed behavior
---
Appendix: Raw Test Output
Test T1: offset=0, limit=1
0→第一行:这是中文测试内容
Test T2: offset=1, limit=1
1→第一行:这是中文测试内容
Test T3: offset=2, limit=1
2→第二行:汉字Unicode编码测试
Test T6: offset=10, limit=1
10→第十行:最后一行测试结束
---
Report Generated: 2025-12-17
Reporter: Automated Test Script
Status: Awaiting Developer Review
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Claude Code v2.0.71
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Windows Terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗