Skip to content

Conversation

@StillKnotKnown
Copy link
Collaborator

@StillKnotKnown StillKnotKnown commented Jan 21, 2026

Base Branch

  • This PR targets the develop branch (required for all feature/fix PRs)
  • This PR targets main (hotfix only - maintainers)

Description

When CLAUDE.md exceeds ~128KB, passing it as a command-line argument causes "Argument list too long" (errno 7/E2BIG) on Linux due to the kernel's ARG_MAX limit. This fix detects large system prompts and writes them to a temporary file using the @filepath syntax supported by the Claude CLI.

Related Issue

Closes #384

Refs: ACS-384

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 📚 Documentation
  • ♻️ Refactor
  • 🧪 Test

Area

  • Frontend
  • Backend
  • Fullstack

Commit Message Format

Follow conventional commits: <type>: <subject>

Types: feat, fix, docs, style, refactor, test, chore

Example: feat: add user authentication system

Checklist

  • I've synced with develop branch
  • I've tested my changes locally
  • I've followed the code principles (SOLID, DRY, KISS)
  • My PR is small and focused (< 400 lines ideally)
  • (Python only) All file operations specify encoding="utf-8" for text files

Platform Testing Checklist

CRITICAL: This project supports Windows, macOS, and Linux. Platform-specific bugs are a common source of breakage.

  • Windows tested (either on Windows or via CI)
  • macOS tested (either on macOS or via CI)
  • Linux tested (CI covers this)
  • Used centralized platform/ module instead of direct process.platform checks
  • No hardcoded paths (used findExecutable() or platform abstractions)

If you only have access to one OS: CI now tests on all platforms. Ensure all checks pass before submitting.

CI/Testing Requirements

  • All CI checks pass on all platforms (Windows, macOS, Linux)
  • All existing tests pass
  • New features include test coverage (5 new tests for _prepare_system_prompt)
  • Bug fixes include regression tests

Screenshots

Before After

Feature Toggle

  • Behind localStorage flag: use_feature_name
  • Behind settings toggle
  • Behind environment variable/config
  • N/A - Feature is complete and ready for all users

Breaking Changes

Breaking: No

Details:
This is a non-breaking fix. The temp file approach is transparent to users and only activates when the system prompt exceeds 90KB.

Summary by CodeRabbit

  • Chores
    • Improved internal system prompt handling to enhance stability and resource efficiency when managing large configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

When CLAUDE.md exceeds ~128KB, passing it as a command-line argument
causes "Argument list too long" (errno 7/E2BIG) on Linux due to the
kernel's ARG_MAX limit.

Changes:
- Add _prepare_system_prompt() helper that detects large prompts
- Write prompts >90KB to temp file using @filepath syntax
- Add comprehensive tests for the new functionality

Fixes #384
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

System-prompt size handling is implemented to prevent exceeding Linux ARG_MAX limits by writing oversized prompts to temporary files with @filepath references. CLAUDE.md integration is added with conditional inclusion based on file size and environment variables. Cleanup mechanisms ensure temporary files are removed on process exit.

Changes

Cohort / File(s) Summary
Core Implementation
apps/backend/core/client.py
Added _prepare_system_prompt() function to build and conditionally write system prompts to temp files, _cleanup_temp_files() for cleanup, _SYSTEM_PROMPT_SIZE_THRESHOLD constant (90KB), and atexit handler registration. Integrated CLAUDE.md support with size-based decision logic for direct string vs @filepath reference.
Test Suite
tests/test_client.py
Added comprehensive TestSystemPromptPreparation test class covering small/medium/large prompts, CLAUDE.md enabled/disabled scenarios, missing file handling, and temp file creation/cleanup verification. Tests validate prompt content, temp file references, and environment variable handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

priority/medium, confirmed, stable-roadmap

Suggested reviewers

  • AndyMik90
  • marcefalcondev

Poem

🐰 A prompt too large? No need to despair!
Our fuzzy friend writes temp files with care,
@filepath references fit through the air,
When CLAUDE.md joins the system's affair!
The cleanup hops away without a trace. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: addressing large system prompts on Linux by using temporary files instead of passing them as command arguments.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @StillKnotKnown, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue on Linux systems where large system prompts, particularly those incorporating extensive CLAUDE.md content, could lead to an 'Argument list too long' error due to the kernel's ARG_MAX limit. The solution introduces a mechanism to detect oversized prompts and transparently redirects their content to a temporary file, leveraging the Claude CLI's @filepath syntax. This enhancement ensures the application's stability and compatibility across different environments by preventing command-line argument overflow.

Highlights

  • System Prompt Size Handling: Implemented a new _prepare_system_prompt function to intelligently manage the system prompt content, especially for large inputs.
  • Linux ARG_MAX Limit Fix: Introduced a 90KB threshold for system prompts. If exceeded, the prompt content is written to a temporary file, and its path is passed using the Claude CLI's @filepath syntax, circumventing the 'Argument list too long' (errno 7) error on Linux.
  • Code Refactoring: The create_client function was refactored to utilize the new _prepare_system_prompt logic, centralizing prompt preparation.
  • Comprehensive Testing: Added a new test suite, TestSystemPromptPreparation, with five distinct tests covering various scenarios for prompt sizes (small, medium, large) and CLAUDE.md inclusion/exclusion, ensuring robust behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added area/backend This is backend only bug Something isn't working size/M Medium (100-499 lines) labels Jan 21, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the 'Argument list too long' error on Linux for large system prompts by using a temporary file. The approach is sound and the new tests are comprehensive. However, I've identified a critical resource leak where these temporary files are never deleted, which could lead to storage issues on the user's machine. I've provided a detailed comment on this issue. Additionally, I've included a suggestion to improve the file handling code to be more idiomatic and robust.

