Prompt-based continuous learning (CL) offers a parameter-efficient approach for adapting large-scale language models (LLMs) to task sequences. However, most existing methods rely on task-aware inference and maintain a growing set of task-specific prompts, leading to two major challenges: (1) significant performance degradation relative to previous tasks under task-agnostic inference, and (2) limited scalability due to prompt memory accumulation as task sequences grow. In this paper, we present GRID, an integrated framework designed to address these challenges. GRID integrates a decoding mechanism that utilizes representative inputs to improve backtransfer, automatic task identification, and constrained decoding. Furthermore, it employs a gradient-based prompt selection strategy to compress less informative prompts into a single, unified representation, ensuring scalable and memory-efficient continuous learning. Extensive experiments on long-sequence and negative transfer benchmarks demonstrate that GRID improves average accuracy and backtransfer, achieves competitive backtransfer, and substantially reduces prompt memory usage.