DEV Community

AlirezaRg
AlirezaRg

Posted on

I Built Two AI Desktop Tools with Python — No API Keys, No Cloud Costs

I got tired of switching between my code editor, terminal, browser, and an AI chat window.
So I built two desktop tools that bring the AI directly into my workflow — one that controls my entire PC, and one that understands my codebase.

Here's how they work, and the unusual technical choice that made them possible.


The Two Tools

Rasco — A JARVIS-style desktop assistant. You type (or speak) a command, it executes it: opens apps, navigates websites, manages files, takes screenshots, reads system stats. Black & gold UI, always running in the corner.

Gosi — A coding assistant that actually reads your project. Point it at a folder, ask a question about a bug or an architecture decision, and it finds the relevant files, builds context, and answers based on your actual code — not generic patterns.

Both are built with Python + Tkinter and run fully on your local machine.


The Architecture: Claude Code CLI as a Subprocess

Here's the part most people find surprising: neither tool calls the Anthropic API directly.

Instead, they pipe prompts through Claude Code CLI:

def _run_claude(prompt, timeout=120):
    # Write prompt to temp file (handles large prompts reliably on Windows)
    with tempfile.NamedTemporaryFile(mode="w", suffix=".txt",
                                     delete=False, encoding="utf-8") as tmp:
        tmp.write(prompt)
        tmp_path = tmp.name

    cmd = f'type "{tmp_path}" | "{CLAUDE_CMD_PATH}" -p --model sonnet'
    result = subprocess.run(
        cmd, capture_output=True, text=True,
        encoding="utf-8", timeout=timeout, shell=True
    )
    return result.stdout.strip()
Enter fullscreen mode Exit fullscreen mode

Why pipe through a temp file instead of stdin? On Windows, very long prompts passed directly to subprocess through input= can fail silently. Writing to a temp file and piping with type is much more reliable.

The tradeoff: You need a Claude Code subscription (Pro or Max), not a pay-per-token API key. For me — a developer who uses Claude Code all day anyway — this means the tools cost me nothing extra.


Rasco: Giving AI Hands on Your PC

The core of Rasco is a dispatcher that maps natural language to system actions:

COMMANDS = {
    "open chrome":     lambda: subprocess.Popen(["chrome"]),
    "screenshot":      lambda: pyautogui.screenshot().save("screen.png"),
    "system info":     lambda: get_system_stats(),
    "open youtube":    lambda: browser_navigate("https://youtube.com"),
    # ... 40+ more commands
}
Enter fullscreen mode Exit fullscreen mode

For anything not in the predefined map, it falls through to Claude with full conversation history:

def handle_message(user_input, history):
    # Try local commands first (instant, no AI needed)
    for keyword, action in COMMANDS.items():
        if keyword in user_input.lower():
            return action()

    # Fall through to Claude with context
    response = ask_claude(user_input, history)
    speak(response)   # pyttsx3 TTS
    return response
Enter fullscreen mode Exit fullscreen mode

Browser automation uses Selenium under the hood — so "search YouTube for lofi beats" actually opens Chrome, navigates to YouTube, and types into the search box.

def browser_navigate(url):
    opts = Options()
    opts.add_experimental_option("excludeSwitches", ["enable-automation"])
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opts)
    driver.get(url)
    return driver
Enter fullscreen mode Exit fullscreen mode

Gosi: An AI That Actually Reads Your Code

The smarter challenge with Gosi was context selection. You can't dump an entire Flask project into a prompt — you hit token limits and the signal-to-noise ratio tanks.

The solution: a simple relevance scorer that finds the right files before asking Claude anything.

def find_relevant_files(self, query, max_files=8):
    query_lower = query.lower()
    words = [w for w in query_lower.split() if len(w) > 2]
    scored = []

    for rel in self.files:
        score = 0
        base = os.path.basename(rel.lower())

        # Direct filename mention in query = strong signal
        if base in query_lower:
            score += 10

        # Keyword overlap
        for w in words:
            if w in rel.lower():
                score += 3

        # Prioritize logs when user mentions errors
        if any(k in query_lower for k in ["error", "exception", "log", "crash"]):
            if rel.endswith((".log", ".txt")):
                score += 5

        if score > 0:
            scored.append((score, rel))

    scored.sort(key=lambda x: -x[0])
    return [rel for _, rel in scored[:max_files]]
Enter fullscreen mode Exit fullscreen mode

The scanner walks the project directory, skips noise (__pycache__, venv, migrations, etc.), and truncates large files at 6,000 chars to stay within context limits.

The system prompt is bilingual — it detects whether the user wrote in Persian or English and responds in the same language:

SYSTEM_PROMPT = """You are CodePilot, an expert AI coding assistant specialized
in Python, Flask, and Odoo projects. The user speaks Persian or English —
always reply in the same language they used.

You will be given relevant source files and/or log excerpts as CONTEXT,
followed by their QUESTION. Use the context to explain bugs, suggest fixes,
and help debug errors from logs."""
Enter fullscreen mode Exit fullscreen mode

The file editing feature adds a diff review step before writing anything. Gosi asks Claude for the full new file content, diffs it against the original, shows the diff in the UI, and only writes to disk after the user confirms. It also makes a .bak backup automatically.


Setup

# 1. Clone
git clone https://github.com/AlirezaRg/Rasco-Gosi
cd Rasco-Gosi

# 2. Install Python dependencies
pip install pyttsx3 pyautogui psutil selenium webdriver-manager speechrecognition

# 3. Install and login to Claude Code CLI
npm install -g @anthropic-ai/claude-code
claude   # login here

# 4. Run
python rasco.py    # for the PC assistant
python Gosi.py     # for the coding assistant
Enter fullscreen mode Exit fullscreen mode

If you don't have a Claude subscription, there's also an Ollama backend:

ollama pull llama3.2
ollama serve
python codepilot_ollama.py
Enter fullscreen mode Exit fullscreen mode

What I Learned

Subprocess beats raw API for local tools. When you already pay for a Claude Code subscription, routing through the CLI gives you the same model with zero extra cost and zero key management.

Context selection matters more than context size. A prompt with 4 perfectly-chosen files beats a prompt with 20 files dumped in. The relevance scorer, even this simple version, made a real quality difference.

Tkinter is underrated. Everyone says "use Electron" or "use a web UI." But Tkinter starts in milliseconds, ships as a single Python file, and stays out of the way. For personal productivity tools, that's exactly what you want.


Links


Built this while studying Computer Engineering and integrating biometric hardware with Odoo 18 at work. Writing tools that solve my own problems is the best way I've found to actually ship something.

If you build something on top of this or have questions about the Selenium integration / Ollama backend, drop a comment.

Top comments (0)