Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions augment/hooks/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def _clear_path(path: Path, label: str) -> str:
return "failed"


def clear_setup() -> None:
def clear_setup() -> bool:
"""Undo all changes made by the setup script."""
print("=" * 60)
print("Augment Code Hooks - Clearing Setup")
Expand Down Expand Up @@ -692,6 +692,8 @@ def clear_setup() -> None:
print("Clear Complete!")
print("=" * 60)

return not any_failed


def get_device_identifier() -> Optional[str]:
system = platform.system().lower()
Expand Down Expand Up @@ -903,8 +905,7 @@ def main():
print("[backfill] Augment backfill is not supported.")

if clear_mode:
clear_setup()
return
return clear_setup()

if check_enterprise_hooks_conflict():
print("\n❌ Skipped — Augment is managed by your organization (MDM).")
Expand Down Expand Up @@ -944,14 +945,14 @@ def main():
if not api_key:
if not domain:
print("❌ Missing required argument: --domain or --api-key")
return
return False

auth_url = normalize_url(domain)

cb_response = run_callback_server(auth_url)
if cb_response is None:
print("❌ Failed to receive callback. Exiting.")
return
return False

try:
api_key = (cb_response.get("query") or {}).get("api_key")
Expand All @@ -965,15 +966,15 @@ def main():
print(f"❌ Setup failed: {safe_error}")
else:
print("❌ No API key received. Exiting.")
return
return False

debug_print("API key received from callback")

debug_print("Setting UNBOUND_AUGMENT_API_KEY environment variable...")
success, message = set_env_var("UNBOUND_AUGMENT_API_KEY", api_key)
if not success:
print(f"❌ Failed to set environment variable: {message}")
return
return False
debug_print("UNBOUND_AUGMENT_API_KEY set successfully")

_install_state = detect_install_state()
Expand All @@ -984,13 +985,13 @@ def main():
debug_print("Setting up hooks...")
if not setup_hooks(gateway_url=gateway_url):
print("❌ Failed to setup hooks")
return
return False
debug_print("Hooks downloaded successfully")

debug_print("Configuring Augment settings...")
if not configure_augment_settings():
print("❌ Failed to configure Augment settings")
return
return False
debug_print("Augment settings configured successfully")

print("✅ API key verified and added")
Expand All @@ -1003,12 +1004,16 @@ def main():
if rc_path is not None:
print(f"\nTo apply changes in your current terminal, run:\n source {rc_path}\n\nOr open a new terminal.")

return True


