AGENTS.md
Guidance for coding agents working on claude-auto-yes. This is a small Python utility that wraps Claude CLI sessions and automatically selects an approval choice only when the screen clearly matches a permission prompt.
Project Overview
claude_auto_yes.py is a single-file command-line tool. It normalizes terminal output, detects numbered approval prompts, deduplicates prompt fingerprints, writes a configured answer into a PTY, can inspect Claude agent JSON for permission-waiting sessions, and can attach to waiting sessions. It also protects maintenance commands from accidental automation.
The core safety requirement is conservative prompt detection. A false positive can approve an unintended action, so keep detection explicit, testable, and easy to audit.
Project Map
- claude_auto_yes.py is the full implementation.
- normalize_screen strips ANSI and control characters before prompt analysis.
- detect_auto_select_prompt returns a fingerprint only when the selected choice is yes-like and the surrounding context is permission-like.
- AutoSelector buffers terminal output, detects repeated prompts, and sends the configured answer.
- extract_permission_session_ids walks nested JSON rows and returns sessions waiting on permission.
- build_agents_json_command and build_attach_command isolate Claude CLI command construction.
- PTY, select, signal, and subprocess handling keep wrapped sessions interactive.
Setup Commands
bashpython3 -m py_compile claude_auto_yes.py
python3 claude_auto_yes.py --help
Add focused tests before broadening behavior. Use small screen-text fixtures for prompt parsing instead of live CLI sessions.
Change Rules For Agents
- Keep auto-selection optically conservative: require permission-like context and a yes-like selected choice.
- Do not treat a lone numbered menu as approval unless surrounding text clearly indicates permission.
- Preserve fingerprint deduplication so repeated screen repainting does not spam answers.
- Keep ANSI/control stripping separate from detection logic.
- Do not automate Claude maintenance commands such as update or upgrade.
- Keep command builders pure and easy to unit test.
- Avoid logging raw terminal buffers when they may contain prompts, paths, or secrets.
Verification
bashpython3 -m py_compile claude_auto_yes.py
python3 claude_auto_yes.py --help
For detection changes, add fixture-level tests for yes/no prompts, unrelated numbered menus, ANSI-wrapped prompts, nested JSON session rows, and duplicate prompt fingerprints.
Security Notes
This tool can approve actions. Keep the default behavior narrow, make unsafe automation explicit, and never publish captured session output, credentials, private paths, or local command transcripts.
PR Checklist
- Prompt detection rejects unrelated menus.
- Prompt detection accepts only explicit permission contexts.
- Session JSON parsing handles nested lists and objects.
- Maintenance-command guardrails remain intact.