agents

Stop forgetting the plan by Pranav Khandelwal

One of the biggest issues I run into with AI agents is that the implementation of a given feature starts to drift from the original implementation plan.

This is extremely frustrating, especially after spending a significant amount of time iterating on a plan.

And frequently, these misses are subtle and hard to catch.

The reason this seems to happen is because as the context fills up, the specific implementation details in the plan itself get lost. Basically…the agent starts to forget parts of the plan itself.

An interesting observation is that the now forgotten “Ralph loop” approach actually addressed this point well. Because it broke tasks into small granular and isolated units of work and then addressed those small tasks 1 by 1 each in a brand new chat, it kept the agent aligned and grounded.

Plan mode in Claude Code and OpenCode doesn’t quite work this way.

So what is the fix?

When the agent generates the Task list or Todos, I ask that every 3 tasks, it inject a task to re-read the entire plan file.

This means the plan keeps getting freshly injected into the context, so even during a long 1hr+ run, the agent remains grounded and aligned to the plan.

Setting up Postgres MCP Pro with Opencode by Pranav Khandelwal

I recently needed to get Postgres MCP Pro setup with Opencode. The biggest issue I kept running into was that the DATABASE_URI environment variables was not being detected from my local .env file.

The confusion stemmed from Opencode docs which vaguely suggested that environment variables declared in .env could be referenced in the MCP configuration like this:

    "mcp": {
        "postgres": {
            "type": "local",
            "command": ["uvx", "postgres-mcp", "--access-mode=restricted"],
            "enabled": true,
            "environment": {
                "DATABASE_URI": "{env:DATABASE_URI}"
            }
        }
    }

This unfortunately does not work.

The fix for this was to use a file instead. I created a .secrets folder in my repo root and placed a .txt file inside it with the full DATABASE_URI defined. Then I referenced the file like this

    "mcp": {
        "postgres": {
            "type": "local",
            "command": ["uvx", "postgres-mcp", "--access-mode=restricted"],
            "enabled": true,
            "environment": {
                "DATABASE_URI": "{file:.secrets/dev-db-conn-str.txt}"
            }
        }
    }

This worked and the MCP was successfully connected.

I think the confusion was that the {env:DATABASE_URI} only works for environment variable that are set in OpenCode settings, not within the codebase. This behavior changed back in September 2017. See: https://github.com/anomalyco/opencode/issues/2033#issuecomment-3301312732.