marketplace/productivity

Ask for the Fix

v0.1.0

@rebindfree

Copy an error or a sentence, press F8, and Claude's answer is pasted where you are. Uses your own Anthropic API key.

Gallery

Ask for the Fix preview

Readme

Copy an error message, a rough sentence, or anything you would otherwise switch windows for, then press F8. Rebind sends it to Claude with a short instruction and pastes the answer into the app you are in.

Needs Rebind 3.8.0 or newer on Windows or macOS, and your own Anthropic API key. It requests network access to api.anthropic.com only.

Set up

  1. Create an API key in the Anthropic Console. Calls are billed to your Anthropic account.
  2. Paste it into Anthropic API key in the package options.
  3. Put the cursor where the answer should go, copy your text, and press F8.

Settings

  • Ask and paste the answer: default F8. Key changes apply while the package runs on Rebind 3.9 or newer; on older versions, restart the package.
  • Instruction sent before your text: what Claude is asked to do. The default asks for a fixed or improved version only.

Limits

  • The answer replaces what was on the clipboard.
  • Answers are limited to 4,096 tokens, including Claude's thinking, and the request waits up to 60 seconds. An answer cut off at that limit is not pasted; a notice says so.
  • Your key is stored in Rebind's settings for this package on this computer.
  • Errors from Anthropic show as a notice in Rebind. To see notices on the desktop, turn on Desktop notifications in Rebind's settings.
  • Live use remains unverified on Windows and macOS.

Stop

Stop the package from the editor toolbar, or press Left Ctrl + Left Alt + K to stop all scripts.

Reviews

No reviews yet. Be the first, from the app.

Source

Version 0.1.0 (current)

main.luau

-- Ask for the Fix: send what you copied to Claude with a short instruction
-- and paste the answer where you are. Uses your own Anthropic API key.

local cfg = UI.Schema({
  key = UI.Keybind("F8", { label = "Ask and paste the answer" }),
  apiKey = UI.Text("", { label = "Anthropic API key" }),
  prompt = UI.Text("Fix or improve this. Reply with only the corrected text:", {
    label = "Instruction sent before your text",
  }),
})

local busy = false

local function answerText(body)
  local ok, data = pcall(JSON.Parse, body)
  if not ok or type(data) ~= "table" then
    return nil
  end
  for _, block in data.content or {} do
    if block.type == "text" then
      return block.text
    end
  end
  return nil
end

local function errorMessage(body)
  local ok, data = pcall(JSON.Parse, body)
  if ok and type(data) == "table" and data.error and data.error.message then
    return data.error.message
  end
  return "no answer"
end

Bind(
  cfg.key,
  Async(function()
    if busy then
      return
    end
    if cfg.apiKey == "" then
      UI.Notify("Add your Anthropic API key in the package options", "warning")
      return
    end
    local text = Clipboard.Get() or ""
    if text == "" then
      UI.Notify("Copy something first", "warning")
      return
    end
    busy = true
    UI.Notify("Asking Claude", "info")
    local ok, resp = pcall(
      Net.Post,
      "https://api.anthropic.com/v1/messages",
      JSON.Stringify({
        model = "claude-sonnet-5-5",
        max_tokens = 4096,
        messages = { { role = "user", content = cfg.prompt .. "\n\n" .. text } },
      }),
      {
        ["x-api-key"] = cfg.apiKey,
        ["anthropic-version"] = "2023-06-01",
        ["content-type"] = "application/json",
      },
      { timeout = 60000 }
    )
    busy = false
    if not ok then
      UI.Notify("Could not reach Claude: " .. tostring(resp), "error")
      return
    end
    if resp.status == 200 and resp.body:find('"stop_reason"%s*:%s*"max_tokens"') then
      UI.Notify("Claude's answer was too long and was cut off, so nothing was pasted", "warning")
      return
    end
    local answer = if resp.status == 200 then answerText(resp.body) else nil
    if not answer then
      UI.Notify(`Claude did not answer ({resp.status}): {errorMessage(resp.body)}`, "error")
      return
    end
    Clipboard.Set(answer)
    HID.Press(if _REBIND.platform == "macos" then "LWin+V" else "LCtrl+V")
  end)
)