claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Bug: @filepath syntax not supported, agents silently dropped

Open peterjrichens opened this issue 1 year ago • 5 comments

Bug: @filepath syntax not supported, agents silently dropped

Summary

PR #245 introduced a workaround for command line length limits by using --agents @/tmp/file.json syntax. However, the Claude CLI does not support @filepath syntax, causing agents to be silently dropped when command lines exceed 100KB (macOS/Linux) or 8KB (Windows).

Note: While PR #245 was intended to fix Windows-specific command line limits, this bug now affects all platforms (Windows, macOS, Linux) because the @filepath syntax is not implemented in the CLI on any platform.

Reproduction

# Works: Inline JSON
claude --output-format stream-json --verbose --print "hi" --max-turns 1 \
  --agents '{"test-agent": {"description": "test", "prompt": "test"}}' 2>&1 | \
  jq -r 'select(.type == "system" and .subtype == "init") | .agents[]' | grep test-agent
# Output: test-agent ✅

# Fails: @filepath notation
echo '{"test-agent": {"description": "test", "prompt": "test"}}' > /tmp/test.json
claude --output-format stream-json --verbose --print "hi" --max-turns 1 \
  --agents "@/tmp/test.json" 2>&1 | \
  jq -r 'select(.type == "system" and .subtype == "init") | .agents[]' | grep test-agent
# Output: (nothing) ❌

Root Cause

Location: claude_agent_sdk/_internal/transport/subprocess_cli.py:248

cmd[agents_idx + 1] = f"@{temp_file.name}"  # CLI doesn't support @ syntax

The SDK assumes the CLI supports @filepath syntax, but it doesn't. The CLI tries to parse @/tmp/file.json as literal JSON, fails silently, and loads zero agents.

Introduced in: https://github.com/anthropics/claude-agent-sdk-python/pull/245/files

peterjrichens avatar Nov 18 '25 04:11 peterjrichens

@ashwin-ant @ollie-anthropic hello 👋 . We are still seeing this issue on our side, the Reproduction section from the original issue still fails and the section of the code that uses the @filepath syntax was never changed.

Can we please reopen this issue? And is it possible to make a plan to address this?

Thank you!

smithla02 avatar Dec 17 '25 01:12 smithla02

@ollie-anthropic thanks for adding this commit! Would this fix the issue if merged?

smithla02 avatar Jan 05 '26 21:01 smithla02

could this be merged @ollie-anthropic? we currently have to pin our claude-agent-sdk to the fix commit (https://github.com/anthropics/claude-agent-sdk-python/commit/b0ba1882bbb6da630c31069f047114f35ed127e5) because we need this behavior, thanks!

mnocito avatar Jan 11 '26 22:01 mnocito

No, this commit won't solve the command line length limit issue.

$(cat filepath) is expanded by the shell before execve() is called, so the full JSON content still gets passed as an argument. The ARG_MAX limit applies to the expanded command, not the literal string.

Maybe the CLI needs to support something like --agents-file <path> and read the file internally.

SNM511 avatar Jan 16 '26 08:01 SNM511

This issue was resolved in SDK v0.1.31 (PR #468). Agent definitions are now sent via the initialize control request through stdin, completely bypassing CLI argument length limits. The @filepath syntax is no longer used.

The current source code in subprocess_cli.py confirms this:

# Agents are always sent via initialize request (matching TypeScript SDK)
# No --agents CLI flag needed

This means agents of any size will work correctly on all platforms (including Windows with its 8KB command-line limit). Closing as resolved.

qing-ant avatar Mar 24 '26 18:03 qing-ant