Most AI coding tools face these issues:
- Token limits - Can't send entire codebase
- Irrelevant context - Including unnecessary files wastes tokens
- Missing context - Missing imported files causes errors
When you ask to modify userController.js, XibeCode:
1. Reads userController.js
2. Extracts imports:
- import { User } from './models/User'
- import { auth } from './middleware/auth'
3. Follows imports and reads:
- models/User.js
- middleware/auth.js
4. Finds related files:
- test/userController.test.js (test file)
- package.json (config)
5. Builds complete context automatically
For large files (>1000 lines):
// Instead of reading entire 5000-line file:
read_file({ path: "big-file.js", start_line: 450, end_line: 550 })
// Gets context around line 500
// Saves tokens while maintaining understandingXibeCode tracks token usage:
- Reserves ~100k tokens for context
- Loads files by priority:
- Primary files (explicitly mentioned)
- Imported files
- Test files
- Config files
- Stops at 80% capacity
- Always keeps room for AI responses
# Let AI discover context automatically
xibecode run "Add input validation to userController.js"
# AI will:
# 1. Read userController.js
# 2. Find it imports: User model, auth middleware
# 3. Read those files
# 4. Understand the full picture
# 5. Add validation that matches existing patterns
# Or explicitly request context
xibecode run "Get context for src/api/users.js and tell me how it works"When to use: Small, targeted changes
// Find unique text and replace it
edit_file({
path: "app.js",
search: "const port = 3000;",
replace: "const port = process.env.PORT || 3000;"
})Why it's reliable:
- ✅ Only edits if search text is unique
- ✅ Fails safely if ambiguous
- ✅ Creates automatic backup
- ✅ Shows exact changes in diff
Best practices:
# Good - unique search string
search: "function calculateTotal(items) {\n return items.reduce"
# Bad - too generic
search: "return"When to use: Large files, known line numbers
edit_lines({
path: "large-file.js",
start_line: 100,
end_line: 150,
new_content: "// Entire new implementation"
})Advantages:
- ✅ Works on huge files
- ✅ Precise control
- ✅ Efficient (doesn't load whole file)
When AI uses it:
xibecode run "Fix the bug around line 500 in big-file.js"
# AI will:
# 1. read_file big-file.js lines 450-550
# 2. Identify the bug
# 3. edit_lines 495-505 with fixWhen to use: Adding new code without replacing
insert_at_line({
path: "app.js",
line: 5,
content: "const express = require('express');"
})Use cases:
- Adding imports
- Adding new functions
- Inserting middleware
Every edit creates a backup:
.xibecode_backups/
app.js.1707234567890.backup
app.js.1707234589123.backup
app.js.1707234601456.backup
Revert anytime:
xibecode run "Revert app.js to previous version"
# Or specific backup:
xibecode run "Revert app.js to backup 1" --verboseUser command:
xibecode run "The tests in test/user.test.js are failing. Fix them."What XibeCode does:
// Run tests to see failure
run_command({ command: "npm test test/user.test.js" })
// Output:
// FAIL test/user.test.js
// ✕ should create user (50ms)
// TypeError: Cannot read property 'save' of undefined// Read test file
read_file({ path: "test/user.test.js" })
// Read source code
read_file({ path: "src/controllers/userController.js" })
// Get context (imports, etc.)
get_context({ files: ["src/controllers/userController.js"] })AI analysis:
- Test expects User.save() method
- Controller doesn't call save()
- Missing database interaction
edit_file({
path: "src/controllers/userController.js",
search: "const user = new User(req.body);\n res.json(user);",
replace: "const user = new User(req.body);\n await user.save();\n res.json(user);"
})run_command({ command: "npm test test/user.test.js" })
// Output:
// PASS test/user.test.js
// ✓ should create user (25ms)💬 Assistant:
Fixed the bug in userController.js. The issue was that we were
creating a User instance but not saving it to the database.
Added await user.save() before sending response.
All tests now pass ✓
xibecode run "List all Python files"
# AI knows it's Windows and uses:
run_command({ command: "dir /s /b *.py" })xibecode run "List all Python files"
# AI knows it's Unix and uses:
run_command({ command: "find . -name '*.py'" })XibeCode normalizes paths:
- Windows:
src\controllers\user.js - Unix:
src/controllers/user.js
Both work seamlessly!
// Without loop detection:
Iteration 1: read_file("app.js")
Iteration 2: read_file("app.js") // Same thing again
Iteration 3: read_file("app.js") // Still doing it
Iteration 4: read_file("app.js") // Infinite loop!// XibeCode tracks recent actions:
History: [
{ tool: "read_file", input: "app.js", time: 1000 },
{ tool: "read_file", input: "app.js", time: 1100 },
{ tool: "read_file", input: "app.js", time: 1200 },
]
// After 3 identical calls:
⚠️ Loop detected: read_file called 3+ times with same parameters💬 Assistant receives:
"Error: Loop detected. Try a different approach."
AI adjusts strategy:
Instead of: read_file("app.js") again
Does: edit_file("app.js", ...) to make progress
xibecode run "Add JWT authentication:
1. Install jsonwebtoken and bcrypt
2. Create auth middleware
3. Add /login and /register endpoints
4. Protect existing routes
5. Add tests"Execution:
Iteration 1: run_command("npm install jsonwebtoken bcrypt")
Iteration 2: write_file("middleware/auth.js") # Creates middleware
Iteration 3: read_file("app.js") # Understand current routes
Iteration 4: edit_file("app.js") # Add auth routes
Iteration 5: edit_file("app.js") # Protect routes
Iteration 6: write_file("test/auth.test.js") # Add tests
Iteration 7: run_command("npm test") # Verify
xibecode run "Convert src/ to TypeScript"Execution:
Iteration 1: search_files("src/**/*.js") # Find all JS files
Iteration 2: read_file("package.json") # Check dependencies
Iteration 3: run_command("npm install -D typescript @types/node")
Iteration 4: write_file("tsconfig.json") # Create config
Iteration 5-15: For each file:
- read_file("file.js")
- write_file("file.ts") # Convert with types
Iteration 16: run_command("npx tsc") # Verify compilation
xibecode run "Production error: 'Cannot read property x of undefined'
in userController.js line 42. Fix it." --verboseExecution:
Iteration 1: read_file("userController.js", 35, 50) # Context
Iteration 2: # AI spots: user.profile.name without null check
Iteration 3: edit_file(
search: "const name = user.profile.name;",
replace: "const name = user?.profile?.name || 'Unknown';"
)
Iteration 4: read_file("test/userController.test.js")
Iteration 5: edit_file(...) # Add test for null profile
Iteration 6: run_command("npm test")
# Good
xibecode run "Add error handling to src/api/users.js"
# Less good (AI might guess wrong file)
xibecode run "Add error handling to the users file"xibecode run "There's a bug around line 500 in data-processor.js"
# AI will read just that section instead of entire 2000-line filexibecode run "Refactor entire codebase" --verbose
# Shows every tool call, helpful for debugging# Don't manually list imports
xibecode run "Fix userController.js. It imports User and auth, read those too"
# Just ask
xibecode run "Fix userController.js"
# AI will find imports automatically# Instead of:
xibecode run "Build complete e-commerce platform"
# Do:
xibecode run "Create product model and CRUD endpoints"
xibecode run "Add shopping cart functionality"
xibecode run "Implement checkout process"For more examples, see the README.md!