if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\n⚠️ Setup cancelled.")
sys.exit(1)
except Exception as e:
print(f"\n❌ Error: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
48 changes: 30 additions & 18 deletions claude-code/gateway/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import sys
import platform
import subprocess
import urllib.request
Expand Down Expand Up @@ -143,12 +144,12 @@ def set_env_var_on_unix(var_name: str, value: str) -> bool:
debug_print(f"Writing to shell file: {rc_file}")
export_line = f'export {var_name}="{value}"'

was_added = append_to_file(rc_file, export_line)
if was_added:
return True
else:
return True
append_to_file(rc_file, export_line)

try:
return any(line.strip() == export_line for line in rc_file.read_text(encoding="utf-8").splitlines())
except Exception:
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Commented export blocks gateway setup

Medium Severity

On Unix, gateway setup now verifies an exact active export line in the shell rc file, but append_to_file still skips writing when that text appears anywhere in the file (including inside a commented # export … line). With only a commented export present, no active line is added, read-back fails, and setup exits with failure even though the installer never writes a usable export.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6f6aa58. Configure here.



def set_env_var(var_name: str, value: str) -> Tuple[bool, str]:
Expand Down Expand Up @@ -293,7 +294,7 @@ def remove_hooks_unbound_script() -> None:
debug_print(f"Failed to remove {script_path}: {e}")


def setup_claude_key_helper() -> None:
def setup_claude_key_helper() -> bool:
"""
Create ~/.claude/anthropic_key.sh that echoes UNBOUND_API_KEY and
update ~/.claude/settings.json with apiKeyHelper pointing to that script.
Expand Down Expand Up @@ -329,8 +330,10 @@ def setup_claude_key_helper() -> None:
settings["apiKeyHelper"] = "~/.claude/anthropic_key.sh"

settings_path.write_text(json.dumps(settings, indent=2), encoding="utf-8")
return True
except Exception as e:
print(f"⚠️ Failed to configure Claude Code key helper: {e}")
print(f"❌ Failed to configure Claude Code key helper: {e}")
return False


def run_one_shot_callback_server(frontend_url: str) -> Optional[Dict[str, any]]:
Expand Down Expand Up @@ -448,7 +451,7 @@ def remove_api_key_helper_setting() -> str:
return "failed"


def clear_setup() -> None:
def clear_setup() -> bool:
"""Undo all changes made by the setup script."""
print("=" * 60)
print("Claude Code - Clearing Setup")
Expand Down Expand Up @@ -487,6 +490,8 @@ def clear_setup() -> None:
print("Clear Complete!")
print("=" * 60)

return not any_failed


def get_device_identifier() -> Optional[str]:
system = platform.system().lower()
Expand Down Expand Up @@ -675,8 +680,7 @@ def main():
debug_print("Debug mode enabled")

if args.clear:
clear_setup()
return
return clear_setup()

if check_enterprise_hooks_conflict():
print("\n❌ Skipped — Claude Code is managed by your organization (MDM).")
Expand Down Expand Up @@ -704,13 +708,13 @@ def main():
if not api_key:
if not args.domain:
print("\n❌ Missing required argument: --domain or --api-key")
return
return False

auth_url = normalize_url(args.domain)
cb_response = run_one_shot_callback_server(auth_url)
if cb_response is None:
print("\n❌ Failed to receive callback response. Exiting.")
return
return False

try:
api_key = (cb_response.get("query") or {}).get("api_key")
Expand All @@ -719,7 +723,7 @@ def main():

if not api_key:
print("\n❌ No api_key found in callback. Exiting.")
return
return False

print("API Key Verified ✅")
debug_print("API key verification successful")
Expand All @@ -728,11 +732,14 @@ def main():
success, message = set_env_var("UNBOUND_API_KEY", api_key)
if not success:
print(f"❌ Failed to configure UNBOUND_API_KEY: {message}")
return
return False
debug_print("UNBOUND_API_KEY set successfully")

debug_print("Setting ANTHROPIC_BASE_URL environment variable...")
success, message = set_env_var("ANTHROPIC_BASE_URL", args.gateway_url)
if not success:
print(f"❌ Failed to configure ANTHROPIC_BASE_URL: {message}")
return False
Comment thread
greptile-apps[bot] marked this conversation as resolved.
debug_print("ANTHROPIC_BASE_URL set successfully")

_install_state = detect_install_state()
Expand All @@ -742,7 +749,8 @@ def main():

# Configure Claude Code helper files
debug_print("Setting up Claude key helper...")
setup_claude_key_helper()
if not setup_claude_key_helper():
return False
debug_print("Claude key helper configured")

# Final instructions
Expand All @@ -756,11 +764,15 @@ def main():
if rc_path is not None:
print(f"\nTo apply changes in your current terminal, run:\n source {rc_path}\n\nOr open a new terminal.")

return True
Comment thread
greptile-apps[bot] marked this conversation as resolved.

if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\n⚠️ Setup cancelled by user.")
sys.exit(1)
except Exception as e:
print(f"\n❌ An error occurred: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
25 changes: 14 additions & 11 deletions claude-code/hooks/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def _clear_path(path: Path, label: str) -> str:
return "failed"


def clear_setup() -> None:
def clear_setup() -> bool:
"""Undo all changes made by the setup script."""
print("=" * 60)
print("Claude Code Hooks - Clearing Setup")
Expand Down Expand Up @@ -659,6 +659,7 @@ def clear_setup() -> None:
print("\n" + "=" * 60)
print("Clear Complete!")
print("=" * 60)
return not any_failed


def get_device_identifier() -> Optional[str]:
Expand Down Expand Up @@ -1197,8 +1198,7 @@ def main():
debug_print("Debug mode enabled")

if clear_mode:
clear_setup()
return
return clear_setup()

if check_enterprise_hooks_conflict():
print("\n❌ Skipped — Claude Code is managed by your organization (MDM).")
Expand Down Expand Up @@ -1238,14 +1238,14 @@ def main():
if not api_key:
if not domain:
print("❌ Missing required argument: --domain or --api-key")
return
return False

auth_url = normalize_url(domain)

cb_response = run_callback_server(auth_url)
if cb_response is None:
print("❌ Failed to receive callback. Exiting.")
return
return False

try:
api_key = (cb_response.get("query") or {}).get("api_key")
Expand All @@ -1259,7 +1259,7 @@ def main():
print(f"❌ Setup failed: {safe_error}")
else:
print("❌ No API key received. Exiting.")
return
return False

debug_print("API key received from callback")

Expand All @@ -1275,7 +1275,7 @@ def main():
success, message = set_env_var("UNBOUND_CLAUDE_API_KEY", api_key)
if not success:
print(f"❌ Failed to set environment variable: {message}")
return
return False
debug_print("UNBOUND_CLAUDE_API_KEY set successfully")

_install_state = detect_install_state()
Expand All @@ -1286,13 +1286,13 @@ def main():
debug_print("Setting up hooks...")
if not setup_hooks(gateway_url=gateway_url):
print("❌ Failed to setup hooks")
return
return False
debug_print("Hooks downloaded successfully")

debug_print("Configuring Claude settings...")
if not configure_claude_settings():
print("❌ Failed to configure Claude settings")
return
return False
debug_print("Claude settings configured successfully")

print("✅ API key verified and added")
Expand All @@ -1307,13 +1307,16 @@ def main():
rc_path = get_shell_rc_file()
if rc_path is not None:
print(f"\nTo apply changes in your current terminal, run:\n source {rc_path}\n\nOr open a new terminal.")
return True


if __name__ == "__main__":
try:
main()
ok = main()
except KeyboardInterrupt:
print("\n\n⚠️ Setup cancelled.")
sys.exit(1)
except Exception as e:
print(f"\n❌ Error: {e}")
exit(1)
sys.exit(1)
sys.exit(0 if ok else 1)
Loading