print(" - CLAUDE.md: disabled by project settings")
# Build system prompt (handles large prompts via temp file to avoid errno 7)
# See: https://github.com/AndyMik90/Auto-Claude/issues/384
system_prompt_value, _temp_prompt_file = _prepare_system_prompt(project_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This line discards the path to the temporary file created for a large system prompt. Since _prepare_system_prompt creates the file with delete=False, it will never be cleaned up, leading to a resource leak on the user's machine. This is a critical issue that will cause temporary files to accumulate indefinitely.

The test test_large_prompt_returns_temp_file_reference correctly calls os.unlink(temp_file), which indicates awareness of this responsibility.

To fix this, you need to manage the lifecycle of the temporary file. Here are a couple of options:

  1. Modify create_client to return the temp file path: Change the return signature to -> tuple[ClaudeSDKClient, str | None] and update all call sites to handle the cleanup in a finally block. This is the most robust solution but requires broader changes.
  2. Create a context manager wrapper: create_client could return a wrapper object that implements __enter__ and __exit__ to handle cleanup. Callers would then need to use with create_client(...) as client:. This also involves changing all call sites.

Please address this leak to prevent filling up the user's temporary directory.

Comment on lines 497 to 513
# ruff: noqa: SIM115
temp_file = tempfile.NamedTemporaryFile(
mode="w",
suffix=".txt",
delete=False,
encoding="utf-8",
)
temp_file.write(base_prompt)
temp_file.close()

logger.info(
f"System prompt size ({prompt_size:,} bytes) exceeds threshold "
f"({_SYSTEM_PROMPT_SIZE_THRESHOLD:,} bytes). Using temp file: {temp_file.name}"
)
print(f" - CLAUDE.md: large prompt ({prompt_size:,} bytes), using temp file")

return f"@{temp_file.name}", temp_file.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a with statement to handle the temporary file is more idiomatic and ensures the file is closed correctly, even if errors occur. You can still access the file name outside the with block. This change also allows you to remove the ruff: noqa: SIM115 directive.

Suggested change
# ruff: noqa: SIM115
temp_file = tempfile.NamedTemporaryFile(
mode="w",
suffix=".txt",
delete=False,
encoding="utf-8",
)
temp_file.write(base_prompt)
temp_file.close()
logger.info(
f"System prompt size ({prompt_size:,} bytes) exceeds threshold "
f"({_SYSTEM_PROMPT_SIZE_THRESHOLD:,} bytes). Using temp file: {temp_file.name}"
)
print(f" - CLAUDE.md: large prompt ({prompt_size:,} bytes), using temp file")
return f"@{temp_file.name}", temp_file.name
# Write to temp file and use @filepath syntax
temp_file_path: str
with tempfile.NamedTemporaryFile(
mode="w",
suffix=".txt",
delete=False,
encoding="utf-8",
) as temp_file:
temp_file.write(base_prompt)
temp_file_path = temp_file.name
logger.info(
f"System prompt size ({prompt_size:,} bytes) exceeds threshold "
f"({_SYSTEM_PROMPT_SIZE_THRESHOLD:,} bytes). Using temp file: {temp_file_path}"
)
print(f" - CLAUDE.md: large prompt ({prompt_size:,} bytes), using temp file")
return f"@{temp_file_path}", temp_file_path

Comment on lines 498 to 503
temp_file = tempfile.NamedTemporaryFile(
mode="w",
suffix=".txt",
delete=False,
encoding="utf-8",
)

This comment was marked as outdated.

)
print(f" - CLAUDE.md: large prompt ({prompt_size:,} bytes), using temp file")

return f"@{temp_file.name}", temp_file.name

This comment was marked as outdated.

StillKnotKnown and others added 2 commits January 21, 2026 21:32
This addresses the resource leak issue identified in PR review where
temporary files created for large system prompts were never cleaned up.

Changes:
- Add atexit cleanup handler for temp files
- Track temp files in module-level list
- Use with statement for idiomatic file handling
- Remove ruff noqa comment (no longer needed)

Fixes review comment from @gemini-code-assist
…ist-too-long-on-linux-when-claude-md-exceeds-128kb


# Register cleanup handler to run on process exit
atexit.register(_cleanup_temp_files)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The Claude Agent SDK's system_prompt parameter does not support the "@{filepath}" syntax, causing large prompts passed as temp files to fail.
Severity: HIGH

Suggested Fix

Instead of passing a "@{temp_file_path}" string to the SDK, read the contents of the temporary file into a string variable and pass that variable directly to the system_prompt parameter. The temporary file can be deleted immediately after its contents are read.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/backend/core/client.py#L471

Potential issue: The `_prepare_system_prompt` function creates a temporary file for
large system prompts and formats the prompt string as `"@{temp_file_path}"`. However,
the Claude Agent SDK's `system_prompt` parameter does not appear to support this
`@filepath` syntax for file references. The SDK will likely interpret
`"@{temp_file_path}"` as a literal string, passing a nonsensical prompt to the model
instead of the file's contents. This will cause the functionality for handling large
system prompts to fail, as the actual prompt content will not be loaded.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend This is backend only bug Something isn't working size/M Medium (100-499 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants